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;
loop {
match args.get(0) {
Some(cmd_arg) => {
// Try to find a subcommand to run
match Command::choose(cmd_arg, options) {
Some(choice) => {
if choice.sub_commands.is_empty() {
// No sub commands left to choose from, just pass the input
if choice.sub_commands.is_empty() {
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() {
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"),
}
}
}