fix command calling
This commit is contained in:
parent
00b4583f3b
commit
c0fff34a7c
23
src/main.rs
23
src/main.rs
@ -30,32 +30,33 @@ fn main() {
|
||||
let mut options = commands;
|
||||
|
||||
loop {
|
||||
|
||||
match args.get(0) {
|
||||
Some(cmd_arg) => {
|
||||
// Try to find a subcommand to run
|
||||
match Command::choose(cmd_arg, options) {
|
||||
Some(choice) => {
|
||||
// No sub commands left to choose from, just pass the input
|
||||
if choice.sub_commands.is_empty() {
|
||||
// No sub commands left to choose from, just pass the input
|
||||
choice.call(&args);
|
||||
break;
|
||||
} else {
|
||||
args = &args[1..];
|
||||
options = &choice.sub_commands;
|
||||
}
|
||||
|
||||
// a sort of last chance before running into hella edgecases
|
||||
if args.is_empty() {
|
||||
choice.call(args);
|
||||
break;
|
||||
}
|
||||
args = &args[1..];
|
||||
options = &choice.sub_commands;
|
||||
|
||||
// a sort of last chance before running into hella edgecases
|
||||
if args.is_empty()
|
||||
|| Command::choose(args[0], options).is_none() // yes, this means that we search for a choice twice if it misses, but the search takes all of 0ms, so it's fine.
|
||||
{
|
||||
choice.call(args);
|
||||
break;
|
||||
}
|
||||
}
|
||||
// When no good choice presents it's self
|
||||
None => break,
|
||||
}
|
||||
}
|
||||
None => todo!("Couldn't get index 0 of the args"),
|
||||
None => unimplemented!("Couldn't get index 0 of the args"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user