mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-10-27 20:09:32 +00:00
Update default help triggers
This commit is contained in:
@@ -704,7 +704,7 @@ pub fn parse_struct_args(
|
||||
|
||||
'parse_args: while let Some(&next_arg) = remaining_args.first() {
|
||||
remaining_args = &remaining_args[1..];
|
||||
if (parse_options.help_triggers.contains(&next_arg)) && !options_ended {
|
||||
if (parse_options.help_triggers().contains(&next_arg)) && !options_ended {
|
||||
help = true;
|
||||
continue;
|
||||
}
|
||||
@@ -761,7 +761,7 @@ pub struct ParseStructOptions<'a> {
|
||||
pub help_triggers: &'a [&'a str],
|
||||
}
|
||||
|
||||
impl ParseStructOptions<'_> {
|
||||
impl<'a> ParseStructOptions<'a> {
|
||||
/// Parse a commandline option.
|
||||
///
|
||||
/// `arg`: the current option argument being parsed (e.g. `--foo`).
|
||||
@@ -772,7 +772,7 @@ impl ParseStructOptions<'_> {
|
||||
.arg_to_slot
|
||||
.iter()
|
||||
.find_map(|&(name, pos)| if name == arg { Some(pos) } else { None })
|
||||
.ok_or_else(|| unrecognized_argument(arg, self.arg_to_slot, self.help_triggers))?;
|
||||
.ok_or_else(|| unrecognized_argument(arg, self.arg_to_slot, self.help_triggers()))?;
|
||||
|
||||
match self.slots[pos] {
|
||||
ParseStructOption::Flag(ref mut b) => b.set_flag(arg),
|
||||
@@ -798,6 +798,14 @@ impl ParseStructOptions<'_> {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn help_triggers(&self) -> &'a [&'a str] {
|
||||
if self.help_triggers.is_empty() {
|
||||
&["-h", "--help"]
|
||||
} else {
|
||||
self.help_triggers
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn unrecognized_argument(
|
||||
|
||||
@@ -425,11 +425,12 @@ fn impl_from_args_struct_from_args<'a>(
|
||||
|
||||
/// get help triggers vector from type_attrs.help_triggers as a [`Vec<String>`]
|
||||
///
|
||||
/// Defaults to vec!["--help", "help"] if type_attrs.help_triggers is None
|
||||
/// Defaults to vec!["-h", "--help"] if type_attrs.help_triggers is None
|
||||
fn get_help_triggers(type_attrs: &TypeAttrs) -> Vec<String> {
|
||||
type_attrs.help_triggers.as_ref().map_or_else(
|
||||
|| vec!["--help".to_owned(), "help".to_owned()],
|
||||
|s| {
|
||||
type_attrs
|
||||
.help_triggers
|
||||
.as_ref()
|
||||
.map_or_else(Vec::new, |s| {
|
||||
s.iter()
|
||||
.filter_map(|s| {
|
||||
let trigger = s.value();
|
||||
@@ -441,8 +442,7 @@ fn get_help_triggers(type_attrs: &TypeAttrs) -> Vec<String> {
|
||||
}
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
},
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
/// Ensures that only the last positional arg is non-required.
|
||||
|
||||
Reference in New Issue
Block a user