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

basename: update to clap 4

This commit is contained in:
Terts Diepraam 2022-09-29 15:23:27 +02:00
parent 26309dc9d7
commit 649dab36f1
3 changed files with 12 additions and 10 deletions

View file

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

View file

@ -7,7 +7,7 @@
// spell-checker:ignore (ToDO) fullname // spell-checker:ignore (ToDO) fullname
use clap::{crate_version, Arg, Command}; use clap::{crate_version, Arg, ArgAction, Command};
use std::path::{is_separator, PathBuf}; use std::path::{is_separator, PathBuf};
use uucore::display::Quotable; use uucore::display::Quotable;
use uucore::error::{UResult, UUsageError}; use uucore::error::{UResult, UUsageError};
@ -56,9 +56,9 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
return Err(UUsageError::new(1, "missing operand".to_string())); return Err(UUsageError::new(1, "missing operand".to_string()));
} }
let opt_suffix = matches.contains_id(options::SUFFIX); let opt_suffix = matches.get_one::<String>(options::SUFFIX).is_some();
let opt_multiple = matches.contains_id(options::MULTIPLE); let opt_multiple = matches.get_flag(options::MULTIPLE);
let opt_zero = matches.contains_id(options::ZERO); let opt_zero = matches.get_flag(options::ZERO);
let multiple_paths = opt_suffix || opt_multiple; let multiple_paths = opt_suffix || opt_multiple;
let name_args_count = matches let name_args_count = matches
.get_many::<String>(options::NAME) .get_many::<String>(options::NAME)
@ -115,7 +115,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
Ok(()) Ok(())
} }
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)
@ -125,11 +125,12 @@ pub fn uu_app<'a>() -> Command<'a> {
Arg::new(options::MULTIPLE) Arg::new(options::MULTIPLE)
.short('a') .short('a')
.long(options::MULTIPLE) .long(options::MULTIPLE)
.help("support multiple arguments and treat each as a NAME"), .help("support multiple arguments and treat each as a NAME")
.action(ArgAction::SetTrue),
) )
.arg( .arg(
Arg::new(options::NAME) Arg::new(options::NAME)
.multiple_occurrences(true) .action(clap::ArgAction::Append)
.value_hint(clap::ValueHint::AnyPath) .value_hint(clap::ValueHint::AnyPath)
.hide(true), .hide(true),
) )
@ -144,7 +145,8 @@ pub fn uu_app<'a>() -> Command<'a> {
Arg::new(options::ZERO) Arg::new(options::ZERO)
.short('z') .short('z')
.long(options::ZERO) .long(options::ZERO)
.help("end each output line with NUL, not newline"), .help("end each output line with NUL, not newline")
.action(ArgAction::SetTrue),
) )
} }

View file

@ -11,7 +11,7 @@ fn test_help() {
.arg(help_flg) .arg(help_flg)
.succeeds() .succeeds()
.no_stderr() .no_stderr()
.stdout_contains("USAGE:"); .stdout_contains("Usage:");
} }
} }