-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[gcdemu] implement plusarg to parse args
Signed-off-by: unlsycn <[email protected]>
- Loading branch information
Showing
7 changed files
with
51 additions
and
219 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
pub struct PlusArgMatcher { | ||
plusargs: Vec<String>, | ||
} | ||
|
||
impl PlusArgMatcher { | ||
pub fn from_args() -> Self { | ||
let plusargs = std::env::args().filter(|arg| arg.starts_with('+')).collect(); | ||
|
||
Self { plusargs } | ||
} | ||
|
||
pub fn try_match(&self, arg_name: &str) -> Option<&str> { | ||
let prefix = &format!("+{arg_name}="); | ||
|
||
for plusarg in &self.plusargs { | ||
if plusarg.starts_with(prefix) { | ||
return Some(&plusarg[prefix.len()..]); | ||
} | ||
} | ||
None | ||
} | ||
|
||
pub fn match_(&self, arg_name: &str) -> &str { | ||
self.try_match(arg_name).unwrap_or_else(|| { | ||
tracing::error!("required plusarg '+{arg_name}=' not found"); | ||
panic!("failed to match '+{arg_name}='"); | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters