mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
Remove path from ta command in usage text
Previously would show things like "target/bin/ta [filter] list"
This commit is contained in:
parent
5f28eb3a74
commit
8069d1badc
1 changed files with 20 additions and 1 deletions
|
@ -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"),
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue