From f432e5809c6ad5dcf51d9c06eda8afff1733eaa9 Mon Sep 17 00:00:00 2001 From: Terts Diepraam Date: Thu, 29 Sep 2022 22:05:31 +0200 Subject: [PATCH] mkdir: update to clap 4 --- src/uu/mkdir/Cargo.toml | 2 +- src/uu/mkdir/src/mkdir.rs | 29 ++++++++++++++--------------- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/src/uu/mkdir/Cargo.toml b/src/uu/mkdir/Cargo.toml index d855cd3f0..54a644ca2 100644 --- a/src/uu/mkdir/Cargo.toml +++ b/src/uu/mkdir/Cargo.toml @@ -15,7 +15,7 @@ edition = "2021" path = "src/mkdir.rs" [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=["fs", "mode"] } [[bin]] diff --git a/src/uu/mkdir/src/mkdir.rs b/src/uu/mkdir/src/mkdir.rs index 02e357dc3..e922ec1d1 100644 --- a/src/uu/mkdir/src/mkdir.rs +++ b/src/uu/mkdir/src/mkdir.rs @@ -12,7 +12,7 @@ extern crate uucore; use clap::builder::ValueParser; use clap::parser::ValuesRef; -use clap::{crate_version, Arg, ArgMatches, Command}; +use clap::{crate_version, Arg, ArgAction, ArgMatches, Command}; use std::ffi::OsString; use std::path::{Path, PathBuf}; #[cfg(not(windows))] @@ -35,8 +35,8 @@ mod options { pub const DIRS: &str = "dirs"; } -fn get_long_usage() -> String { - String::from("Each MODE is of the form '[ugoa]*([-+=]([rwxXst]*|[ugo]))+|[-+=]?[0-7]+'.") +fn get_long_usage() -> &'static str { + "Each MODE is of the form '[ugoa]*([-+=]([rwxXst]*|[ugo]))+|[-+=]?[0-7]+'." } #[cfg(windows)] @@ -91,20 +91,19 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { // Before we can parse 'args' with clap (and previously getopts), // a possible MODE prefix '-' needs to be removed (e.g. "chmod -x FILE"). let mode_had_minus_prefix = strip_minus_from_mode(&mut args); - let after_help = get_long_usage(); // Linux-specific options, not implemented // opts.optflag("Z", "context", "set SELinux security context" + // " of each created directory to CTX"), let matches = uu_app() - .after_help(&after_help[..]) + .after_help(get_long_usage()) .try_get_matches_from(args)?; let dirs = matches .get_many::(options::DIRS) .unwrap_or_default(); - let verbose = matches.contains_id(options::VERBOSE); - let recursive = matches.contains_id(options::PARENTS); + let verbose = matches.get_flag(options::VERBOSE); + let recursive = matches.get_flag(options::PARENTS); match get_mode(&matches, mode_had_minus_prefix) { Ok(mode) => exec(dirs, recursive, mode, verbose), @@ -112,7 +111,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()) .version(crate_version!()) .about(ABOUT) @@ -122,26 +121,26 @@ pub fn uu_app<'a>() -> Command<'a> { Arg::new(options::MODE) .short('m') .long(options::MODE) - .help("set file mode (not implemented on windows)") - .takes_value(true), + .help("set file mode (not implemented on windows)"), ) .arg( Arg::new(options::PARENTS) .short('p') .long(options::PARENTS) - .help("make parent directories as needed"), + .help("make parent directories as needed") + .action(ArgAction::SetTrue), ) .arg( Arg::new(options::VERBOSE) .short('v') .long(options::VERBOSE) - .help("print a message for each printed directory"), + .help("print a message for each printed directory") + .action(ArgAction::SetTrue), ) .arg( Arg::new(options::DIRS) - .multiple_occurrences(true) - .takes_value(true) - .min_values(1) + .action(ArgAction::Append) + .num_args(1..) .value_parser(ValueParser::os_string()) .value_hint(clap::ValueHint::DirPath), )