1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-09-16 19:56:17 +00:00

pinky: update to clap 4

This commit is contained in:
Terts Diepraam 2022-09-30 15:59:22 +02:00
parent a2023c8d15
commit b5ab886f4d
2 changed files with 34 additions and 26 deletions

View file

@ -15,7 +15,7 @@ edition = "2021"
path = "src/pinky.rs" path = "src/pinky.rs"
[dependencies] [dependencies]
clap = { version = "3.2", features = ["wrap_help", "cargo"] } clap = { version = "4.0", features = ["wrap_help", "cargo"] }
uucore = { version=">=0.0.16", package="uucore", path="../../uucore", features=["utmpx", "entries"] } uucore = { version=">=0.0.16", package="uucore", path="../../uucore", features=["utmpx", "entries"] }
[[bin]] [[bin]]

View file

@ -18,7 +18,7 @@ use std::io::BufReader;
use std::fs::File; use std::fs::File;
use std::os::unix::fs::MetadataExt; use std::os::unix::fs::MetadataExt;
use clap::{crate_version, Arg, Command}; use clap::{crate_version, Arg, ArgAction, Command};
use std::path::PathBuf; use std::path::PathBuf;
use uucore::format_usage; use uucore::format_usage;
@ -51,10 +51,8 @@ fn get_long_usage() -> String {
pub fn uumain(args: impl uucore::Args) -> UResult<()> { pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let args = args.collect_ignore(); let args = args.collect_ignore();
let after_help = get_long_usage();
let matches = uu_app() let matches = uu_app()
.after_help(&after_help[..]) .after_help(get_long_usage())
.try_get_matches_from(args)?; .try_get_matches_from(args)?;
let users: Vec<String> = matches let users: Vec<String> = matches
@ -68,35 +66,35 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let mut include_idle = true; let mut include_idle = true;
// If true, display a line at the top describing each field. // If true, display a line at the top describing each field.
let include_heading = !matches.contains_id(options::OMIT_HEADINGS); let include_heading = !matches.get_flag(options::OMIT_HEADINGS);
// if true, display the user's full name from pw_gecos. // if true, display the user's full name from pw_gecos.
let mut include_fullname = true; let mut include_fullname = true;
// if true, display the user's ~/.project file when doing long format. // if true, display the user's ~/.project file when doing long format.
let include_project = !matches.contains_id(options::OMIT_PROJECT_FILE); let include_project = !matches.get_flag(options::OMIT_PROJECT_FILE);
// if true, display the user's ~/.plan file when doing long format. // if true, display the user's ~/.plan file when doing long format.
let include_plan = !matches.contains_id(options::OMIT_PLAN_FILE); let include_plan = !matches.get_flag(options::OMIT_PLAN_FILE);
// if true, display the user's home directory and shell // if true, display the user's home directory and shell
// when doing long format. // when doing long format.
let include_home_and_shell = !matches.contains_id(options::OMIT_HOME_DIR); let include_home_and_shell = !matches.get_flag(options::OMIT_HOME_DIR);
// if true, use the "short" output format. // if true, use the "short" output format.
let do_short_format = !matches.contains_id(options::LONG_FORMAT); let do_short_format = !matches.get_flag(options::LONG_FORMAT);
/* if true, display the ut_host field. */ /* if true, display the ut_host field. */
let mut include_where = true; let mut include_where = true;
if matches.contains_id(options::OMIT_NAME) { if matches.get_flag(options::OMIT_NAME) {
include_fullname = false; include_fullname = false;
} }
if matches.contains_id(options::OMIT_NAME_HOST) { if matches.get_flag(options::OMIT_NAME_HOST) {
include_fullname = false; include_fullname = false;
include_where = false; include_where = false;
} }
if matches.contains_id(options::OMIT_NAME_HOST_TIME) { if matches.get_flag(options::OMIT_NAME_HOST_TIME) {
include_fullname = false; include_fullname = false;
include_idle = false; include_idle = false;
include_where = false; include_where = false;
@ -124,62 +122,71 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
} }
} }
pub fn uu_app<'a>() -> Command<'a> { pub fn uu_app() -> Command {
Command::new(uucore::util_name()) Command::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.override_usage(format_usage(USAGE)) .override_usage(format_usage(USAGE))
.infer_long_args(true) .infer_long_args(true)
.disable_help_flag(true)
.arg( .arg(
Arg::new(options::LONG_FORMAT) Arg::new(options::LONG_FORMAT)
.short('l') .short('l')
.requires(options::USER) .requires(options::USER)
.help("produce long format output for the specified USERs"), .help("produce long format output for the specified USERs")
.action(ArgAction::SetTrue),
) )
.arg( .arg(
Arg::new(options::OMIT_HOME_DIR) Arg::new(options::OMIT_HOME_DIR)
.short('b') .short('b')
.help("omit the user's home directory and shell in long format"), .help("omit the user's home directory and shell in long format")
.action(ArgAction::SetTrue),
) )
.arg( .arg(
Arg::new(options::OMIT_PROJECT_FILE) Arg::new(options::OMIT_PROJECT_FILE)
.short('h') .short('h')
.help("omit the user's project file in long format"), .help("omit the user's project file in long format")
.action(ArgAction::SetTrue),
) )
.arg( .arg(
Arg::new(options::OMIT_PLAN_FILE) Arg::new(options::OMIT_PLAN_FILE)
.short('p') .short('p')
.help("omit the user's plan file in long format"), .help("omit the user's plan file in long format")
.action(ArgAction::SetTrue),
) )
.arg( .arg(
Arg::new(options::SHORT_FORMAT) Arg::new(options::SHORT_FORMAT)
.short('s') .short('s')
.help("do short format output, this is the default"), .help("do short format output, this is the default")
.action(ArgAction::SetTrue),
) )
.arg( .arg(
Arg::new(options::OMIT_HEADINGS) Arg::new(options::OMIT_HEADINGS)
.short('f') .short('f')
.help("omit the line of column headings in short format"), .help("omit the line of column headings in short format")
.action(ArgAction::SetTrue),
) )
.arg( .arg(
Arg::new(options::OMIT_NAME) Arg::new(options::OMIT_NAME)
.short('w') .short('w')
.help("omit the user's full name in short format"), .help("omit the user's full name in short format")
.action(ArgAction::SetTrue),
) )
.arg( .arg(
Arg::new(options::OMIT_NAME_HOST) Arg::new(options::OMIT_NAME_HOST)
.short('i') .short('i')
.help("omit the user's full name and remote host in short format"), .help("omit the user's full name and remote host in short format")
.action(ArgAction::SetTrue),
) )
.arg( .arg(
Arg::new(options::OMIT_NAME_HOST_TIME) Arg::new(options::OMIT_NAME_HOST_TIME)
.short('q') .short('q')
.help("omit the user's full name, remote host and idle time in short format"), .help("omit the user's full name, remote host and idle time in short format")
.action(ArgAction::SetTrue),
) )
.arg( .arg(
Arg::new(options::USER) Arg::new(options::USER)
.takes_value(true) .action(ArgAction::Append)
.multiple_occurrences(true)
.value_hint(clap::ValueHint::Username), .value_hint(clap::ValueHint::Username),
) )
.arg( .arg(
@ -187,7 +194,8 @@ pub fn uu_app<'a>() -> Command<'a> {
// since that conflicts with omit_project_file. // since that conflicts with omit_project_file.
Arg::new(options::HELP) Arg::new(options::HELP)
.long(options::HELP) .long(options::HELP)
.help("Print help information"), .help("Print help information")
.action(ArgAction::Help),
) )
} }