From 8c177cd3a881ce39a2770c675f7a4b36b826c26a Mon Sep 17 00:00:00 2001 From: Terts Diepraam Date: Mon, 29 Jan 2024 17:02:13 +0100 Subject: [PATCH] echo: do not infer long args --- src/uu/echo/src/echo.rs | 4 +++- tests/by-util/test_echo.rs | 10 ++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/uu/echo/src/echo.rs b/src/uu/echo/src/echo.rs index a34c99bc91d..c94443822e0 100644 --- a/src/uu/echo/src/echo.rs +++ b/src/uu/echo/src/echo.rs @@ -132,13 +132,15 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { } pub fn uu_app() -> Command { + // Note: echo is different from the other utils in that it should **not** + // have `infer_long_args(true)`, because, for example, `--ver` should be + // printed as `--ver` and not show the version text. Command::new(uucore::util_name()) // TrailingVarArg specifies the final positional argument is a VarArg // and it doesn't attempts the parse any further args. // Final argument must have multiple(true) or the usage string equivalent. .trailing_var_arg(true) .allow_hyphen_values(true) - .infer_long_args(true) .version(crate_version!()) .about(ABOUT) .after_help(AFTER_HELP) diff --git a/tests/by-util/test_echo.rs b/tests/by-util/test_echo.rs index ac6bd74d1e0..8a9798eac66 100644 --- a/tests/by-util/test_echo.rs +++ b/tests/by-util/test_echo.rs @@ -293,3 +293,13 @@ fn old_octal_syntax() { .succeeds() .stdout_is("A1\n"); } + +#[test] +fn partial_version_argument() { + new_ucmd!().arg("--ver").succeeds().stdout_is("--ver"); +} + +#[test] +fn partial_help_argument() { + new_ucmd!().arg("--he").succeeds().stdout_is("--ver"); +}