mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-29 12:07:46 +00:00
mv: update to clap 4
This commit is contained in:
parent
ca135d3ef3
commit
5faae817ba
3 changed files with 34 additions and 23 deletions
|
@ -15,7 +15,7 @@ edition = "2021"
|
||||||
path = "src/mv.rs"
|
path = "src/mv.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
clap = { version = "3.2", features = ["wrap_help", "cargo"] }
|
clap = { version = "4.0", features = ["wrap_help", "cargo"] }
|
||||||
fs_extra = "1.1.0"
|
fs_extra = "1.1.0"
|
||||||
uucore = { version=">=0.0.16", package="uucore", path="../../uucore" }
|
uucore = { version=">=0.0.16", package="uucore", path="../../uucore" }
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ mod error;
|
||||||
extern crate uucore;
|
extern crate uucore;
|
||||||
|
|
||||||
use clap::builder::ValueParser;
|
use clap::builder::ValueParser;
|
||||||
use clap::{crate_version, Arg, ArgMatches, Command, ErrorKind};
|
use clap::{crate_version, error::ErrorKind, Arg, ArgAction, ArgMatches, Command};
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::ffi::OsString;
|
use std::ffi::OsString;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
|
@ -76,7 +76,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||||
LONG_HELP,
|
LONG_HELP,
|
||||||
backup_control::BACKUP_CONTROL_LONG_HELP
|
backup_control::BACKUP_CONTROL_LONG_HELP
|
||||||
);
|
);
|
||||||
let mut app = uu_app().after_help(&*help);
|
let mut app = uu_app().after_help(help);
|
||||||
let matches = app.try_get_matches_from_mut(args)?;
|
let matches = app.try_get_matches_from_mut(args)?;
|
||||||
|
|
||||||
if !matches.contains_id(OPT_TARGET_DIRECTORY)
|
if !matches.contains_id(OPT_TARGET_DIRECTORY)
|
||||||
|
@ -118,19 +118,19 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||||
overwrite: overwrite_mode,
|
overwrite: overwrite_mode,
|
||||||
backup: backup_mode,
|
backup: backup_mode,
|
||||||
suffix: backup_suffix,
|
suffix: backup_suffix,
|
||||||
update: matches.contains_id(OPT_UPDATE),
|
update: matches.get_flag(OPT_UPDATE),
|
||||||
target_dir: matches
|
target_dir: matches
|
||||||
.get_one::<OsString>(OPT_TARGET_DIRECTORY)
|
.get_one::<OsString>(OPT_TARGET_DIRECTORY)
|
||||||
.map(OsString::from),
|
.map(OsString::from),
|
||||||
no_target_dir: matches.contains_id(OPT_NO_TARGET_DIRECTORY),
|
no_target_dir: matches.get_flag(OPT_NO_TARGET_DIRECTORY),
|
||||||
verbose: matches.contains_id(OPT_VERBOSE),
|
verbose: matches.get_flag(OPT_VERBOSE),
|
||||||
strip_slashes: matches.contains_id(OPT_STRIP_TRAILING_SLASHES),
|
strip_slashes: matches.get_flag(OPT_STRIP_TRAILING_SLASHES),
|
||||||
};
|
};
|
||||||
|
|
||||||
exec(&files[..], &behavior)
|
exec(&files[..], &behavior)
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
||||||
|
@ -142,24 +142,28 @@ pub fn uu_app<'a>() -> Command<'a> {
|
||||||
Arg::new(OPT_FORCE)
|
Arg::new(OPT_FORCE)
|
||||||
.short('f')
|
.short('f')
|
||||||
.long(OPT_FORCE)
|
.long(OPT_FORCE)
|
||||||
.help("do not prompt before overwriting"),
|
.help("do not prompt before overwriting")
|
||||||
|
.action(ArgAction::SetTrue),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new(OPT_INTERACTIVE)
|
Arg::new(OPT_INTERACTIVE)
|
||||||
.short('i')
|
.short('i')
|
||||||
.long(OPT_INTERACTIVE)
|
.long(OPT_INTERACTIVE)
|
||||||
.help("prompt before override"),
|
.help("prompt before override")
|
||||||
|
.action(ArgAction::SetTrue),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new(OPT_NO_CLOBBER)
|
Arg::new(OPT_NO_CLOBBER)
|
||||||
.short('n')
|
.short('n')
|
||||||
.long(OPT_NO_CLOBBER)
|
.long(OPT_NO_CLOBBER)
|
||||||
.help("do not overwrite an existing file"),
|
.help("do not overwrite an existing file")
|
||||||
|
.action(ArgAction::SetTrue),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new(OPT_STRIP_TRAILING_SLASHES)
|
Arg::new(OPT_STRIP_TRAILING_SLASHES)
|
||||||
.long(OPT_STRIP_TRAILING_SLASHES)
|
.long(OPT_STRIP_TRAILING_SLASHES)
|
||||||
.help("remove any trailing slashes from each SOURCE argument"),
|
.help("remove any trailing slashes from each SOURCE argument")
|
||||||
|
.action(ArgAction::SetTrue),
|
||||||
)
|
)
|
||||||
.arg(backup_control::arguments::suffix())
|
.arg(backup_control::arguments::suffix())
|
||||||
.arg(
|
.arg(
|
||||||
|
@ -167,7 +171,6 @@ pub fn uu_app<'a>() -> Command<'a> {
|
||||||
.short('t')
|
.short('t')
|
||||||
.long(OPT_TARGET_DIRECTORY)
|
.long(OPT_TARGET_DIRECTORY)
|
||||||
.help("move all SOURCE arguments into DIRECTORY")
|
.help("move all SOURCE arguments into DIRECTORY")
|
||||||
.takes_value(true)
|
|
||||||
.value_name("DIRECTORY")
|
.value_name("DIRECTORY")
|
||||||
.value_hint(clap::ValueHint::DirPath)
|
.value_hint(clap::ValueHint::DirPath)
|
||||||
.conflicts_with(OPT_NO_TARGET_DIRECTORY)
|
.conflicts_with(OPT_NO_TARGET_DIRECTORY)
|
||||||
|
@ -177,23 +180,30 @@ pub fn uu_app<'a>() -> Command<'a> {
|
||||||
Arg::new(OPT_NO_TARGET_DIRECTORY)
|
Arg::new(OPT_NO_TARGET_DIRECTORY)
|
||||||
.short('T')
|
.short('T')
|
||||||
.long(OPT_NO_TARGET_DIRECTORY)
|
.long(OPT_NO_TARGET_DIRECTORY)
|
||||||
.help("treat DEST as a normal file"),
|
.help("treat DEST as a normal file")
|
||||||
|
.action(ArgAction::SetTrue),
|
||||||
)
|
)
|
||||||
.arg(Arg::new(OPT_UPDATE).short('u').long(OPT_UPDATE).help(
|
.arg(
|
||||||
"move only when the SOURCE file is newer than the destination file \
|
Arg::new(OPT_UPDATE)
|
||||||
|
.short('u')
|
||||||
|
.long(OPT_UPDATE)
|
||||||
|
.help(
|
||||||
|
"move only when the SOURCE file is newer than the destination file \
|
||||||
or when the destination file is missing",
|
or when the destination file is missing",
|
||||||
))
|
)
|
||||||
|
.action(ArgAction::SetTrue),
|
||||||
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new(OPT_VERBOSE)
|
Arg::new(OPT_VERBOSE)
|
||||||
.short('v')
|
.short('v')
|
||||||
.long(OPT_VERBOSE)
|
.long(OPT_VERBOSE)
|
||||||
.help("explain what is being done"),
|
.help("explain what is being done")
|
||||||
|
.action(ArgAction::SetTrue),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new(ARG_FILES)
|
Arg::new(ARG_FILES)
|
||||||
.multiple_occurrences(true)
|
.action(ArgAction::Append)
|
||||||
.takes_value(true)
|
.num_args(1..)
|
||||||
.min_values(1)
|
|
||||||
.required(true)
|
.required(true)
|
||||||
.value_parser(ValueParser::os_string())
|
.value_parser(ValueParser::os_string())
|
||||||
.value_hint(clap::ValueHint::AnyPath),
|
.value_hint(clap::ValueHint::AnyPath),
|
||||||
|
@ -206,9 +216,9 @@ fn determine_overwrite_mode(matches: &ArgMatches) -> OverwriteMode {
|
||||||
// overwrite options are supplied, only the last takes effect.
|
// overwrite options are supplied, only the last takes effect.
|
||||||
// To default to no-clobber in that situation seems safer:
|
// To default to no-clobber in that situation seems safer:
|
||||||
//
|
//
|
||||||
if matches.contains_id(OPT_NO_CLOBBER) {
|
if matches.get_flag(OPT_NO_CLOBBER) {
|
||||||
OverwriteMode::NoClobber
|
OverwriteMode::NoClobber
|
||||||
} else if matches.contains_id(OPT_INTERACTIVE) {
|
} else if matches.get_flag(OPT_INTERACTIVE) {
|
||||||
OverwriteMode::Interactive
|
OverwriteMode::Interactive
|
||||||
} else {
|
} else {
|
||||||
OverwriteMode::Force
|
OverwriteMode::Force
|
||||||
|
|
|
@ -803,6 +803,7 @@ fn test_mv_verbose() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg(any(target_os = "linux", target_os = "android"))] // mkdir does not support -m on windows. Freebsd doesn't return a permission error either.
|
#[cfg(any(target_os = "linux", target_os = "android"))] // mkdir does not support -m on windows. Freebsd doesn't return a permission error either.
|
||||||
|
#[cfg(features = "mkdir")]
|
||||||
fn test_mv_permission_error() {
|
fn test_mv_permission_error() {
|
||||||
let scene = TestScenario::new("mkdir");
|
let scene = TestScenario::new("mkdir");
|
||||||
let folder1 = "bar";
|
let folder1 = "bar";
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue