mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 03:27:44 +00:00
chgrp: update to clap 4
This commit is contained in:
parent
9605c7f135
commit
075245235e
3 changed files with 34 additions and 22 deletions
|
@ -15,7 +15,7 @@ edition = "2021"
|
|||
path = "src/chgrp.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=["entries", "fs", "perms"] }
|
||||
|
||||
[[bin]]
|
||||
|
|
|
@ -13,7 +13,7 @@ use uucore::error::{FromIo, UResult, USimpleError};
|
|||
use uucore::format_usage;
|
||||
use uucore::perms::{chown_base, options, IfFrom};
|
||||
|
||||
use clap::{Arg, ArgMatches, Command};
|
||||
use clap::{Arg, ArgAction, ArgMatches, Command};
|
||||
|
||||
use std::fs;
|
||||
use std::os::unix::fs::MetadataExt;
|
||||
|
@ -57,42 +57,49 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
|||
chown_base(uu_app(), args, options::ARG_GROUP, parse_gid_and_uid, true)
|
||||
}
|
||||
|
||||
pub fn uu_app<'a>() -> Command<'a> {
|
||||
pub fn uu_app() -> Command {
|
||||
Command::new(uucore::util_name())
|
||||
.version(VERSION)
|
||||
.about(ABOUT)
|
||||
.override_usage(format_usage(USAGE))
|
||||
.infer_long_args(true)
|
||||
.disable_help_flag(true)
|
||||
.arg(
|
||||
Arg::new(options::HELP)
|
||||
.long(options::HELP)
|
||||
.help("Print help information.")
|
||||
.action(ArgAction::Help)
|
||||
)
|
||||
.arg(
|
||||
Arg::new(options::verbosity::CHANGES)
|
||||
.short('c')
|
||||
.long(options::verbosity::CHANGES)
|
||||
.help("like verbose but report only when a change is made"),
|
||||
.help("like verbose but report only when a change is made")
|
||||
.action(ArgAction::SetTrue),
|
||||
)
|
||||
.arg(
|
||||
Arg::new(options::verbosity::SILENT)
|
||||
.short('f')
|
||||
.long(options::verbosity::SILENT),
|
||||
.long(options::verbosity::SILENT)
|
||||
.action(ArgAction::SetTrue),
|
||||
)
|
||||
.arg(
|
||||
Arg::new(options::verbosity::QUIET)
|
||||
.long(options::verbosity::QUIET)
|
||||
.help("suppress most error messages"),
|
||||
.help("suppress most error messages")
|
||||
.action(ArgAction::SetTrue),
|
||||
)
|
||||
.arg(
|
||||
Arg::new(options::verbosity::VERBOSE)
|
||||
.short('v')
|
||||
.long(options::verbosity::VERBOSE)
|
||||
.help("output a diagnostic for every file processed"),
|
||||
.help("output a diagnostic for every file processed")
|
||||
.action(ArgAction::SetTrue),
|
||||
)
|
||||
.arg(
|
||||
Arg::new(options::dereference::DEREFERENCE)
|
||||
.long(options::dereference::DEREFERENCE),
|
||||
.long(options::dereference::DEREFERENCE)
|
||||
.action(ArgAction::SetTrue),
|
||||
)
|
||||
.arg(
|
||||
Arg::new(options::dereference::NO_DEREFERENCE)
|
||||
|
@ -100,47 +107,52 @@ pub fn uu_app<'a>() -> Command<'a> {
|
|||
.long(options::dereference::NO_DEREFERENCE)
|
||||
.help(
|
||||
"affect symbolic links instead of any referenced file (useful only on systems that can change the ownership of a symlink)",
|
||||
),
|
||||
)
|
||||
.action(ArgAction::SetTrue),
|
||||
)
|
||||
.arg(
|
||||
Arg::new(options::preserve_root::PRESERVE)
|
||||
.long(options::preserve_root::PRESERVE)
|
||||
.help("fail to operate recursively on '/'"),
|
||||
.help("fail to operate recursively on '/'")
|
||||
.action(ArgAction::SetTrue),
|
||||
)
|
||||
.arg(
|
||||
Arg::new(options::preserve_root::NO_PRESERVE)
|
||||
.long(options::preserve_root::NO_PRESERVE)
|
||||
.help("do not treat '/' specially (the default)"),
|
||||
.help("do not treat '/' specially (the default)")
|
||||
.action(ArgAction::SetTrue),
|
||||
)
|
||||
.arg(
|
||||
Arg::new(options::REFERENCE)
|
||||
.long(options::REFERENCE)
|
||||
.value_name("RFILE")
|
||||
.value_hint(clap::ValueHint::FilePath)
|
||||
.help("use RFILE's group rather than specifying GROUP values")
|
||||
.takes_value(true)
|
||||
.multiple_occurrences(false),
|
||||
.help("use RFILE's group rather than specifying GROUP values"),
|
||||
)
|
||||
.arg(
|
||||
Arg::new(options::RECURSIVE)
|
||||
.short('R')
|
||||
.long(options::RECURSIVE)
|
||||
.help("operate on files and directories recursively"),
|
||||
.help("operate on files and directories recursively")
|
||||
.action(ArgAction::SetTrue),
|
||||
)
|
||||
.arg(
|
||||
Arg::new(options::traverse::TRAVERSE)
|
||||
.short(options::traverse::TRAVERSE.chars().next().unwrap())
|
||||
.help("if a command line argument is a symbolic link to a directory, traverse it"),
|
||||
.help("if a command line argument is a symbolic link to a directory, traverse it")
|
||||
.action(ArgAction::SetTrue),
|
||||
)
|
||||
.arg(
|
||||
Arg::new(options::traverse::NO_TRAVERSE)
|
||||
.short(options::traverse::NO_TRAVERSE.chars().next().unwrap())
|
||||
.help("do not traverse any symbolic links (default)")
|
||||
.overrides_with_all(&[options::traverse::TRAVERSE, options::traverse::EVERY]),
|
||||
.overrides_with_all(&[options::traverse::TRAVERSE, options::traverse::EVERY])
|
||||
.action(ArgAction::SetTrue),
|
||||
)
|
||||
.arg(
|
||||
Arg::new(options::traverse::EVERY)
|
||||
.short(options::traverse::EVERY.chars().next().unwrap())
|
||||
.help("traverse every symbolic link to a directory encountered"),
|
||||
.help("traverse every symbolic link to a directory encountered")
|
||||
.action(ArgAction::SetTrue),
|
||||
)
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ fn test_help() {
|
|||
new_ucmd!()
|
||||
.arg("--help")
|
||||
.succeeds()
|
||||
.stdout_contains("ARGS:\n <GROUP> \n <FILE>... ");
|
||||
.stdout_contains("Arguments:");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -30,7 +30,7 @@ fn test_help_ref() {
|
|||
.arg("--help")
|
||||
.arg("--reference=ref_file")
|
||||
.succeeds()
|
||||
.stdout_contains("ARGS:\n <GROUP> \n <FILE>... ");
|
||||
.stdout_contains("Arguments:");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -39,7 +39,7 @@ fn test_ref_help() {
|
|||
.arg("--reference=ref_file")
|
||||
.arg("--help")
|
||||
.succeeds()
|
||||
.stdout_contains("ARGS:\n <GROUP> \n <FILE>... ");
|
||||
.stdout_contains("Arguments:");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -196,7 +196,7 @@ fn test_missing_files() {
|
|||
.arg("groupname")
|
||||
.fails()
|
||||
.stderr_contains(
|
||||
"error: The following required arguments were not provided:\n <FILE>...\n",
|
||||
"error: The following required arguments were not provided:\n <FILE>...\n",
|
||||
);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue