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

dirname: update to clap 4

This commit is contained in:
Terts Diepraam 2022-09-29 17:01:48 +02:00
parent aaf1e362bf
commit 98673ad76f
2 changed files with 11 additions and 14 deletions

View file

@ -15,7 +15,7 @@ edition = "2021"
path = "src/dirname.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" }
[[bin]]

View file

@ -5,7 +5,7 @@
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.
use clap::{crate_version, Arg, Command};
use clap::{crate_version, Arg, ArgAction, Command};
use std::path::Path;
use uucore::display::print_verbatim;
use uucore::error::{UResult, UUsageError};
@ -19,24 +19,20 @@ mod options {
pub const DIR: &str = "dir";
}
fn get_long_usage() -> String {
String::from(
"Output each NAME with its last non-slash component and trailing slashes \n\
removed; if NAME contains no /'s, output '.' (meaning the current directory).",
)
fn get_long_usage() -> &'static str {
"Output each NAME with its last non-slash component and trailing slashes \n\
removed; if NAME contains no /'s, output '.' (meaning the current directory)."
}
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let args = args.collect_lossy();
let after_help = get_long_usage();
let matches = uu_app()
.after_help(&after_help[..])
.after_help(get_long_usage())
.try_get_matches_from(args)?;
let separator = if matches.contains_id(options::ZERO) {
let separator = if matches.get_flag(options::ZERO) {
"\0"
} else {
"\n"
@ -76,7 +72,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())
.about(ABOUT)
.version(crate_version!())
@ -86,12 +82,13 @@ pub fn uu_app<'a>() -> Command<'a> {
Arg::new(options::ZERO)
.long(options::ZERO)
.short('z')
.help("separate output with NUL rather than newline"),
.help("separate output with NUL rather than newline")
.action(ArgAction::SetTrue),
)
.arg(
Arg::new(options::DIR)
.hide(true)
.multiple_occurrences(true)
.action(ArgAction::Append)
.value_hint(clap::ValueHint::AnyPath),
)
}