diff --git a/cli/src/argparse/command.rs b/cli/src/argparse/command.rs index 891a4525f..45f95e970 100644 --- a/cli/src/argparse/command.rs +++ b/cli/src/argparse/command.rs @@ -15,8 +15,15 @@ pub(crate) struct Command { impl Command { pub(super) fn parse(input: ArgList) -> IResult { fn to_command(input: (&str, Subcommand)) -> Result { + // Clean up command name, so `./target/bin/ta` to `ta` etc + let command_name: String = std::path::PathBuf::from(&input.0) + .file_name() + // Convert to string, very unlikely to contain non-UTF8 + .map(|x| x.to_string_lossy().to_string()) + .unwrap_or(input.0.to_owned()); + let command = Command { - command_name: input.0.to_owned(), + command_name, subcommand: input.1, }; Ok(command) @@ -64,4 +71,16 @@ mod test { } ); } + + + #[test] + fn test_cleaning_command_name() { + assert_eq!( + Command::from_argv(argv!["/tmp/ta", "version"]).unwrap(), + Command { + subcommand: Subcommand::Version, + command_name: s!("ta"), + } + ); + } }