Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 3 additions & 34 deletions src/uu/chgrp/src/chgrp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ pub fn uu_app() -> Command {
Arg::new(options::HELP)
.long(options::HELP)
.help("Print help information.")
.action(ArgAction::Help)
.action(ArgAction::Help),
)
.arg(
Arg::new(options::verbosity::CHANGES)
Expand Down Expand Up @@ -101,20 +101,6 @@ pub fn uu_app() -> Command {
.help("output a diagnostic for every file processed")
.action(ArgAction::SetTrue),
)
.arg(
Arg::new(options::dereference::DEREFERENCE)
.long(options::dereference::DEREFERENCE)
.action(ArgAction::SetTrue),
)
.arg(
Arg::new(options::dereference::NO_DEREFERENCE)
.short('h')
.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)
Expand All @@ -141,23 +127,6 @@ pub fn uu_app() -> Command {
.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")
.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])
.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")
.action(ArgAction::SetTrue),
)
// Add common arguments with chgrp, chown & chmod
.args(uucore::perms::common_args())
}
17 changes: 14 additions & 3 deletions src/uu/chmod/src/chmod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const USAGE: &str = help_usage!("chmod.md");
const LONG_USAGE: &str = help_section!("after help", "chmod.md");

mod options {
pub const HELP: &str = "help";
pub const CHANGES: &str = "changes";
pub const QUIET: &str = "quiet"; // visible_alias("silent")
pub const VERBOSE: &str = "verbose";
Expand Down Expand Up @@ -158,6 +159,13 @@ pub fn uu_app() -> Command {
.args_override_self(true)
.infer_long_args(true)
.no_binary_name(true)
.disable_help_flag(true)
.arg(
Arg::new(options::HELP)
.long(options::HELP)
.help("Print help information.")
.action(ArgAction::Help),
)
.arg(
Arg::new(options::CHANGES)
.long(options::CHANGES)
Expand Down Expand Up @@ -206,16 +214,19 @@ pub fn uu_app() -> Command {
.help("use RFILE's mode instead of MODE values"),
)
.arg(
Arg::new(options::MODE).required_unless_present(options::REFERENCE), // It would be nice if clap could parse with delimiter, e.g. "g-x,u+x",
// however .multiple_occurrences(true) cannot be used here because FILE already needs that.
// Only one positional argument with .multiple_occurrences(true) set is allowed per command
Arg::new(options::MODE).required_unless_present(options::REFERENCE),
// It would be nice if clap could parse with delimiter, e.g. "g-x,u+x",
// however .multiple_occurrences(true) cannot be used here because FILE already needs that.
// Only one positional argument with .multiple_occurrences(true) set is allowed per command
)
.arg(
Arg::new(options::FILE)
.required_unless_present(options::MODE)
.action(ArgAction::Append)
.value_hint(clap::ValueHint::AnyPath),
)
// Add common arguments with chgrp, chown & chmod
.args(uucore::perms::common_args())
}

struct Chmoder {
Expand Down
42 changes: 2 additions & 40 deletions src/uu/chown/src/chown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,25 +96,6 @@ pub fn uu_app() -> Command {
.help("like verbose but report only when a change is made")
.action(ArgAction::SetTrue),
)
.arg(
Arg::new(options::dereference::DEREFERENCE)
.long(options::dereference::DEREFERENCE)
.help(
"affect the referent of each symbolic link (this is the default), \
rather than the symbolic link itself",
)
.action(ArgAction::SetTrue),
)
.arg(
Arg::new(options::dereference::NO_DEREFERENCE)
.short('h')
.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::FROM)
.long(options::FROM)
Expand Down Expand Up @@ -165,34 +146,15 @@ pub fn uu_app() -> Command {
.long(options::verbosity::SILENT)
.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")
.overrides_with_all([options::traverse::EVERY, options::traverse::NO_TRAVERSE])
.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")
.overrides_with_all([options::traverse::TRAVERSE, options::traverse::NO_TRAVERSE])
.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])
.action(ArgAction::SetTrue),
)
.arg(
Arg::new(options::verbosity::VERBOSE)
.long(options::verbosity::VERBOSE)
.short('v')
.help("output a diagnostic for every file processed")
.action(ArgAction::SetTrue),
)
// Add common arguments with chgrp, chown & chmod
.args(uucore::perms::common_args())
}

/// Parses the user string to extract the UID.
Expand Down
37 changes: 37 additions & 0 deletions src/uucore/src/lib/features/perms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub use crate::features::entries;
use crate::show_error;
use clap::{Arg, ArgMatches, Command};
use libc::{gid_t, uid_t};
use options::traverse;
use walkdir::WalkDir;

use std::io::Error as IOError;
Expand All @@ -33,6 +34,7 @@ pub enum VerbosityLevel {
Verbose,
Normal,
}

#[derive(PartialEq, Eq, Clone, Debug)]
pub struct Verbosity {
pub groups_only: bool,
Expand Down Expand Up @@ -634,6 +636,41 @@ pub fn chown_base(
executor.exec()
}

pub fn common_args() -> Vec<Arg> {
vec![
Arg::new(traverse::TRAVERSE)
.short(traverse::TRAVERSE.chars().next().unwrap())
.help("if a command line argument is a symbolic link to a directory, traverse it")
.overrides_with_all([traverse::EVERY, traverse::NO_TRAVERSE])
.action(clap::ArgAction::SetTrue),
Arg::new(traverse::EVERY)
.short(traverse::EVERY.chars().next().unwrap())
.help("traverse every symbolic link to a directory encountered")
.overrides_with_all([traverse::TRAVERSE, traverse::NO_TRAVERSE])
.action(clap::ArgAction::SetTrue),
Arg::new(traverse::NO_TRAVERSE)
.short(traverse::NO_TRAVERSE.chars().next().unwrap())
.help("do not traverse any symbolic links (default)")
.overrides_with_all([traverse::TRAVERSE, traverse::EVERY])
.action(clap::ArgAction::SetTrue),
Arg::new(options::dereference::DEREFERENCE)
.long(options::dereference::DEREFERENCE)
.help(
"affect the referent of each symbolic link (this is the default), \
rather than the symbolic link itself",
)
.action(clap::ArgAction::SetTrue),
Arg::new(options::dereference::NO_DEREFERENCE)
.short('h')
.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(clap::ArgAction::SetTrue),
]
}

#[cfg(test)]
mod tests {
// Note this useful idiom: importing names from outer (for mod tests) scope.
Expand Down
Loading