From 512d206f1e87b546428c2aa45f8a9ef93ce89bef Mon Sep 17 00:00:00 2001 From: Jan Scheer Date: Thu, 29 Apr 2021 00:11:21 +0200 Subject: [PATCH] who: move from getopts to clap 2.33.3 (#2124) --- src/uu/who/Cargo.toml | 2 +- src/uu/who/src/who.rs | 97 +++++++++++++++++++++------------------ tests/by-util/test_who.rs | 2 +- 3 files changed, 54 insertions(+), 47 deletions(-) diff --git a/src/uu/who/Cargo.toml b/src/uu/who/Cargo.toml index ff1c5b2af..4d8eccb45 100644 --- a/src/uu/who/Cargo.toml +++ b/src/uu/who/Cargo.toml @@ -17,7 +17,7 @@ path = "src/who.rs" [dependencies] uucore = { version=">=0.0.8", package="uucore", path="../../uucore", features=["utmpx"] } uucore_procs = { version=">=0.0.5", package="uucore_procs", path="../../uucore_procs" } -clap = "3.0.0-beta.2" +clap = "2.33.3" [[bin]] name = "who" diff --git a/src/uu/who/src/who.rs b/src/uu/who/src/who.rs index 47c9dfa6e..ba1360eff 100644 --- a/src/uu/who/src/who.rs +++ b/src/uu/who/src/who.rs @@ -63,95 +63,100 @@ pub fn uumain(args: impl uucore::Args) -> i32 { let matches = App::new(executable!()) .version(VERSION) .about(ABOUT) - .override_usage(&usage[..]) + .usage(&usage[..]) .after_help(&after_help[..]) .arg( - Arg::new(options::ALL) + Arg::with_name(options::ALL) .long(options::ALL) - .short('a') - .about("same as -b -d --login -p -r -t -T -u"), + .short("a") + .help("same as -b -d --login -p -r -t -T -u"), ) .arg( - Arg::new(options::BOOT) + Arg::with_name(options::BOOT) .long(options::BOOT) - .short('b') - .about("time of last system boot"), + .short("b") + .help("time of last system boot"), ) .arg( - Arg::new(options::DEAD) + Arg::with_name(options::DEAD) .long(options::DEAD) - .short('d') - .about("print dead processes"), + .short("d") + .help("print dead processes"), ) .arg( - Arg::new(options::HEADING) + Arg::with_name(options::HEADING) .long(options::HEADING) - .short('H') - .about("print line of column headings"), + .short("H") + .help("print line of column headings"), ) .arg( - Arg::new(options::LOGIN) + Arg::with_name(options::LOGIN) .long(options::LOGIN) - .short('l') - .about("print system login processes"), + .short("l") + .help("print system login processes"), ) .arg( - Arg::new(options::LOOKUP) + Arg::with_name(options::LOOKUP) .long(options::LOOKUP) - .about("attempt to canonicalize hostnames via DNS"), + .help("attempt to canonicalize hostnames via DNS"), ) .arg( - Arg::new(options::ONLY_HOSTNAME_USER) - .short('m') - .about("only hostname and user associated with stdin"), + Arg::with_name(options::ONLY_HOSTNAME_USER) + .short("m") + .help("only hostname and user associated with stdin"), ) .arg( - Arg::new(options::PROCESS) + Arg::with_name(options::PROCESS) .long(options::PROCESS) - .short('p') - .about("print active processes spawned by init"), + .short("p") + .help("print active processes spawned by init"), ) .arg( - Arg::new(options::COUNT) + Arg::with_name(options::COUNT) .long(options::COUNT) - .short('q') - .about("all login names and number of users logged on"), + .short("q") + .help("all login names and number of users logged on"), ) .arg( #[cfg(any(target_vendor = "apple", target_os = "linux", target_os = "android"))] - Arg::new(options::RUNLEVEL) + Arg::with_name(options::RUNLEVEL) .long(options::RUNLEVEL) - .short('r') - .about("print current runlevel"), + .short("r") + .help("print current runlevel"), ) .arg( - Arg::new(options::SHORT) + Arg::with_name(options::SHORT) .long(options::SHORT) - .short('s') - .about("print only name, line, and time (default)"), + .short("s") + .help("print only name, line, and time (default)"), ) .arg( - Arg::new(options::TIME) + Arg::with_name(options::TIME) .long(options::TIME) - .short('t') - .about("print last system clock change"), + .short("t") + .help("print last system clock change"), ) .arg( - Arg::new(options::USERS) + Arg::with_name(options::USERS) .long(options::USERS) - .short('u') - .about("list users logged in"), + .short("u") + .help("list users logged in"), ) .arg( - Arg::new(options::MESG) + Arg::with_name(options::MESG) .long(options::MESG) - .short('T') - .visible_short_alias('w') + .short("T") + // .visible_short_alias('w') // TODO: requires clap "3.0.0-beta.2" .visible_aliases(&["message", "writable"]) - .about("add user's message status as +, - or ?"), + .help("add user's message status as +, - or ?"), ) .arg( - Arg::new(options::FILE) + Arg::with_name("w") // work around for `Arg::visible_short_alias` + .short("w") + .help("same as -T"), + ) + .arg( + Arg::with_name(options::FILE) .takes_value(true) .min_values(1) .max_values(2), @@ -184,7 +189,9 @@ pub fn uumain(args: impl uucore::Args) -> i32 { // If true, display a '+' for each user if mesg y, a '-' if mesg n, // or a '?' if their tty cannot be statted. - let include_mesg = matches.is_present(options::ALL) || matches.is_present(options::MESG); + let include_mesg = matches.is_present(options::ALL) + || matches.is_present(options::MESG) + || matches.is_present("w"); // If true, display process termination & exit status. let mut include_exit = false; diff --git a/tests/by-util/test_who.rs b/tests/by-util/test_who.rs index 9bd607ec3..a5637f23a 100644 --- a/tests/by-util/test_who.rs +++ b/tests/by-util/test_who.rs @@ -139,7 +139,7 @@ fn test_arg1_arg2() { #[test] fn test_too_many_args() { let expected = - "error: The value 'u' was provided to '...' but it wasn't expecting any more values"; + "error: The value 'u' was provided to '...', but it wasn't expecting any more values"; new_ucmd!() .arg("am")