ps: improve the parameter output of the ps command

This commit is contained in:
yushuoqi
2026-04-08 12:24:59 +08:00
parent 46b2b1be38
commit c1801fd264
3 changed files with 23 additions and 5 deletions
+1 -1
View File
@@ -71,7 +71,7 @@ pub struct ProcessSelectionSettings {
impl ProcessSelectionSettings { impl ProcessSelectionSettings {
pub fn from_matches(matches: &ArgMatches) -> Self { pub fn from_matches(matches: &ArgMatches) -> Self {
Self { Self {
select_all: matches.get_flag("A"), select_all: matches.get_flag("A") || matches.get_flag("e"),
select_non_session_leaders_with_tty: matches.get_flag("a"), select_non_session_leaders_with_tty: matches.get_flag("a"),
select_non_session_leaders: matches.get_flag("d"), select_non_session_leaders: matches.get_flag("d"),
dont_require_tty: matches.get_flag("x"), dont_require_tty: matches.get_flag("x"),
+4 -1
View File
@@ -202,7 +202,10 @@ pub fn uu_app() -> Command {
Arg::new("A") Arg::new("A")
.short('A') .short('A')
.help("all processes") .help("all processes")
.visible_short_alias('e') .action(ArgAction::SetTrue),
Arg::new("e")
.short('e')
.help("Select all processes. Identical to -A")
.action(ArgAction::SetTrue), .action(ArgAction::SetTrue),
Arg::new("a") Arg::new("a")
.short('a') .short('a')
+18 -3
View File
@@ -13,9 +13,24 @@ use uucore::process::geteuid;
#[test] #[test]
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
fn test_select_all_processes() { fn test_select_all_processes() {
for arg in ["-A", "-e"] { let expected_headers = ["PID", "TTY", "TIME", "CMD"];
// TODO ensure the output format is correct
new_ucmd!().arg(arg).succeeds(); let args_sets = vec![vec!["-A"], vec!["-e"], vec!["-A", "-e"]];
for args in args_sets {
let result = new_ucmd!().args(&args).succeeds();
let lines: Vec<&str> = result.stdout_str().lines().collect();
assert!(
lines.len() >= 2,
"expected at least a header and one process row"
);
let headers: Vec<&str> = lines[0].split_whitespace().collect();
assert_eq!(
headers, expected_headers,
"unexpected header for args: {:?}",
args
);
} }
} }