Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

echo: do not infer long args #5911

Merged
merged 1 commit into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/uu/echo/src/echo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions tests/by-util/test_echo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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\n");
}

#[test]
fn partial_help_argument() {
new_ucmd!().arg("--he").succeeds().stdout_is("--he\n");
}
Loading