src/cli/command.rs: improve help command completion

This commit is contained in:
Dietmar Maurer 2019-02-23 18:07:32 +01:00
parent 6949d91564
commit 793b0f4d77
1 changed files with 10 additions and 1 deletions

View File

@ -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);