1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 03:27:44 +00:00

tr: prevent passing options in the wrong place

Note: This requires using the DEPRECATED item Command::trailing_var_arg
in clap. This is going to be another
[problem with clap](https://github.com/tertsdiepraam/uutils-args/blob/main/docs/design/problems_with_clap.md).
This commit is contained in:
Ben Wiederhake 2024-02-23 02:15:53 +01:00
parent d9b6675bbf
commit cad94a69be
2 changed files with 25 additions and 0 deletions

View file

@ -164,6 +164,7 @@ pub fn uu_app() -> Command {
.about(ABOUT)
.override_usage(format_usage(USAGE))
.infer_long_args(true)
.trailing_var_arg(true)
.arg(
Arg::new(options::COMPLEMENT)
.visible_short_alias('C')

View file

@ -78,6 +78,14 @@ fn test_complement1() {
.stdout_is("aX");
}
#[test]
fn test_complement_afterwards_is_not_flag() {
new_ucmd!()
.args(&["a", "X", "-c"])
.fails()
.stderr_contains("extra operand '-c'");
}
#[test]
fn test_complement2() {
new_ucmd!()
@ -127,6 +135,22 @@ fn test_complement_multi_early() {
.stdout_is("aX");
}
#[test]
fn test_complement_multi_middle() {
new_ucmd!()
.args(&["-c", "a", "-c", "X"])
.fails()
.stderr_contains("tr: extra operand 'X'");
}
#[test]
fn test_complement_multi_late() {
new_ucmd!()
.args(&["-c", "a", "X", "-c"])
.fails()
.stderr_contains("tr: extra operand '-c'");
}
#[test]
fn test_squeeze() {
new_ucmd!()