fix command calling

This commit is contained in:
Oliver Atkinson 2024-11-26 09:13:05 -07:00
parent 00b4583f3b
commit c0fff34a7c

View File

@ -30,32 +30,33 @@ fn main() {
let mut options = commands; let mut options = commands;
loop { loop {
match args.get(0) { match args.get(0) {
Some(cmd_arg) => { Some(cmd_arg) => {
// Try to find a subcommand to run // Try to find a subcommand to run
match Command::choose(cmd_arg, options) { match Command::choose(cmd_arg, options) {
Some(choice) => { Some(choice) => {
// No sub commands left to choose from, just pass the input
if choice.sub_commands.is_empty() { if choice.sub_commands.is_empty() {
// No sub commands left to choose from, just pass the input
choice.call(&args); choice.call(&args);
break; break;
} else { }
args = &args[1..];
options = &choice.sub_commands;
// a sort of last chance before running into hella edgecases args = &args[1..];
if args.is_empty() { options = &choice.sub_commands;
choice.call(args);
break; // 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 // When no good choice presents it's self
None => break, None => break,
} }
} }
None => todo!("Couldn't get index 0 of the args"), None => unimplemented!("Couldn't get index 0 of the args"),
} }
} }
} }