Remove path from ta command in usage text
Previously would show things like "target/bin/ta [filter] list"
This commit is contained in:
@@ -15,8 +15,15 @@ pub(crate) struct Command {
|
|||||||
impl Command {
|
impl Command {
|
||||||
pub(super) fn parse(input: ArgList) -> IResult<ArgList, Command> {
|
pub(super) fn parse(input: ArgList) -> IResult<ArgList, Command> {
|
||||||
fn to_command(input: (&str, Subcommand)) -> Result<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 {
|
let command = Command {
|
||||||
command_name: input.0.to_owned(),
|
command_name,
|
||||||
subcommand: input.1,
|
subcommand: input.1,
|
||||||
};
|
};
|
||||||
Ok(command)
|
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"),
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user