mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-30 04:27:45 +00:00
dirname: update to clap 4
This commit is contained in:
parent
aaf1e362bf
commit
98673ad76f
2 changed files with 11 additions and 14 deletions
|
@ -15,7 +15,7 @@ edition = "2021"
|
||||||
path = "src/dirname.rs"
|
path = "src/dirname.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" }
|
uucore = { version=">=0.0.16", package="uucore", path="../../uucore" }
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
// For the full copyright and license information, please view the LICENSE
|
// For the full copyright and license information, please view the LICENSE
|
||||||
// file that was distributed with this source code.
|
// 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 std::path::Path;
|
||||||
use uucore::display::print_verbatim;
|
use uucore::display::print_verbatim;
|
||||||
use uucore::error::{UResult, UUsageError};
|
use uucore::error::{UResult, UUsageError};
|
||||||
|
@ -19,24 +19,20 @@ mod options {
|
||||||
pub const DIR: &str = "dir";
|
pub const DIR: &str = "dir";
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_long_usage() -> String {
|
fn get_long_usage() -> &'static str {
|
||||||
String::from(
|
"Output each NAME with its last non-slash component and trailing slashes \n\
|
||||||
"Output each NAME with its last non-slash component and trailing slashes \n\
|
removed; if NAME contains no /'s, output '.' (meaning the current directory)."
|
||||||
removed; if NAME contains no /'s, output '.' (meaning the current directory).",
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[uucore::main]
|
#[uucore::main]
|
||||||
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||||
let args = args.collect_lossy();
|
let args = args.collect_lossy();
|
||||||
|
|
||||||
let after_help = get_long_usage();
|
|
||||||
|
|
||||||
let matches = uu_app()
|
let matches = uu_app()
|
||||||
.after_help(&after_help[..])
|
.after_help(get_long_usage())
|
||||||
.try_get_matches_from(args)?;
|
.try_get_matches_from(args)?;
|
||||||
|
|
||||||
let separator = if matches.contains_id(options::ZERO) {
|
let separator = if matches.get_flag(options::ZERO) {
|
||||||
"\0"
|
"\0"
|
||||||
} else {
|
} else {
|
||||||
"\n"
|
"\n"
|
||||||
|
@ -76,7 +72,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())
|
||||||
.about(ABOUT)
|
.about(ABOUT)
|
||||||
.version(crate_version!())
|
.version(crate_version!())
|
||||||
|
@ -86,12 +82,13 @@ pub fn uu_app<'a>() -> Command<'a> {
|
||||||
Arg::new(options::ZERO)
|
Arg::new(options::ZERO)
|
||||||
.long(options::ZERO)
|
.long(options::ZERO)
|
||||||
.short('z')
|
.short('z')
|
||||||
.help("separate output with NUL rather than newline"),
|
.help("separate output with NUL rather than newline")
|
||||||
|
.action(ArgAction::SetTrue),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new(options::DIR)
|
Arg::new(options::DIR)
|
||||||
.hide(true)
|
.hide(true)
|
||||||
.multiple_occurrences(true)
|
.action(ArgAction::Append)
|
||||||
.value_hint(clap::ValueHint::AnyPath),
|
.value_hint(clap::ValueHint::AnyPath),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue