mirror of
https://github.com/uutils/procps.git
synced 2026-06-10 16:14:00 -07:00
ps: Implement --deselect flag
This commit is contained in:
@@ -42,6 +42,9 @@ pub struct ProcessSelectionSettings {
|
||||
pub select_non_session_leaders_with_tty: bool,
|
||||
/// - `-d` Select all processes except session leaders.
|
||||
pub select_non_session_leaders: bool,
|
||||
|
||||
/// - `--deselect` Negates the selection.
|
||||
pub negate_selection: bool,
|
||||
}
|
||||
|
||||
impl ProcessSelectionSettings {
|
||||
@@ -50,6 +53,7 @@ impl ProcessSelectionSettings {
|
||||
select_all: matches.get_flag("A"),
|
||||
select_non_session_leaders_with_tty: matches.get_flag("a"),
|
||||
select_non_session_leaders: matches.get_flag("d"),
|
||||
negate_selection: matches.get_flag("deselect"),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,7 +81,7 @@ impl ProcessSelectionSettings {
|
||||
|
||||
let mut selected = vec![];
|
||||
for mut process in walk_process() {
|
||||
if matches_criteria(&mut process)? {
|
||||
if matches_criteria(&mut process)? ^ self.negate_selection {
|
||||
selected.push(process);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -179,3 +179,20 @@ fn test_no_headers_flags() {
|
||||
.stdout_does_not_match(®ex);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(target_os = "linux")]
|
||||
fn test_deselect() {
|
||||
// Inverse of all processes should be empty
|
||||
new_ucmd!()
|
||||
.args(&["--deselect", "-A", "--no-headers"])
|
||||
.fails()
|
||||
.code_is(1)
|
||||
.stdout_is("");
|
||||
|
||||
// PID 1 should be present in inverse of default filter criteria
|
||||
new_ucmd!()
|
||||
.args(&["--deselect"])
|
||||
.succeeds()
|
||||
.stdout_matches(&Regex::new("\n *1 ").unwrap());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user