mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-29 12:07:46 +00:00
ln: update to clap 4
This commit is contained in:
parent
838479f86a
commit
56ea8bb4ac
2 changed files with 38 additions and 31 deletions
|
@ -15,7 +15,7 @@ edition = "2021"
|
||||||
path = "src/ln.rs"
|
path = "src/ln.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"] }
|
uucore = { version=">=0.0.16", package="uucore", path="../../uucore", features=["fs"] }
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate uucore;
|
extern crate uucore;
|
||||||
|
|
||||||
use clap::{crate_version, Arg, Command};
|
use clap::{crate_version, Arg, ArgAction, Command};
|
||||||
use uucore::display::Quotable;
|
use uucore::display::Quotable;
|
||||||
use uucore::error::{FromIo, UError, UResult};
|
use uucore::error::{FromIo, UError, UResult};
|
||||||
use uucore::format_usage;
|
use uucore::format_usage;
|
||||||
|
@ -128,15 +128,14 @@ static ARG_FILES: &str = "files";
|
||||||
|
|
||||||
#[uucore::main]
|
#[uucore::main]
|
||||||
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||||
let long_usage = long_usage();
|
// clap requires a 'static string
|
||||||
|
let long_usage = format!(
|
||||||
|
"{}\n{}",
|
||||||
|
long_usage(),
|
||||||
|
backup_control::BACKUP_CONTROL_LONG_HELP
|
||||||
|
);
|
||||||
|
|
||||||
let matches = uu_app()
|
let matches = uu_app().after_help(long_usage).try_get_matches_from(args)?;
|
||||||
.after_help(&*format!(
|
|
||||||
"{}\n{}",
|
|
||||||
long_usage,
|
|
||||||
backup_control::BACKUP_CONTROL_LONG_HELP
|
|
||||||
))
|
|
||||||
.try_get_matches_from(args)?;
|
|
||||||
|
|
||||||
/* the list of files */
|
/* the list of files */
|
||||||
|
|
||||||
|
@ -146,11 +145,11 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||||
.map(PathBuf::from)
|
.map(PathBuf::from)
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let symbolic = matches.contains_id(options::SYMBOLIC);
|
let symbolic = matches.get_flag(options::SYMBOLIC);
|
||||||
|
|
||||||
let overwrite_mode = if matches.contains_id(options::FORCE) {
|
let overwrite_mode = if matches.get_flag(options::FORCE) {
|
||||||
OverwriteMode::Force
|
OverwriteMode::Force
|
||||||
} else if matches.contains_id(options::INTERACTIVE) {
|
} else if matches.get_flag(options::INTERACTIVE) {
|
||||||
OverwriteMode::Interactive
|
OverwriteMode::Interactive
|
||||||
} else {
|
} else {
|
||||||
OverwriteMode::NoClobber
|
OverwriteMode::NoClobber
|
||||||
|
@ -160,7 +159,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||||
let backup_suffix = backup_control::determine_backup_suffix(&matches);
|
let backup_suffix = backup_control::determine_backup_suffix(&matches);
|
||||||
|
|
||||||
// When we have "-L" or "-L -P", false otherwise
|
// When we have "-L" or "-L -P", false otherwise
|
||||||
let logical = matches.contains_id(options::LOGICAL);
|
let logical = matches.get_flag(options::LOGICAL);
|
||||||
|
|
||||||
let settings = Settings {
|
let settings = Settings {
|
||||||
overwrite: overwrite_mode,
|
overwrite: overwrite_mode,
|
||||||
|
@ -168,19 +167,19 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||||
suffix: backup_suffix,
|
suffix: backup_suffix,
|
||||||
symbolic,
|
symbolic,
|
||||||
logical,
|
logical,
|
||||||
relative: matches.contains_id(options::RELATIVE),
|
relative: matches.get_flag(options::RELATIVE),
|
||||||
target_dir: matches
|
target_dir: matches
|
||||||
.get_one::<String>(options::TARGET_DIRECTORY)
|
.get_one::<String>(options::TARGET_DIRECTORY)
|
||||||
.map(String::from),
|
.map(String::from),
|
||||||
no_target_dir: matches.contains_id(options::NO_TARGET_DIRECTORY),
|
no_target_dir: matches.get_flag(options::NO_TARGET_DIRECTORY),
|
||||||
no_dereference: matches.contains_id(options::NO_DEREFERENCE),
|
no_dereference: matches.get_flag(options::NO_DEREFERENCE),
|
||||||
verbose: matches.contains_id(options::VERBOSE),
|
verbose: matches.get_flag(options::VERBOSE),
|
||||||
};
|
};
|
||||||
|
|
||||||
exec(&paths[..], &settings)
|
exec(&paths[..], &settings)
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
||||||
|
@ -198,13 +197,15 @@ pub fn uu_app<'a>() -> Command<'a> {
|
||||||
Arg::new(options::FORCE)
|
Arg::new(options::FORCE)
|
||||||
.short('f')
|
.short('f')
|
||||||
.long(options::FORCE)
|
.long(options::FORCE)
|
||||||
.help("remove existing destination files"),
|
.help("remove existing destination files")
|
||||||
|
.action(ArgAction::SetTrue),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new(options::INTERACTIVE)
|
Arg::new(options::INTERACTIVE)
|
||||||
.short('i')
|
.short('i')
|
||||||
.long(options::INTERACTIVE)
|
.long(options::INTERACTIVE)
|
||||||
.help("prompt whether to remove existing destination files"),
|
.help("prompt whether to remove existing destination files")
|
||||||
|
.action(ArgAction::SetTrue),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new(options::NO_DEREFERENCE)
|
Arg::new(options::NO_DEREFERENCE)
|
||||||
|
@ -213,21 +214,24 @@ pub fn uu_app<'a>() -> Command<'a> {
|
||||||
.help(
|
.help(
|
||||||
"treat LINK_NAME as a normal file if it is a \
|
"treat LINK_NAME as a normal file if it is a \
|
||||||
symbolic link to a directory",
|
symbolic link to a directory",
|
||||||
),
|
)
|
||||||
|
.action(ArgAction::SetTrue),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new(options::LOGICAL)
|
Arg::new(options::LOGICAL)
|
||||||
.short('L')
|
.short('L')
|
||||||
.long(options::LOGICAL)
|
.long(options::LOGICAL)
|
||||||
.help("dereference TARGETs that are symbolic links")
|
.help("dereference TARGETs that are symbolic links")
|
||||||
.overrides_with(options::PHYSICAL),
|
.overrides_with(options::PHYSICAL)
|
||||||
|
.action(ArgAction::SetTrue),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
// Not implemented yet
|
// Not implemented yet
|
||||||
Arg::new(options::PHYSICAL)
|
Arg::new(options::PHYSICAL)
|
||||||
.short('P')
|
.short('P')
|
||||||
.long(options::PHYSICAL)
|
.long(options::PHYSICAL)
|
||||||
.help("make hard links directly to symbolic links"),
|
.help("make hard links directly to symbolic links")
|
||||||
|
.action(ArgAction::SetTrue),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new(options::SYMBOLIC)
|
Arg::new(options::SYMBOLIC)
|
||||||
|
@ -235,7 +239,8 @@ pub fn uu_app<'a>() -> Command<'a> {
|
||||||
.long(options::SYMBOLIC)
|
.long(options::SYMBOLIC)
|
||||||
.help("make symbolic links instead of hard links")
|
.help("make symbolic links instead of hard links")
|
||||||
// override added for https://github.com/uutils/coreutils/issues/2359
|
// override added for https://github.com/uutils/coreutils/issues/2359
|
||||||
.overrides_with(options::SYMBOLIC),
|
.overrides_with(options::SYMBOLIC)
|
||||||
|
.action(ArgAction::SetTrue),
|
||||||
)
|
)
|
||||||
.arg(backup_control::arguments::suffix())
|
.arg(backup_control::arguments::suffix())
|
||||||
.arg(
|
.arg(
|
||||||
|
@ -251,28 +256,30 @@ pub fn uu_app<'a>() -> Command<'a> {
|
||||||
Arg::new(options::NO_TARGET_DIRECTORY)
|
Arg::new(options::NO_TARGET_DIRECTORY)
|
||||||
.short('T')
|
.short('T')
|
||||||
.long(options::NO_TARGET_DIRECTORY)
|
.long(options::NO_TARGET_DIRECTORY)
|
||||||
.help("treat LINK_NAME as a normal file always"),
|
.help("treat LINK_NAME as a normal file always")
|
||||||
|
.action(ArgAction::SetTrue),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new(options::RELATIVE)
|
Arg::new(options::RELATIVE)
|
||||||
.short('r')
|
.short('r')
|
||||||
.long(options::RELATIVE)
|
.long(options::RELATIVE)
|
||||||
.help("create symbolic links relative to link location")
|
.help("create symbolic links relative to link location")
|
||||||
.requires(options::SYMBOLIC),
|
.requires(options::SYMBOLIC)
|
||||||
|
.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 name of each linked file"),
|
.help("print name of each linked file")
|
||||||
|
.action(ArgAction::SetTrue),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new(ARG_FILES)
|
Arg::new(ARG_FILES)
|
||||||
.multiple_occurrences(true)
|
.action(ArgAction::Append)
|
||||||
.takes_value(true)
|
|
||||||
.value_hint(clap::ValueHint::AnyPath)
|
.value_hint(clap::ValueHint::AnyPath)
|
||||||
.required(true)
|
.required(true)
|
||||||
.min_values(1),
|
.num_args(1..),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue