1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 11:37:44 +00:00

who: move from getopts to clap 2.33.3 (#2124)

This commit is contained in:
Jan Scheer 2021-04-29 00:11:21 +02:00
parent 6f16cafe88
commit 512d206f1e
3 changed files with 54 additions and 47 deletions

View file

@ -17,7 +17,7 @@ path = "src/who.rs"
[dependencies] [dependencies]
uucore = { version=">=0.0.8", package="uucore", path="../../uucore", features=["utmpx"] } uucore = { version=">=0.0.8", package="uucore", path="../../uucore", features=["utmpx"] }
uucore_procs = { version=">=0.0.5", package="uucore_procs", path="../../uucore_procs" } uucore_procs = { version=">=0.0.5", package="uucore_procs", path="../../uucore_procs" }
clap = "3.0.0-beta.2" clap = "2.33.3"
[[bin]] [[bin]]
name = "who" name = "who"

View file

@ -63,95 +63,100 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
let matches = App::new(executable!()) let matches = App::new(executable!())
.version(VERSION) .version(VERSION)
.about(ABOUT) .about(ABOUT)
.override_usage(&usage[..]) .usage(&usage[..])
.after_help(&after_help[..]) .after_help(&after_help[..])
.arg( .arg(
Arg::new(options::ALL) Arg::with_name(options::ALL)
.long(options::ALL) .long(options::ALL)
.short('a') .short("a")
.about("same as -b -d --login -p -r -t -T -u"), .help("same as -b -d --login -p -r -t -T -u"),
) )
.arg( .arg(
Arg::new(options::BOOT) Arg::with_name(options::BOOT)
.long(options::BOOT) .long(options::BOOT)
.short('b') .short("b")
.about("time of last system boot"), .help("time of last system boot"),
) )
.arg( .arg(
Arg::new(options::DEAD) Arg::with_name(options::DEAD)
.long(options::DEAD) .long(options::DEAD)
.short('d') .short("d")
.about("print dead processes"), .help("print dead processes"),
) )
.arg( .arg(
Arg::new(options::HEADING) Arg::with_name(options::HEADING)
.long(options::HEADING) .long(options::HEADING)
.short('H') .short("H")
.about("print line of column headings"), .help("print line of column headings"),
) )
.arg( .arg(
Arg::new(options::LOGIN) Arg::with_name(options::LOGIN)
.long(options::LOGIN) .long(options::LOGIN)
.short('l') .short("l")
.about("print system login processes"), .help("print system login processes"),
) )
.arg( .arg(
Arg::new(options::LOOKUP) Arg::with_name(options::LOOKUP)
.long(options::LOOKUP) .long(options::LOOKUP)
.about("attempt to canonicalize hostnames via DNS"), .help("attempt to canonicalize hostnames via DNS"),
) )
.arg( .arg(
Arg::new(options::ONLY_HOSTNAME_USER) Arg::with_name(options::ONLY_HOSTNAME_USER)
.short('m') .short("m")
.about("only hostname and user associated with stdin"), .help("only hostname and user associated with stdin"),
) )
.arg( .arg(
Arg::new(options::PROCESS) Arg::with_name(options::PROCESS)
.long(options::PROCESS) .long(options::PROCESS)
.short('p') .short("p")
.about("print active processes spawned by init"), .help("print active processes spawned by init"),
) )
.arg( .arg(
Arg::new(options::COUNT) Arg::with_name(options::COUNT)
.long(options::COUNT) .long(options::COUNT)
.short('q') .short("q")
.about("all login names and number of users logged on"), .help("all login names and number of users logged on"),
) )
.arg( .arg(
#[cfg(any(target_vendor = "apple", target_os = "linux", target_os = "android"))] #[cfg(any(target_vendor = "apple", target_os = "linux", target_os = "android"))]
Arg::new(options::RUNLEVEL) Arg::with_name(options::RUNLEVEL)
.long(options::RUNLEVEL) .long(options::RUNLEVEL)
.short('r') .short("r")
.about("print current runlevel"), .help("print current runlevel"),
) )
.arg( .arg(
Arg::new(options::SHORT) Arg::with_name(options::SHORT)
.long(options::SHORT) .long(options::SHORT)
.short('s') .short("s")
.about("print only name, line, and time (default)"), .help("print only name, line, and time (default)"),
) )
.arg( .arg(
Arg::new(options::TIME) Arg::with_name(options::TIME)
.long(options::TIME) .long(options::TIME)
.short('t') .short("t")
.about("print last system clock change"), .help("print last system clock change"),
) )
.arg( .arg(
Arg::new(options::USERS) Arg::with_name(options::USERS)
.long(options::USERS) .long(options::USERS)
.short('u') .short("u")
.about("list users logged in"), .help("list users logged in"),
) )
.arg( .arg(
Arg::new(options::MESG) Arg::with_name(options::MESG)
.long(options::MESG) .long(options::MESG)
.short('T') .short("T")
.visible_short_alias('w') // .visible_short_alias('w') // TODO: requires clap "3.0.0-beta.2"
.visible_aliases(&["message", "writable"]) .visible_aliases(&["message", "writable"])
.about("add user's message status as +, - or ?"), .help("add user's message status as +, - or ?"),
) )
.arg( .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) .takes_value(true)
.min_values(1) .min_values(1)
.max_values(2), .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, // If true, display a '+' for each user if mesg y, a '-' if mesg n,
// or a '?' if their tty cannot be statted. // 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. // If true, display process termination & exit status.
let mut include_exit = false; let mut include_exit = false;

View file

@ -139,7 +139,7 @@ fn test_arg1_arg2() {
#[test] #[test]
fn test_too_many_args() { fn test_too_many_args() {
let expected = let expected =
"error: The value 'u' was provided to '<FILE>...' but it wasn't expecting any more values"; "error: The value 'u' was provided to '<FILE>...', but it wasn't expecting any more values";
new_ucmd!() new_ucmd!()
.arg("am") .arg("am")