diff --git a/src/uu/ln/Cargo.toml b/src/uu/ln/Cargo.toml index 92da57f80..33a300ee1 100644 --- a/src/uu/ln/Cargo.toml +++ b/src/uu/ln/Cargo.toml @@ -15,7 +15,7 @@ edition = "2021" path = "src/ln.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"] } [[bin]] diff --git a/src/uu/ln/src/ln.rs b/src/uu/ln/src/ln.rs index a227eb68e..6f179f797 100644 --- a/src/uu/ln/src/ln.rs +++ b/src/uu/ln/src/ln.rs @@ -10,7 +10,7 @@ #[macro_use] extern crate uucore; -use clap::{crate_version, Arg, Command}; +use clap::{crate_version, Arg, ArgAction, Command}; use uucore::display::Quotable; use uucore::error::{FromIo, UError, UResult}; use uucore::format_usage; @@ -128,15 +128,14 @@ static ARG_FILES: &str = "files"; #[uucore::main] 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() - .after_help(&*format!( - "{}\n{}", - long_usage, - backup_control::BACKUP_CONTROL_LONG_HELP - )) - .try_get_matches_from(args)?; + let matches = uu_app().after_help(long_usage).try_get_matches_from(args)?; /* the list of files */ @@ -146,11 +145,11 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { .map(PathBuf::from) .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 - } else if matches.contains_id(options::INTERACTIVE) { + } else if matches.get_flag(options::INTERACTIVE) { OverwriteMode::Interactive } else { OverwriteMode::NoClobber @@ -160,7 +159,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { let backup_suffix = backup_control::determine_backup_suffix(&matches); // 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 { overwrite: overwrite_mode, @@ -168,19 +167,19 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { suffix: backup_suffix, symbolic, logical, - relative: matches.contains_id(options::RELATIVE), + relative: matches.get_flag(options::RELATIVE), target_dir: matches .get_one::(options::TARGET_DIRECTORY) .map(String::from), - no_target_dir: matches.contains_id(options::NO_TARGET_DIRECTORY), - no_dereference: matches.contains_id(options::NO_DEREFERENCE), - verbose: matches.contains_id(options::VERBOSE), + no_target_dir: matches.get_flag(options::NO_TARGET_DIRECTORY), + no_dereference: matches.get_flag(options::NO_DEREFERENCE), + verbose: matches.get_flag(options::VERBOSE), }; exec(&paths[..], &settings) } -pub fn uu_app<'a>() -> Command<'a> { +pub fn uu_app() -> Command { Command::new(uucore::util_name()) .version(crate_version!()) .about(ABOUT) @@ -198,13 +197,15 @@ pub fn uu_app<'a>() -> Command<'a> { Arg::new(options::FORCE) .short('f') .long(options::FORCE) - .help("remove existing destination files"), + .help("remove existing destination files") + .action(ArgAction::SetTrue), ) .arg( Arg::new(options::INTERACTIVE) .short('i') .long(options::INTERACTIVE) - .help("prompt whether to remove existing destination files"), + .help("prompt whether to remove existing destination files") + .action(ArgAction::SetTrue), ) .arg( Arg::new(options::NO_DEREFERENCE) @@ -213,21 +214,24 @@ pub fn uu_app<'a>() -> Command<'a> { .help( "treat LINK_NAME as a normal file if it is a \ symbolic link to a directory", - ), + ) + .action(ArgAction::SetTrue), ) .arg( Arg::new(options::LOGICAL) .short('L') .long(options::LOGICAL) .help("dereference TARGETs that are symbolic links") - .overrides_with(options::PHYSICAL), + .overrides_with(options::PHYSICAL) + .action(ArgAction::SetTrue), ) .arg( // Not implemented yet Arg::new(options::PHYSICAL) .short('P') .long(options::PHYSICAL) - .help("make hard links directly to symbolic links"), + .help("make hard links directly to symbolic links") + .action(ArgAction::SetTrue), ) .arg( Arg::new(options::SYMBOLIC) @@ -235,7 +239,8 @@ pub fn uu_app<'a>() -> Command<'a> { .long(options::SYMBOLIC) .help("make symbolic links instead of hard links") // 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( @@ -251,28 +256,30 @@ pub fn uu_app<'a>() -> Command<'a> { Arg::new(options::NO_TARGET_DIRECTORY) .short('T') .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::new(options::RELATIVE) .short('r') .long(options::RELATIVE) .help("create symbolic links relative to link location") - .requires(options::SYMBOLIC), + .requires(options::SYMBOLIC) + .action(ArgAction::SetTrue), ) .arg( Arg::new(options::VERBOSE) .short('v') .long(options::VERBOSE) - .help("print name of each linked file"), + .help("print name of each linked file") + .action(ArgAction::SetTrue), ) .arg( Arg::new(ARG_FILES) - .multiple_occurrences(true) - .takes_value(true) + .action(ArgAction::Append) .value_hint(clap::ValueHint::AnyPath) .required(true) - .min_values(1), + .num_args(1..), ) }