1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-29 20:17:45 +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"
[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]]

View file

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