Remove path from ta command in usage text

Previously would show things like "target/bin/ta [filter] list"
This commit is contained in:
dbr 2021-06-05 11:50:19 +10:00
parent 5f28eb3a74
commit 8069d1badc

View file

@ -15,8 +15,15 @@ pub(crate) struct Command {
impl Command {
pub(super) fn parse(input: ArgList) -> IResult<ArgList, Command> {
fn to_command(input: (&str, Subcommand)) -> Result<Command, ()> {
// 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"),
}
);
}
}