Skip to content

Commit

Permalink
Merge pull request #65 from cakebaker/w_help
Browse files Browse the repository at this point in the history
w: add `--help`
  • Loading branch information
sylvestre authored Apr 18, 2024
2 parents b5bafe7 + 93f813b commit 0be3823
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/uu/w/src/w.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,12 @@ pub fn uu_app() -> Command {
.override_usage(format_usage(USAGE))
.infer_long_args(true)
.disable_help_flag(true)
.arg(
Arg::new("help")
.long("help")
.help("Print help information")
.action(ArgAction::Help),
)
.arg(
Arg::new("no-header")
.short('h')
Expand Down
17 changes: 14 additions & 3 deletions tests/by-util/test_w.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,24 @@ fn test_invalid_arg() {
new_ucmd!().arg("--definitely-invalid").fails().code_is(1);
}

#[test]
fn test_help() {
new_ucmd!()
.arg("--help")
.succeeds()
.stdout_contains("Usage")
.stdout_contains("Options");
}

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

let result = cmd.stdout_str();
let result = cmd.stdout_str();

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

#[test]
Expand Down

0 comments on commit 0be3823

Please sign in to comment.