mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-30 04:27:45 +00:00
mkdir: update to clap 4
This commit is contained in:
parent
c6cff20f18
commit
f432e5809c
2 changed files with 15 additions and 16 deletions
|
@ -15,7 +15,7 @@ edition = "2021"
|
||||||
path = "src/mkdir.rs"
|
path = "src/mkdir.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=["fs", "mode"] }
|
uucore = { version=">=0.0.16", package="uucore", path="../../uucore", features=["fs", "mode"] }
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
|
|
|
@ -12,7 +12,7 @@ extern crate uucore;
|
||||||
|
|
||||||
use clap::builder::ValueParser;
|
use clap::builder::ValueParser;
|
||||||
use clap::parser::ValuesRef;
|
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::ffi::OsString;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
#[cfg(not(windows))]
|
#[cfg(not(windows))]
|
||||||
|
@ -35,8 +35,8 @@ mod options {
|
||||||
pub const DIRS: &str = "dirs";
|
pub const DIRS: &str = "dirs";
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_long_usage() -> String {
|
fn get_long_usage() -> &'static str {
|
||||||
String::from("Each MODE is of the form '[ugoa]*([-+=]([rwxXst]*|[ugo]))+|[-+=]?[0-7]+'.")
|
"Each MODE is of the form '[ugoa]*([-+=]([rwxXst]*|[ugo]))+|[-+=]?[0-7]+'."
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
|
@ -91,20 +91,19 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||||
// Before we can parse 'args' with clap (and previously getopts),
|
// Before we can parse 'args' with clap (and previously getopts),
|
||||||
// a possible MODE prefix '-' needs to be removed (e.g. "chmod -x FILE").
|
// 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 mode_had_minus_prefix = strip_minus_from_mode(&mut args);
|
||||||
let after_help = get_long_usage();
|
|
||||||
|
|
||||||
// Linux-specific options, not implemented
|
// Linux-specific options, not implemented
|
||||||
// opts.optflag("Z", "context", "set SELinux security context" +
|
// opts.optflag("Z", "context", "set SELinux security context" +
|
||||||
// " of each created directory to CTX"),
|
// " of each created directory to CTX"),
|
||||||
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 dirs = matches
|
let dirs = matches
|
||||||
.get_many::<OsString>(options::DIRS)
|
.get_many::<OsString>(options::DIRS)
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
let verbose = matches.contains_id(options::VERBOSE);
|
let verbose = matches.get_flag(options::VERBOSE);
|
||||||
let recursive = matches.contains_id(options::PARENTS);
|
let recursive = matches.get_flag(options::PARENTS);
|
||||||
|
|
||||||
match get_mode(&matches, mode_had_minus_prefix) {
|
match get_mode(&matches, mode_had_minus_prefix) {
|
||||||
Ok(mode) => exec(dirs, recursive, mode, verbose),
|
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())
|
Command::new(uucore::util_name())
|
||||||
.version(crate_version!())
|
.version(crate_version!())
|
||||||
.about(ABOUT)
|
.about(ABOUT)
|
||||||
|
@ -122,26 +121,26 @@ pub fn uu_app<'a>() -> Command<'a> {
|
||||||
Arg::new(options::MODE)
|
Arg::new(options::MODE)
|
||||||
.short('m')
|
.short('m')
|
||||||
.long(options::MODE)
|
.long(options::MODE)
|
||||||
.help("set file mode (not implemented on windows)")
|
.help("set file mode (not implemented on windows)"),
|
||||||
.takes_value(true),
|
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new(options::PARENTS)
|
Arg::new(options::PARENTS)
|
||||||
.short('p')
|
.short('p')
|
||||||
.long(options::PARENTS)
|
.long(options::PARENTS)
|
||||||
.help("make parent directories as needed"),
|
.help("make parent directories as needed")
|
||||||
|
.action(ArgAction::SetTrue),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new(options::VERBOSE)
|
Arg::new(options::VERBOSE)
|
||||||
.short('v')
|
.short('v')
|
||||||
.long(options::VERBOSE)
|
.long(options::VERBOSE)
|
||||||
.help("print a message for each printed directory"),
|
.help("print a message for each printed directory")
|
||||||
|
.action(ArgAction::SetTrue),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new(options::DIRS)
|
Arg::new(options::DIRS)
|
||||||
.multiple_occurrences(true)
|
.action(ArgAction::Append)
|
||||||
.takes_value(true)
|
.num_args(1..)
|
||||||
.min_values(1)
|
|
||||||
.value_parser(ValueParser::os_string())
|
.value_parser(ValueParser::os_string())
|
||||||
.value_hint(clap::ValueHint::DirPath),
|
.value_hint(clap::ValueHint::DirPath),
|
||||||
)
|
)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue