1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 11:37:44 +00:00

chgrp: update to clap 4

This commit is contained in:
Terts Diepraam 2022-09-29 15:29:32 +02:00
parent 9605c7f135
commit 075245235e
3 changed files with 34 additions and 22 deletions

View file

@ -15,7 +15,7 @@ edition = "2021"
path = "src/chgrp.rs" path = "src/chgrp.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=["entries", "fs", "perms"] } uucore = { version=">=0.0.16", package="uucore", path="../../uucore", features=["entries", "fs", "perms"] }
[[bin]] [[bin]]

View file

@ -13,7 +13,7 @@ use uucore::error::{FromIo, UResult, USimpleError};
use uucore::format_usage; use uucore::format_usage;
use uucore::perms::{chown_base, options, IfFrom}; use uucore::perms::{chown_base, options, IfFrom};
use clap::{Arg, ArgMatches, Command}; use clap::{Arg, ArgAction, ArgMatches, Command};
use std::fs; use std::fs;
use std::os::unix::fs::MetadataExt; 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) 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()) Command::new(uucore::util_name())
.version(VERSION) .version(VERSION)
.about(ABOUT) .about(ABOUT)
.override_usage(format_usage(USAGE)) .override_usage(format_usage(USAGE))
.infer_long_args(true) .infer_long_args(true)
.disable_help_flag(true)
.arg( .arg(
Arg::new(options::HELP) Arg::new(options::HELP)
.long(options::HELP) .long(options::HELP)
.help("Print help information.") .help("Print help information.")
.action(ArgAction::Help)
) )
.arg( .arg(
Arg::new(options::verbosity::CHANGES) Arg::new(options::verbosity::CHANGES)
.short('c') .short('c')
.long(options::verbosity::CHANGES) .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(
Arg::new(options::verbosity::SILENT) Arg::new(options::verbosity::SILENT)
.short('f') .short('f')
.long(options::verbosity::SILENT), .long(options::verbosity::SILENT)
.action(ArgAction::SetTrue),
) )
.arg( .arg(
Arg::new(options::verbosity::QUIET) Arg::new(options::verbosity::QUIET)
.long(options::verbosity::QUIET) .long(options::verbosity::QUIET)
.help("suppress most error messages"), .help("suppress most error messages")
.action(ArgAction::SetTrue),
) )
.arg( .arg(
Arg::new(options::verbosity::VERBOSE) Arg::new(options::verbosity::VERBOSE)
.short('v') .short('v')
.long(options::verbosity::VERBOSE) .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(
Arg::new(options::dereference::DEREFERENCE) Arg::new(options::dereference::DEREFERENCE)
.long(options::dereference::DEREFERENCE), .long(options::dereference::DEREFERENCE)
.action(ArgAction::SetTrue),
) )
.arg( .arg(
Arg::new(options::dereference::NO_DEREFERENCE) Arg::new(options::dereference::NO_DEREFERENCE)
@ -100,47 +107,52 @@ pub fn uu_app<'a>() -> Command<'a> {
.long(options::dereference::NO_DEREFERENCE) .long(options::dereference::NO_DEREFERENCE)
.help( .help(
"affect symbolic links instead of any referenced file (useful only on systems that can change the ownership of a symlink)", "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(
Arg::new(options::preserve_root::PRESERVE) Arg::new(options::preserve_root::PRESERVE)
.long(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(
Arg::new(options::preserve_root::NO_PRESERVE) Arg::new(options::preserve_root::NO_PRESERVE)
.long(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(
Arg::new(options::REFERENCE) Arg::new(options::REFERENCE)
.long(options::REFERENCE) .long(options::REFERENCE)
.value_name("RFILE") .value_name("RFILE")
.value_hint(clap::ValueHint::FilePath) .value_hint(clap::ValueHint::FilePath)
.help("use RFILE's group rather than specifying GROUP values") .help("use RFILE's group rather than specifying GROUP values"),
.takes_value(true)
.multiple_occurrences(false),
) )
.arg( .arg(
Arg::new(options::RECURSIVE) Arg::new(options::RECURSIVE)
.short('R') .short('R')
.long(options::RECURSIVE) .long(options::RECURSIVE)
.help("operate on files and directories recursively"), .help("operate on files and directories recursively")
.action(ArgAction::SetTrue),
) )
.arg( .arg(
Arg::new(options::traverse::TRAVERSE) Arg::new(options::traverse::TRAVERSE)
.short(options::traverse::TRAVERSE.chars().next().unwrap()) .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(
Arg::new(options::traverse::NO_TRAVERSE) Arg::new(options::traverse::NO_TRAVERSE)
.short(options::traverse::NO_TRAVERSE.chars().next().unwrap()) .short(options::traverse::NO_TRAVERSE.chars().next().unwrap())
.help("do not traverse any symbolic links (default)") .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(
Arg::new(options::traverse::EVERY) Arg::new(options::traverse::EVERY)
.short(options::traverse::EVERY.chars().next().unwrap()) .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),
) )
} }

View file

@ -21,7 +21,7 @@ fn test_help() {
new_ucmd!() new_ucmd!()
.arg("--help") .arg("--help")
.succeeds() .succeeds()
.stdout_contains("ARGS:\n <GROUP> \n <FILE>... "); .stdout_contains("Arguments:");
} }
#[test] #[test]
@ -30,7 +30,7 @@ fn test_help_ref() {
.arg("--help") .arg("--help")
.arg("--reference=ref_file") .arg("--reference=ref_file")
.succeeds() .succeeds()
.stdout_contains("ARGS:\n <GROUP> \n <FILE>... "); .stdout_contains("Arguments:");
} }
#[test] #[test]
@ -39,7 +39,7 @@ fn test_ref_help() {
.arg("--reference=ref_file") .arg("--reference=ref_file")
.arg("--help") .arg("--help")
.succeeds() .succeeds()
.stdout_contains("ARGS:\n <GROUP> \n <FILE>... "); .stdout_contains("Arguments:");
} }
#[test] #[test]
@ -196,7 +196,7 @@ fn test_missing_files() {
.arg("groupname") .arg("groupname")
.fails() .fails()
.stderr_contains( .stderr_contains(
"error: The following required arguments were not provided:\n <FILE>...\n", "error: The following required arguments were not provided:\n <FILE>...\n",
); );
} }