Skip to content

Commit

Permalink
Merge pull request #38 from fortifiedhill/implement_w_no_header
Browse files Browse the repository at this point in the history
w: Implement --no-header
  • Loading branch information
sylvestre authored Mar 26, 2024
2 parents 833984e + 331003c commit 386d565
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/uu/w/src/w.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,15 @@ fn fetch_user_info() -> Result<Vec<UserInfo>, std::io::Error> {
}
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
// TODO: rename var when it's used
let _matches = uu_app().try_get_matches_from(args)?;
let matches = uu_app().try_get_matches_from(args)?;

let no_header = matches.get_flag("no-header");

match fetch_user_info() {
Ok(user_info) => {
println!("USER\tTTY\t\tLOGIN@\t\tIDLE\tJCPU\tPCPU\tWHAT");
if !no_header {
println!("USER\tTTY\t\tLOGIN@\t\tIDLE\tJCPU\tPCPU\tWHAT");
}
for user in user_info {
println!(
"{}\t{}\t{}\t{}\t{}\t{}\t{}",
Expand Down
9 changes: 9 additions & 0 deletions tests/by-util/test_w.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,12 @@ use crate::common::util::TestScenario;
fn test_invalid_arg() {
new_ucmd!().arg("--definitely-invalid").fails().code_is(1);
}

#[test]
fn test_no_header() {
let cmd = new_ucmd!().arg("--no-header").succeeds();

let result = cmd.stdout_str();

assert!(!result.contains("USER\tTTY\t\tLOGIN@\t\tIDLE\tJCPU\tPCPU\tWHAT"));
}

0 comments on commit 386d565

Please sign in to comment.