diff --git a/src/uu/ps/src/ps.rs b/src/uu/ps/src/ps.rs index 91cc30a..f2df665 100644 --- a/src/uu/ps/src/ps.rs +++ b/src/uu/ps/src/ps.rs @@ -106,15 +106,16 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { collect_code_mapping(&arg_formats) }; - let header = code_mapping - .iter() - .map(|(_, header)| header) - .map(Into::into) - .collect::>(); - - // Apply header - let mut table = Table::from_iter([Row::from_iter(header)]); + let mut table = Table::new(); table.set_format(*FORMAT_CLEAN); + if !matches.get_flag("no-headers") { + let header = code_mapping + .iter() + .map(|(_, header)| header) + .map(Into::into) + .collect::>(); + table.add_row(Row::from_iter(header)); + } table.extend(rows); print!("{table}"); @@ -263,6 +264,13 @@ pub fn uu_app() -> Command { .value_parser(parser) .help("user-defined format"), ) + .arg( + Arg::new("no-headers") + .long("no-headers") + .visible_alias("no-heading") + .action(ArgAction::SetTrue) + .help("do not print header at all"), + ) // .args([ // Arg::new("command").short('c').help("command name"), // Arg::new("GID") diff --git a/tests/by-util/test_ps.rs b/tests/by-util/test_ps.rs index f707d5c..bc3e41d 100644 --- a/tests/by-util/test_ps.rs +++ b/tests/by-util/test_ps.rs @@ -3,6 +3,8 @@ // For the full copyright and license information, please view the LICENSE // file that was distributed with this source code. +#[cfg(target_os = "linux")] +use regex::Regex; use uutests::new_ucmd; #[test] @@ -165,3 +167,15 @@ fn test_code_mapping() { .stdout_contains("CMD1") .stdout_contains("CMD2"); } + +#[test] +#[cfg(target_os = "linux")] +fn test_no_headers_flags() { + let regex = Regex::new("^ *PID +").unwrap(); + for flag in &["--no-headers", "--no-heading"] { + new_ucmd!() + .arg(flag) + .succeeds() + .stdout_does_not_match(®ex); + } +}