mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
Merge pull request #6997 from cakebaker/echo_handle_double_hyphen
echo: handle double hyphens
This commit is contained in:
commit
b4cdc36573
2 changed files with 31 additions and 7 deletions
|
@ -255,9 +255,26 @@ fn print_escaped(input: &[u8], output: &mut StdoutLock) -> io::Result<ControlFlo
|
||||||
Ok(ControlFlow::Continue(()))
|
Ok(ControlFlow::Continue(()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// A workaround because clap interprets the first '--' as a marker that a value
|
||||||
|
// follows. In order to use '--' as a value, we have to inject an additional '--'
|
||||||
|
fn handle_double_hyphens(args: impl uucore::Args) -> impl uucore::Args {
|
||||||
|
let mut result = Vec::new();
|
||||||
|
let mut is_first_double_hyphen = true;
|
||||||
|
|
||||||
|
for arg in args {
|
||||||
|
if arg == "--" && is_first_double_hyphen {
|
||||||
|
result.push(OsString::from("--"));
|
||||||
|
is_first_double_hyphen = false;
|
||||||
|
}
|
||||||
|
result.push(arg);
|
||||||
|
}
|
||||||
|
|
||||||
|
result.into_iter()
|
||||||
|
}
|
||||||
|
|
||||||
#[uucore::main]
|
#[uucore::main]
|
||||||
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||||
let matches = uu_app().get_matches_from(args);
|
let matches = uu_app().get_matches_from(handle_double_hyphens(args));
|
||||||
|
|
||||||
// TODO
|
// TODO
|
||||||
// "If the POSIXLY_CORRECT environment variable is set, then when echo’s first argument is not -n it outputs option-like arguments instead of treating them as options."
|
// "If the POSIXLY_CORRECT environment variable is set, then when echo’s first argument is not -n it outputs option-like arguments instead of treating them as options."
|
||||||
|
|
|
@ -219,8 +219,7 @@ fn test_hyphen_values_at_start() {
|
||||||
.arg("-test")
|
.arg("-test")
|
||||||
.arg("araba")
|
.arg("araba")
|
||||||
.arg("-merci")
|
.arg("-merci")
|
||||||
.run()
|
.succeeds()
|
||||||
.success()
|
|
||||||
.stdout_does_not_contain("-E")
|
.stdout_does_not_contain("-E")
|
||||||
.stdout_is("-test araba -merci\n");
|
.stdout_is("-test araba -merci\n");
|
||||||
}
|
}
|
||||||
|
@ -231,8 +230,7 @@ fn test_hyphen_values_between() {
|
||||||
.arg("test")
|
.arg("test")
|
||||||
.arg("-E")
|
.arg("-E")
|
||||||
.arg("araba")
|
.arg("araba")
|
||||||
.run()
|
.succeeds()
|
||||||
.success()
|
|
||||||
.stdout_is("test -E araba\n");
|
.stdout_is("test -E araba\n");
|
||||||
|
|
||||||
new_ucmd!()
|
new_ucmd!()
|
||||||
|
@ -240,11 +238,20 @@ fn test_hyphen_values_between() {
|
||||||
.arg("dum dum dum")
|
.arg("dum dum dum")
|
||||||
.arg("-e")
|
.arg("-e")
|
||||||
.arg("dum")
|
.arg("dum")
|
||||||
.run()
|
.succeeds()
|
||||||
.success()
|
|
||||||
.stdout_is("dumdum dum dum dum -e dum\n");
|
.stdout_is("dumdum dum dum dum -e dum\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_double_hyphens() {
|
||||||
|
new_ucmd!().arg("--").succeeds().stdout_only("--\n");
|
||||||
|
new_ucmd!()
|
||||||
|
.arg("--")
|
||||||
|
.arg("--")
|
||||||
|
.succeeds()
|
||||||
|
.stdout_only("-- --\n");
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn wrapping_octal() {
|
fn wrapping_octal() {
|
||||||
// Some odd behavior of GNU. Values of \0400 and greater do not fit in the
|
// Some odd behavior of GNU. Values of \0400 and greater do not fit in the
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue