mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-08-01 05:27:45 +00:00
readlink: update to clap 4
This commit is contained in:
parent
9dc9e44cd5
commit
b2cf7be43f
2 changed files with 29 additions and 22 deletions
|
@ -15,7 +15,7 @@ edition = "2021"
|
||||||
path = "src/readlink.rs"
|
path = "src/readlink.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 std::fs;
|
use std::fs;
|
||||||
use std::io::{stdout, Write};
|
use std::io::{stdout, Write};
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
@ -36,23 +36,23 @@ const ARG_FILES: &str = "files";
|
||||||
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||||
let matches = uu_app().try_get_matches_from(args)?;
|
let matches = uu_app().try_get_matches_from(args)?;
|
||||||
|
|
||||||
let mut no_trailing_delimiter = matches.contains_id(OPT_NO_NEWLINE);
|
let mut no_trailing_delimiter = matches.get_flag(OPT_NO_NEWLINE);
|
||||||
let use_zero = matches.contains_id(OPT_ZERO);
|
let use_zero = matches.get_flag(OPT_ZERO);
|
||||||
let silent = matches.contains_id(OPT_SILENT) || matches.contains_id(OPT_QUIET);
|
let silent = matches.get_flag(OPT_SILENT) || matches.get_flag(OPT_QUIET);
|
||||||
let verbose = matches.contains_id(OPT_VERBOSE);
|
let verbose = matches.get_flag(OPT_VERBOSE);
|
||||||
|
|
||||||
let res_mode = if matches.contains_id(OPT_CANONICALIZE)
|
let res_mode = if matches.get_flag(OPT_CANONICALIZE)
|
||||||
|| matches.contains_id(OPT_CANONICALIZE_EXISTING)
|
|| matches.get_flag(OPT_CANONICALIZE_EXISTING)
|
||||||
|| matches.contains_id(OPT_CANONICALIZE_MISSING)
|
|| matches.get_flag(OPT_CANONICALIZE_MISSING)
|
||||||
{
|
{
|
||||||
ResolveMode::Logical
|
ResolveMode::Logical
|
||||||
} else {
|
} else {
|
||||||
ResolveMode::None
|
ResolveMode::None
|
||||||
};
|
};
|
||||||
|
|
||||||
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
|
||||||
|
@ -98,7 +98,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)
|
||||||
|
@ -111,7 +111,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 but the last component must exist",
|
given name recursively; all but the last component must exist",
|
||||||
),
|
)
|
||||||
|
.action(ArgAction::SetTrue),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new(OPT_CANONICALIZE_EXISTING)
|
Arg::new(OPT_CANONICALIZE_EXISTING)
|
||||||
|
@ -120,7 +121,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)
|
||||||
|
@ -129,42 +131,47 @@ 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_NO_NEWLINE)
|
Arg::new(OPT_NO_NEWLINE)
|
||||||
.short('n')
|
.short('n')
|
||||||
.long(OPT_NO_NEWLINE)
|
.long(OPT_NO_NEWLINE)
|
||||||
.help("do not output the trailing delimiter"),
|
.help("do not output the trailing delimiter")
|
||||||
|
.action(ArgAction::SetTrue),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new(OPT_QUIET)
|
Arg::new(OPT_QUIET)
|
||||||
.short('q')
|
.short('q')
|
||||||
.long(OPT_QUIET)
|
.long(OPT_QUIET)
|
||||||
.help("suppress most error messages"),
|
.help("suppress most error messages")
|
||||||
|
.action(ArgAction::SetTrue),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new(OPT_SILENT)
|
Arg::new(OPT_SILENT)
|
||||||
.short('s')
|
.short('s')
|
||||||
.long(OPT_SILENT)
|
.long(OPT_SILENT)
|
||||||
.help("suppress most error messages"),
|
.help("suppress most error messages")
|
||||||
|
.action(ArgAction::SetTrue),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new(OPT_VERBOSE)
|
Arg::new(OPT_VERBOSE)
|
||||||
.short('v')
|
.short('v')
|
||||||
.long(OPT_VERBOSE)
|
.long(OPT_VERBOSE)
|
||||||
.help("report error message"),
|
.help("report error message")
|
||||||
|
.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 with NUL rather than newline"),
|
.help("separate output with NUL rather than newline")
|
||||||
|
.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),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue