From c0fff34a7c199befc1853f5208cf833116a8f75f Mon Sep 17 00:00:00 2001 From: Oliver Atkinson Date: Tue, 26 Nov 2024 09:13:05 -0700 Subject: [PATCH] fix command calling --- src/main.rs | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/main.rs b/src/main.rs index 21d51db..f80fc75 100644 --- a/src/main.rs +++ b/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"), } } }