stat: update to clap 4

This commit is contained in:
Terts Diepraam 2022-10-01 00:07:14 +02:00
parent 261b18d6f3
commit 1f67351efa
2 changed files with 14 additions and 15 deletions

View file

@ -15,7 +15,7 @@ edition = "2021"
path = "src/stat.rs" path = "src/stat.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=["entries", "libc", "fs", "fsext"] } uucore = { version=">=0.0.16", package="uucore", path="../../uucore", features=["entries", "libc", "fs", "fsext"] }
[[bin]] [[bin]]

View file

@ -17,7 +17,7 @@ use uucore::fsext::{
use uucore::libc::mode_t; use uucore::libc::mode_t;
use uucore::{entries, format_usage}; use uucore::{entries, format_usage};
use clap::{crate_version, Arg, ArgMatches, Command}; use clap::{crate_version, Arg, ArgAction, ArgMatches, Command};
use std::borrow::Cow; use std::borrow::Cow;
use std::convert::AsRef; use std::convert::AsRef;
use std::ffi::{OsStr, OsString}; use std::ffi::{OsStr, OsString};
@ -522,8 +522,8 @@ impl Stater {
}; };
let use_printf = matches.contains_id(options::PRINTF); let use_printf = matches.contains_id(options::PRINTF);
let terse = matches.contains_id(options::TERSE); let terse = matches.get_flag(options::TERSE);
let show_fs = matches.contains_id(options::FILE_SYSTEM); let show_fs = matches.get_flag(options::FILE_SYSTEM);
let default_tokens = if format_str.is_empty() { let default_tokens = if format_str.is_empty() {
Self::generate_tokens(&Self::default_format(show_fs, terse, false), use_printf)? Self::generate_tokens(&Self::default_format(show_fs, terse, false), use_printf)?
@ -549,7 +549,7 @@ impl Stater {
}; };
Ok(Self { Ok(Self {
follow: matches.contains_id(options::DEREFERENCE), follow: matches.get_flag(options::DEREFERENCE),
show_fs, show_fs,
from_user: !format_str.is_empty(), from_user: !format_str.is_empty(),
files, files,
@ -1018,10 +1018,8 @@ for details about the options it supports.
#[uucore::main] #[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> { pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let long_usage = get_long_usage();
let matches = uu_app() let matches = uu_app()
.after_help(&long_usage[..]) .after_help(get_long_usage())
.try_get_matches_from(args)?; .try_get_matches_from(args)?;
let stater = Stater::new(&matches)?; let stater = Stater::new(&matches)?;
@ -1033,7 +1031,7 @@ 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)
@ -1043,19 +1041,22 @@ pub fn uu_app<'a>() -> Command<'a> {
Arg::new(options::DEREFERENCE) Arg::new(options::DEREFERENCE)
.short('L') .short('L')
.long(options::DEREFERENCE) .long(options::DEREFERENCE)
.help("follow links"), .help("follow links")
.action(ArgAction::SetTrue),
) )
.arg( .arg(
Arg::new(options::FILE_SYSTEM) Arg::new(options::FILE_SYSTEM)
.short('f') .short('f')
.long(options::FILE_SYSTEM) .long(options::FILE_SYSTEM)
.help("display file system status instead of file status"), .help("display file system status instead of file status")
.action(ArgAction::SetTrue),
) )
.arg( .arg(
Arg::new(options::TERSE) Arg::new(options::TERSE)
.short('t') .short('t')
.long(options::TERSE) .long(options::TERSE)
.help("print the information in terse form"), .help("print the information in terse form")
.action(ArgAction::SetTrue),
) )
.arg( .arg(
Arg::new(options::FORMAT) Arg::new(options::FORMAT)
@ -1079,10 +1080,8 @@ pub fn uu_app<'a>() -> Command<'a> {
) )
.arg( .arg(
Arg::new(ARG_FILES) Arg::new(ARG_FILES)
.multiple_occurrences(true) .action(ArgAction::Append)
.takes_value(true)
.value_parser(ValueParser::os_string()) .value_parser(ValueParser::os_string())
.min_values(1)
.value_hint(clap::ValueHint::FilePath), .value_hint(clap::ValueHint::FilePath),
) )
} }