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

realpath: update to clap 4

This commit is contained in:
Terts Diepraam 2022-09-30 16:18:37 +02:00
parent b2cf7be43f
commit 2faf0b62df
2 changed files with 26 additions and 20 deletions

View file

@ -15,7 +15,7 @@ edition = "2021"
path = "src/realpath.rs" path = "src/realpath.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]]

View file

@ -10,7 +10,9 @@
#[macro_use] #[macro_use]
extern crate uucore; extern crate uucore;
use clap::{builder::NonEmptyStringValueParser, crate_version, Arg, ArgMatches, Command}; use clap::{
builder::NonEmptyStringValueParser, crate_version, Arg, ArgAction, ArgMatches, Command,
};
use std::{ use std::{
io::{stdout, Write}, io::{stdout, Write},
path::{Path, PathBuf}, path::{Path, PathBuf},
@ -51,13 +53,13 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
.map(PathBuf::from) .map(PathBuf::from)
.collect(); .collect();
let strip = matches.contains_id(OPT_STRIP); let strip = matches.get_flag(OPT_STRIP);
let zero = matches.contains_id(OPT_ZERO); let zero = matches.get_flag(OPT_ZERO);
let quiet = matches.contains_id(OPT_QUIET); let quiet = matches.get_flag(OPT_QUIET);
let logical = matches.contains_id(OPT_LOGICAL); let logical = matches.get_flag(OPT_LOGICAL);
let can_mode = if matches.contains_id(OPT_CANONICALIZE_EXISTING) { let can_mode = if matches.get_flag(OPT_CANONICALIZE_EXISTING) {
MissingHandling::Existing MissingHandling::Existing
} else if matches.contains_id(OPT_CANONICALIZE_MISSING) { } else if matches.get_flag(OPT_CANONICALIZE_MISSING) {
MissingHandling::Missing MissingHandling::Missing
} else { } else {
MissingHandling::Normal MissingHandling::Normal
@ -89,7 +91,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
Ok(()) Ok(())
} }
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)
@ -99,33 +101,38 @@ pub fn uu_app<'a>() -> Command<'a> {
Arg::new(OPT_QUIET) Arg::new(OPT_QUIET)
.short('q') .short('q')
.long(OPT_QUIET) .long(OPT_QUIET)
.help("Do not print warnings for invalid paths"), .help("Do not print warnings for invalid paths")
.action(ArgAction::SetTrue),
) )
.arg( .arg(
Arg::new(OPT_STRIP) Arg::new(OPT_STRIP)
.short('s') .short('s')
.long(OPT_STRIP) .long(OPT_STRIP)
.visible_alias("no-symlinks") .visible_alias("no-symlinks")
.help("Only strip '.' and '..' components, but don't resolve symbolic links"), .help("Only strip '.' and '..' components, but don't resolve symbolic links")
.action(ArgAction::SetTrue),
) )
.arg( .arg(
Arg::new(OPT_ZERO) Arg::new(OPT_ZERO)
.short('z') .short('z')
.long(OPT_ZERO) .long(OPT_ZERO)
.help("Separate output filenames with \\0 rather than newline"), .help("Separate output filenames with \\0 rather than newline")
.action(ArgAction::SetTrue),
) )
.arg( .arg(
Arg::new(OPT_LOGICAL) Arg::new(OPT_LOGICAL)
.short('L') .short('L')
.long(OPT_LOGICAL) .long(OPT_LOGICAL)
.help("resolve '..' components before symlinks"), .help("resolve '..' components before symlinks")
.action(ArgAction::SetTrue),
) )
.arg( .arg(
Arg::new(OPT_PHYSICAL) Arg::new(OPT_PHYSICAL)
.short('P') .short('P')
.long(OPT_PHYSICAL) .long(OPT_PHYSICAL)
.overrides_with_all(&[OPT_STRIP, OPT_LOGICAL]) .overrides_with_all(&[OPT_STRIP, OPT_LOGICAL])
.help("resolve symlinks as encountered (default)"), .help("resolve symlinks as encountered (default)")
.action(ArgAction::SetTrue),
) )
.arg( .arg(
Arg::new(OPT_CANONICALIZE_EXISTING) Arg::new(OPT_CANONICALIZE_EXISTING)
@ -134,7 +141,8 @@ pub fn uu_app<'a>() -> Command<'a> {
.help( .help(
"canonicalize by following every symlink in every component of the \ "canonicalize by following every symlink in every component of the \
given name recursively, all components must exist", given name recursively, all components must exist",
), )
.action(ArgAction::SetTrue),
) )
.arg( .arg(
Arg::new(OPT_CANONICALIZE_MISSING) Arg::new(OPT_CANONICALIZE_MISSING)
@ -143,12 +151,12 @@ pub fn uu_app<'a>() -> Command<'a> {
.help( .help(
"canonicalize by following every symlink in every component of the \ "canonicalize by following every symlink in every component of the \
given name recursively, without requirements on components existence", given name recursively, without requirements on components existence",
), )
.action(ArgAction::SetTrue),
) )
.arg( .arg(
Arg::new(OPT_RELATIVE_TO) Arg::new(OPT_RELATIVE_TO)
.long(OPT_RELATIVE_TO) .long(OPT_RELATIVE_TO)
.takes_value(true)
.value_name("DIR") .value_name("DIR")
.value_parser(NonEmptyStringValueParser::new()) .value_parser(NonEmptyStringValueParser::new())
.help("print the resolved path relative to DIR"), .help("print the resolved path relative to DIR"),
@ -156,15 +164,13 @@ pub fn uu_app<'a>() -> Command<'a> {
.arg( .arg(
Arg::new(OPT_RELATIVE_BASE) Arg::new(OPT_RELATIVE_BASE)
.long(OPT_RELATIVE_BASE) .long(OPT_RELATIVE_BASE)
.takes_value(true)
.value_name("DIR") .value_name("DIR")
.value_parser(NonEmptyStringValueParser::new()) .value_parser(NonEmptyStringValueParser::new())
.help("print absolute paths unless paths below DIR"), .help("print absolute paths unless paths below DIR"),
) )
.arg( .arg(
Arg::new(ARG_FILES) Arg::new(ARG_FILES)
.multiple_occurrences(true) .action(ArgAction::Append)
.required(true)
.value_parser(NonEmptyStringValueParser::new()) .value_parser(NonEmptyStringValueParser::new())
.value_hint(clap::ValueHint::AnyPath), .value_hint(clap::ValueHint::AnyPath),
) )