echo: make -e and -E override each other

This commit is contained in:
Terts Diepraam 2023-12-11 10:49:38 +01:00
parent d63d4a7658
commit 191eb9ac12
2 changed files with 17 additions and 2 deletions

View file

@ -154,13 +154,15 @@ pub fn uu_app() -> Command {
Arg::new(options::ENABLE_BACKSLASH_ESCAPE) Arg::new(options::ENABLE_BACKSLASH_ESCAPE)
.short('e') .short('e')
.help("enable interpretation of backslash escapes") .help("enable interpretation of backslash escapes")
.action(ArgAction::SetTrue), .action(ArgAction::SetTrue)
.overrides_with(options::DISABLE_BACKSLASH_ESCAPE),
) )
.arg( .arg(
Arg::new(options::DISABLE_BACKSLASH_ESCAPE) Arg::new(options::DISABLE_BACKSLASH_ESCAPE)
.short('E') .short('E')
.help("disable interpretation of backslash escapes (default)") .help("disable interpretation of backslash escapes (default)")
.action(ArgAction::SetTrue), .action(ArgAction::SetTrue)
.overrides_with(options::ENABLE_BACKSLASH_ESCAPE),
) )
.arg(Arg::new(options::STRING).action(ArgAction::Append)) .arg(Arg::new(options::STRING).action(ArgAction::Append))
} }

View file

@ -117,6 +117,19 @@ fn test_escape_newline() {
.stdout_only("\na\n"); .stdout_only("\na\n");
} }
#[test]
fn test_escape_override() {
new_ucmd!()
.args(&["-e", "-E", "\\na"])
.succeeds()
.stdout_only("\\na\n");
new_ucmd!()
.args(&["-E", "-e", "\\na"])
.succeeds()
.stdout_only("\na\n");
}
#[test] #[test]
fn test_escape_no_further_output() { fn test_escape_no_further_output() {
new_ucmd!() new_ucmd!()