mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 03:27:44 +00:00
echo: handle double hyphens
This commit is contained in:
parent
2c2f5f14a4
commit
90465357e2
2 changed files with 28 additions and 1 deletions
|
@ -255,9 +255,26 @@ fn print_escaped(input: &[u8], output: &mut StdoutLock) -> io::Result<ControlFlo
|
|||
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]
|
||||
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
|
||||
// "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."
|
||||
|
|
|
@ -242,6 +242,16 @@ fn test_hyphen_values_between() {
|
|||
.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]
|
||||
fn wrapping_octal() {
|
||||
// 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