1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-27 19:17:43 +00:00

who: clap 3

This commit is contained in:
Terts Diepraam 2022-01-11 15:22:12 +01:00
parent e9e5768591
commit e3b8e6c993
3 changed files with 34 additions and 34 deletions

View file

@ -17,7 +17,7 @@ path = "src/who.rs"
[dependencies] [dependencies]
uucore = { version=">=0.0.10", package="uucore", path="../../uucore", features=["utmpx"] } uucore = { version=">=0.0.10", package="uucore", path="../../uucore", features=["utmpx"] }
uucore_procs = { version=">=0.0.7", package="uucore_procs", path="../../uucore_procs" } uucore_procs = { version=">=0.0.7", package="uucore_procs", path="../../uucore_procs" }
clap = { version = "2.33", features = ["wrap_help"] } clap = { version = "3.0", features = ["wrap_help", "cargo"] }
[[bin]] [[bin]]
name = "who" name = "who"

View file

@ -69,7 +69,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let after_help = get_long_usage(); let after_help = get_long_usage();
let matches = uu_app() let matches = uu_app()
.usage(&usage[..]) .override_usage(&usage[..])
.after_help(&after_help[..]) .after_help(&after_help[..])
.get_matches_from(args); .get_matches_from(args);
@ -161,101 +161,101 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
who.exec() who.exec()
} }
pub fn uu_app() -> App<'static, 'static> { pub fn uu_app<'a>() -> App<'a> {
App::new(uucore::util_name()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.arg( .arg(
Arg::with_name(options::ALL) Arg::new(options::ALL)
.long(options::ALL) .long(options::ALL)
.short("a") .short('a')
.help("same as -b -d --login -p -r -t -T -u"), .help("same as -b -d --login -p -r -t -T -u"),
) )
.arg( .arg(
Arg::with_name(options::BOOT) Arg::new(options::BOOT)
.long(options::BOOT) .long(options::BOOT)
.short("b") .short('b')
.help("time of last system boot"), .help("time of last system boot"),
) )
.arg( .arg(
Arg::with_name(options::DEAD) Arg::new(options::DEAD)
.long(options::DEAD) .long(options::DEAD)
.short("d") .short('d')
.help("print dead processes"), .help("print dead processes"),
) )
.arg( .arg(
Arg::with_name(options::HEADING) Arg::new(options::HEADING)
.long(options::HEADING) .long(options::HEADING)
.short("H") .short('H')
.help("print line of column headings"), .help("print line of column headings"),
) )
.arg( .arg(
Arg::with_name(options::LOGIN) Arg::new(options::LOGIN)
.long(options::LOGIN) .long(options::LOGIN)
.short("l") .short('l')
.help("print system login processes"), .help("print system login processes"),
) )
.arg( .arg(
Arg::with_name(options::LOOKUP) Arg::new(options::LOOKUP)
.long(options::LOOKUP) .long(options::LOOKUP)
.help("attempt to canonicalize hostnames via DNS"), .help("attempt to canonicalize hostnames via DNS"),
) )
.arg( .arg(
Arg::with_name(options::ONLY_HOSTNAME_USER) Arg::new(options::ONLY_HOSTNAME_USER)
.short("m") .short('m')
.help("only hostname and user associated with stdin"), .help("only hostname and user associated with stdin"),
) )
.arg( .arg(
Arg::with_name(options::PROCESS) Arg::new(options::PROCESS)
.long(options::PROCESS) .long(options::PROCESS)
.short("p") .short('p')
.help("print active processes spawned by init"), .help("print active processes spawned by init"),
) )
.arg( .arg(
Arg::with_name(options::COUNT) Arg::new(options::COUNT)
.long(options::COUNT) .long(options::COUNT)
.short("q") .short('q')
.help("all login names and number of users logged on"), .help("all login names and number of users logged on"),
) )
.arg( .arg(
Arg::with_name(options::RUNLEVEL) Arg::new(options::RUNLEVEL)
.long(options::RUNLEVEL) .long(options::RUNLEVEL)
.short("r") .short('r')
.help(RUNLEVEL_HELP), .help(RUNLEVEL_HELP),
) )
.arg( .arg(
Arg::with_name(options::SHORT) Arg::new(options::SHORT)
.long(options::SHORT) .long(options::SHORT)
.short("s") .short('s')
.help("print only name, line, and time (default)"), .help("print only name, line, and time (default)"),
) )
.arg( .arg(
Arg::with_name(options::TIME) Arg::new(options::TIME)
.long(options::TIME) .long(options::TIME)
.short("t") .short('t')
.help("print last system clock change"), .help("print last system clock change"),
) )
.arg( .arg(
Arg::with_name(options::USERS) Arg::new(options::USERS)
.long(options::USERS) .long(options::USERS)
.short("u") .short('u')
.help("list users logged in"), .help("list users logged in"),
) )
.arg( .arg(
Arg::with_name(options::MESG) Arg::new(options::MESG)
.long(options::MESG) .long(options::MESG)
.short("T") .short('T')
// .visible_short_alias('w') // TODO: requires clap "3.0.0-beta.2" // .visible_short_alias('w') // TODO: requires clap "3.0.0-beta.2"
.visible_aliases(&["message", "writable"]) .visible_aliases(&["message", "writable"])
.help("add user's message status as +, - or ?"), .help("add user's message status as +, - or ?"),
) )
.arg( .arg(
Arg::with_name("w") // work around for `Arg::visible_short_alias` Arg::new("w") // work around for `Arg::visible_short_alias`
.short("w") .short('w')
.help("same as -T"), .help("same as -T"),
) )
.arg( .arg(
Arg::with_name(options::FILE) Arg::new(options::FILE)
.takes_value(true) .takes_value(true)
.min_values(1) .min_values(1)
.max_values(2), .max_values(2),

View file

@ -136,7 +136,7 @@ fn test_arg1_arg2() {
#[test] #[test]
fn test_too_many_args() { fn test_too_many_args() {
const EXPECTED: &str = const EXPECTED: &str =
"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";
let args = ["am", "i", "u"]; let args = ["am", "i", "u"];
new_ucmd!().args(&args).fails().stderr_contains(EXPECTED); new_ucmd!().args(&args).fails().stderr_contains(EXPECTED);