diff --git a/src/uu/sysctl/src/sysctl.rs b/src/uu/sysctl/src/sysctl.rs index 7a3d9e96..eef80099 100644 --- a/src/uu/sysctl/src/sysctl.rs +++ b/src/uu/sysctl/src/sysctl.rs @@ -234,11 +234,13 @@ pub fn uu_app() -> Command { .arg( Arg::new("noop_o") .short('o') + .action(ArgAction::SetTrue) .help("Does nothing, for BSD compatibility"), ) .arg( Arg::new("noop_x") .short('x') + .action(ArgAction::SetTrue) .help("Does nothing, for BSD compatibility"), ) } diff --git a/tests/by-util/test_sysctl.rs b/tests/by-util/test_sysctl.rs index 100a13e2..23c7fcc5 100644 --- a/tests/by-util/test_sysctl.rs +++ b/tests/by-util/test_sysctl.rs @@ -118,6 +118,28 @@ mod linux { .code_is(1) .no_stdout(); } + + // procps-ng treats -o and -x as no-op flags (BSD compatibility), not options + // that take a value. Without SetTrue, clap would consume the next operand. + #[test] + fn test_noop_flags_do_not_take_a_value() { + new_ucmd!() + .args(&["-o", "kernel.ostype"]) + .succeeds() + .stdout_is("kernel.ostype = Linux\n"); + new_ucmd!() + .args(&["-x", "kernel.ostype"]) + .succeeds() + .stdout_is("kernel.ostype = Linux\n"); + new_ucmd!() + .args(&["-o", "-n", "kernel.ostype"]) + .succeeds() + .stdout_is("Linux\n"); + new_ucmd!() + .args(&["-ox", "kernel.ostype"]) + .succeeds() + .stdout_is("kernel.ostype = Linux\n"); + } } #[cfg(not(target_os = "linux"))]