Skip to content

Commit

Permalink
fix: use the help triggers as extra suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Nov 13, 2023
1 parent c0e447f commit 364f7a8
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions argh/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -978,13 +978,7 @@ impl<'a> ParseStructOptions<'a> {
.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,
&["--help".to_owned(), "help".to_owned()],
)
})?;
.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),
Expand All @@ -1007,13 +1001,13 @@ impl<'a> ParseStructOptions<'a> {
fn unrecognized_argument(
given: &str,
arg_to_slot: &[(&str, usize)],
extra_suggestions: &[String],
extra_suggestions: &[&str],
) -> String {
// get the list of available arguments
let available = arg_to_slot
.iter()
.map(|(name, _pos)| *name)
.chain(extra_suggestions.iter().map(|s| s.as_str()))
.chain(extra_suggestions.iter().copied())
.collect::<Vec<&str>>();

if available.is_empty() {
Expand Down

0 comments on commit 364f7a8

Please sign in to comment.