1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-29 12:07:46 +00:00

mkdir: update to clap 4

This commit is contained in:
Terts Diepraam 2022-09-29 22:05:31 +02:00
parent c6cff20f18
commit f432e5809c
2 changed files with 15 additions and 16 deletions

View file

@ -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]]

View file

@ -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::<OsString>(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),
)