mirror of
https://github.com/uutils/procps.git
synced 2026-06-10 16:14:00 -07:00
ps: Support --no-headers flag
This commit is contained in:
+16
-8
@@ -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::<Vec<String>>();
|
||||
|
||||
// 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::<Vec<String>>();
|
||||
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")
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user