From 793b0f4d77fea899d048598db52e57b89033d933 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Sat, 23 Feb 2019 18:07:32 +0100 Subject: [PATCH] src/cli/command.rs: improve help command completion --- src/cli/command.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/cli/command.rs b/src/cli/command.rs index b28cdbb0..800c495c 100644 --- a/src/cli/command.rs +++ b/src/cli/command.rs @@ -472,9 +472,10 @@ fn print_simple_completion( fn print_help_completion(def: &CommandLineInterface, help_cmd: &CliCommand, args: &[String]) { + let mut done = HashSet::new(); + match def { CommandLineInterface::Simple(_) => { - let mut done = HashSet::new(); print_simple_completion(help_cmd, &mut done, &help_cmd.arg_param, args); return; } @@ -485,11 +486,19 @@ fn print_help_completion(def: &CommandLineInterface, help_cmd: &CliCommand, args } return; } + let first = &args[0]; + + if first.starts_with("-") { + print_simple_completion(help_cmd, &mut done, &help_cmd.arg_param, args); + return; + } + if let Some(sub_cmd) = map.commands.get(first) { print_help_completion(sub_cmd, help_cmd, &args[1..]); return; } + for cmd in map.commands.keys() { if cmd.starts_with(first) { println!("{}", cmd);