Skip to content

Commit a7412c4

Browse files
Merge pull request #664 from Franklin-Qi/improve-the-parameters-output-of-the-ps-command
ps: improve the parameter output of the ps command
2 parents ef26896 + c1801fd commit a7412c4

3 files changed

Lines changed: 23 additions & 5 deletions

File tree

src/uu/ps/src/process_selection.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ pub struct ProcessSelectionSettings {
7171
impl ProcessSelectionSettings {
7272
pub fn from_matches(matches: &ArgMatches) -> Self {
7373
Self {
74-
select_all: matches.get_flag("A"),
74+
select_all: matches.get_flag("A") || matches.get_flag("e"),
7575
select_non_session_leaders_with_tty: matches.get_flag("a"),
7676
select_non_session_leaders: matches.get_flag("d"),
7777
dont_require_tty: matches.get_flag("x"),

src/uu/ps/src/ps.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,10 @@ pub fn uu_app() -> Command {
202202
Arg::new("A")
203203
.short('A')
204204
.help("all processes")
205-
.visible_short_alias('e')
205+
.action(ArgAction::SetTrue),
206+
Arg::new("e")
207+
.short('e')
208+
.help("Select all processes. Identical to -A")
206209
.action(ArgAction::SetTrue),
207210
Arg::new("a")
208211
.short('a')

tests/by-util/test_ps.rs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,24 @@ use uucore::process::geteuid;
1313
#[test]
1414
#[cfg(target_os = "linux")]
1515
fn test_select_all_processes() {
16-
for arg in ["-A", "-e"] {
17-
// TODO ensure the output format is correct
18-
new_ucmd!().arg(arg).succeeds();
16+
let expected_headers = ["PID", "TTY", "TIME", "CMD"];
17+
18+
let args_sets = vec![vec!["-A"], vec!["-e"], vec!["-A", "-e"]];
19+
for args in args_sets {
20+
let result = new_ucmd!().args(&args).succeeds();
21+
let lines: Vec<&str> = result.stdout_str().lines().collect();
22+
23+
assert!(
24+
lines.len() >= 2,
25+
"expected at least a header and one process row"
26+
);
27+
28+
let headers: Vec<&str> = lines[0].split_whitespace().collect();
29+
assert_eq!(
30+
headers, expected_headers,
31+
"unexpected header for args: {:?}",
32+
args
33+
);
1934
}
2035
}
2136

0 commit comments

Comments
 (0)