mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-12-05 20:40:19 -08: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() {
|
'parse_args: while let Some(&next_arg) = remaining_args.first() {
|
||||||
remaining_args = &remaining_args[1..];
|
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;
|
help = true;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -761,7 +761,7 @@ pub struct ParseStructOptions<'a> {
|
|||||||
pub help_triggers: &'a [&'a str],
|
pub help_triggers: &'a [&'a str],
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ParseStructOptions<'_> {
|
impl<'a> ParseStructOptions<'a> {
|
||||||
/// Parse a commandline option.
|
/// Parse a commandline option.
|
||||||
///
|
///
|
||||||
/// `arg`: the current option argument being parsed (e.g. `--foo`).
|
/// `arg`: the current option argument being parsed (e.g. `--foo`).
|
||||||
@@ -772,7 +772,7 @@ impl ParseStructOptions<'_> {
|
|||||||
.arg_to_slot
|
.arg_to_slot
|
||||||
.iter()
|
.iter()
|
||||||
.find_map(|&(name, pos)| if name == arg { Some(pos) } else { None })
|
.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] {
|
match self.slots[pos] {
|
||||||
ParseStructOption::Flag(ref mut b) => b.set_flag(arg),
|
ParseStructOption::Flag(ref mut b) => b.set_flag(arg),
|
||||||
@@ -798,6 +798,14 @@ impl ParseStructOptions<'_> {
|
|||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn help_triggers(&self) -> &'a [&'a str] {
|
||||||
|
if self.help_triggers.is_empty() {
|
||||||
|
&["-h", "--help"]
|
||||||
|
} else {
|
||||||
|
self.help_triggers
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn unrecognized_argument(
|
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>`]
|
/// 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> {
|
fn get_help_triggers(type_attrs: &TypeAttrs) -> Vec<String> {
|
||||||
type_attrs.help_triggers.as_ref().map_or_else(
|
type_attrs
|
||||||
|| vec!["--help".to_owned(), "help".to_owned()],
|
.help_triggers
|
||||||
|s| {
|
.as_ref()
|
||||||
|
.map_or_else(Vec::new, |s| {
|
||||||
s.iter()
|
s.iter()
|
||||||
.filter_map(|s| {
|
.filter_map(|s| {
|
||||||
let trigger = s.value();
|
let trigger = s.value();
|
||||||
@@ -441,8 +442,7 @@ fn get_help_triggers(type_attrs: &TypeAttrs) -> Vec<String> {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
},
|
})
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Ensures that only the last positional arg is non-required.
|
/// Ensures that only the last positional arg is non-required.
|
||||||
|
|||||||
Reference in New Issue
Block a user