mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-29 20:17:45 +00:00
Merge pull request #1767 from FelipeLema/mod_opt
Group OPT_ARGUMENTS into mods
This commit is contained in:
commit
517b2a6a22
10 changed files with 326 additions and 283 deletions
|
@ -27,20 +27,30 @@ use std::path::Path;
|
|||
static ABOUT: &str = "change file owner and group";
|
||||
static VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||
|
||||
static OPT_CHANGES: &str = "changes";
|
||||
static OPT_DEREFERENCE: &str = "dereference";
|
||||
static OPT_NO_DEREFERENCE: &str = "no-dereference";
|
||||
static OPT_FROM: &str = "from";
|
||||
static OPT_PRESERVE_ROOT: &str = "preserve-root";
|
||||
static OPT_NO_PRESERVE_ROOT: &str = "no-preserve-root";
|
||||
static OPT_QUIET: &str = "quiet";
|
||||
static OPT_RECURSIVE: &str = "recursive";
|
||||
static OPT_REFERENCE: &str = "reference";
|
||||
static OPT_SILENT: &str = "silent";
|
||||
static OPT_TRAVERSE: &str = "H";
|
||||
static OPT_NO_TRAVERSE: &str = "P";
|
||||
static OPT_TRAVERSE_EVERY: &str = "L";
|
||||
static OPT_VERBOSE: &str = "verbose";
|
||||
pub mod options {
|
||||
pub mod verbosity {
|
||||
pub static CHANGES: &str = "changes";
|
||||
pub static QUIET: &str = "quiet";
|
||||
pub static SILENT: &str = "silent";
|
||||
pub static VERBOSE: &str = "verbose";
|
||||
}
|
||||
pub mod preserve_root {
|
||||
pub static PRESERVE: &str = "preserve-root";
|
||||
pub static NO_PRESERVE: &str = "no-preserve-root";
|
||||
}
|
||||
pub mod dereference {
|
||||
pub static DEREFERENCE: &str = "dereference";
|
||||
pub static NO_DEREFERENCE: &str = "no-dereference";
|
||||
}
|
||||
pub static FROM: &str = "from";
|
||||
pub static RECURSIVE: &str = "recursive";
|
||||
pub mod traverse {
|
||||
pub static TRAVERSE: &str = "H";
|
||||
pub static NO_TRAVERSE: &str = "P";
|
||||
pub static EVERY: &str = "L";
|
||||
}
|
||||
pub static REFERENCE: &str = "reference";
|
||||
}
|
||||
|
||||
static ARG_OWNER: &str = "owner";
|
||||
static ARG_FILES: &str = "files";
|
||||
|
@ -66,80 +76,80 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
|||
.about(ABOUT)
|
||||
.usage(&usage[..])
|
||||
.arg(
|
||||
Arg::with_name(OPT_CHANGES)
|
||||
Arg::with_name(options::verbosity::CHANGES)
|
||||
.short("c")
|
||||
.long(OPT_CHANGES)
|
||||
.long(options::verbosity::CHANGES)
|
||||
.help("like verbose but report only when a change is made"),
|
||||
)
|
||||
.arg(Arg::with_name(OPT_DEREFERENCE).long(OPT_DEREFERENCE).help(
|
||||
.arg(Arg::with_name(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",
|
||||
))
|
||||
.arg(
|
||||
Arg::with_name(OPT_NO_DEREFERENCE)
|
||||
Arg::with_name(options::dereference::NO_DEREFERENCE)
|
||||
.short("h")
|
||||
.long(OPT_NO_DEREFERENCE)
|
||||
.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)",
|
||||
),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name(OPT_FROM)
|
||||
.long(OPT_FROM)
|
||||
Arg::with_name(options::FROM)
|
||||
.long(options::FROM)
|
||||
.help(
|
||||
"change the owner and/or group of each file only if its current owner and/or group match those specified here. Either may be omitted, in which case a match is not required for the omitted attribute",
|
||||
)
|
||||
.value_name("CURRENT_OWNER:CURRENT_GROUP"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name(OPT_PRESERVE_ROOT)
|
||||
.long(OPT_PRESERVE_ROOT)
|
||||
Arg::with_name(options::preserve_root::PRESERVE)
|
||||
.long(options::preserve_root::PRESERVE)
|
||||
.help("fail to operate recursively on '/'"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name(OPT_NO_PRESERVE_ROOT)
|
||||
.long(OPT_NO_PRESERVE_ROOT)
|
||||
Arg::with_name(options::preserve_root::NO_PRESERVE)
|
||||
.long(options::preserve_root::NO_PRESERVE)
|
||||
.help("do not treat '/' specially (the default)"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name(OPT_QUIET)
|
||||
.long(OPT_QUIET)
|
||||
Arg::with_name(options::verbosity::QUIET)
|
||||
.long(options::verbosity::QUIET)
|
||||
.help("suppress most error messages"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name(OPT_RECURSIVE)
|
||||
Arg::with_name(options::RECURSIVE)
|
||||
.short("R")
|
||||
.long(OPT_RECURSIVE)
|
||||
.long(options::RECURSIVE)
|
||||
.help("operate on files and directories recursively"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name(OPT_REFERENCE)
|
||||
.long(OPT_REFERENCE)
|
||||
Arg::with_name(options::REFERENCE)
|
||||
.long(options::REFERENCE)
|
||||
.help("use RFILE's owner and group rather than specifying OWNER:GROUP values")
|
||||
.value_name("RFILE")
|
||||
.min_values(1),
|
||||
)
|
||||
.arg(Arg::with_name(OPT_SILENT).short("f").long(OPT_SILENT))
|
||||
.arg(Arg::with_name(options::verbosity::SILENT).short("f").long(options::verbosity::SILENT))
|
||||
.arg(
|
||||
Arg::with_name(OPT_TRAVERSE)
|
||||
.short(OPT_TRAVERSE)
|
||||
Arg::with_name(options::traverse::TRAVERSE)
|
||||
.short(options::traverse::TRAVERSE)
|
||||
.help("if a command line argument is a symbolic link to a directory, traverse it")
|
||||
.overrides_with_all(&[OPT_TRAVERSE_EVERY, OPT_NO_TRAVERSE]),
|
||||
.overrides_with_all(&[options::traverse::EVERY, options::traverse::NO_TRAVERSE]),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name(OPT_TRAVERSE_EVERY)
|
||||
.short(OPT_TRAVERSE_EVERY)
|
||||
Arg::with_name(options::traverse::EVERY)
|
||||
.short(options::traverse::EVERY)
|
||||
.help("traverse every symbolic link to a directory encountered")
|
||||
.overrides_with_all(&[OPT_TRAVERSE, OPT_NO_TRAVERSE]),
|
||||
.overrides_with_all(&[options::traverse::TRAVERSE, options::traverse::NO_TRAVERSE]),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name(OPT_NO_TRAVERSE)
|
||||
.short(OPT_NO_TRAVERSE)
|
||||
Arg::with_name(options::traverse::NO_TRAVERSE)
|
||||
.short(options::traverse::NO_TRAVERSE)
|
||||
.help("do not traverse any symbolic links (default)")
|
||||
.overrides_with_all(&[OPT_TRAVERSE, OPT_TRAVERSE_EVERY]),
|
||||
.overrides_with_all(&[options::traverse::TRAVERSE, options::traverse::EVERY]),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name(OPT_VERBOSE)
|
||||
.long(OPT_VERBOSE)
|
||||
Arg::with_name(options::verbosity::VERBOSE)
|
||||
.long(options::verbosity::VERBOSE)
|
||||
.help("output a diagnostic for every file processed"),
|
||||
)
|
||||
.arg(
|
||||
|
@ -166,23 +176,23 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
|||
.map(|v| v.map(ToString::to_string).collect())
|
||||
.unwrap_or_default();
|
||||
|
||||
let preserve_root = matches.is_present(OPT_PRESERVE_ROOT);
|
||||
let preserve_root = matches.is_present(options::preserve_root::PRESERVE);
|
||||
|
||||
let mut derefer = if matches.is_present(OPT_NO_DEREFERENCE) {
|
||||
let mut derefer = if matches.is_present(options::dereference::NO_DEREFERENCE) {
|
||||
1
|
||||
} else {
|
||||
0
|
||||
};
|
||||
|
||||
let mut bit_flag = if matches.is_present(OPT_TRAVERSE) {
|
||||
let mut bit_flag = if matches.is_present(options::traverse::TRAVERSE) {
|
||||
FTS_COMFOLLOW | FTS_PHYSICAL
|
||||
} else if matches.is_present(OPT_TRAVERSE_EVERY) {
|
||||
} else if matches.is_present(options::traverse::EVERY) {
|
||||
FTS_LOGICAL
|
||||
} else {
|
||||
FTS_PHYSICAL
|
||||
};
|
||||
|
||||
let recursive = matches.is_present(OPT_RECURSIVE);
|
||||
let recursive = matches.is_present(options::RECURSIVE);
|
||||
if recursive {
|
||||
if bit_flag == FTS_PHYSICAL {
|
||||
if derefer == 1 {
|
||||
|
@ -195,17 +205,19 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
|||
bit_flag = FTS_PHYSICAL;
|
||||
}
|
||||
|
||||
let verbosity = if matches.is_present(OPT_CHANGES) {
|
||||
let verbosity = if matches.is_present(options::verbosity::CHANGES) {
|
||||
Verbosity::Changes
|
||||
} else if matches.is_present(OPT_SILENT) || matches.is_present(OPT_QUIET) {
|
||||
} else if matches.is_present(options::verbosity::SILENT)
|
||||
|| matches.is_present(options::verbosity::QUIET)
|
||||
{
|
||||
Verbosity::Silent
|
||||
} else if matches.is_present(OPT_VERBOSE) {
|
||||
} else if matches.is_present(options::verbosity::VERBOSE) {
|
||||
Verbosity::Verbose
|
||||
} else {
|
||||
Verbosity::Normal
|
||||
};
|
||||
|
||||
let filter = if let Some(spec) = matches.value_of(OPT_FROM) {
|
||||
let filter = if let Some(spec) = matches.value_of(options::FROM) {
|
||||
match parse_spec(&spec) {
|
||||
Ok((Some(uid), None)) => IfFrom::User(uid),
|
||||
Ok((None, Some(gid))) => IfFrom::Group(gid),
|
||||
|
@ -222,7 +234,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
|||
|
||||
let dest_uid: Option<u32>;
|
||||
let dest_gid: Option<u32>;
|
||||
if let Some(file) = matches.value_of(OPT_REFERENCE) {
|
||||
if let Some(file) = matches.value_of(options::REFERENCE) {
|
||||
match fs::metadata(&file) {
|
||||
Ok(meta) => {
|
||||
dest_gid = Some(meta.gid());
|
||||
|
|
|
@ -87,11 +87,13 @@ macro_rules! print_adjusted {
|
|||
static ABOUT: &str = "Display file or file system status.";
|
||||
static VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||
|
||||
static OPT_DEREFERENCE: &str = "dereference";
|
||||
static OPT_FILE_SYSTEM: &str = "file-system";
|
||||
static OPT_FORMAT: &str = "format";
|
||||
static OPT_PRINTF: &str = "printf";
|
||||
static OPT_TERSE: &str = "terse";
|
||||
pub mod options {
|
||||
pub static DEREFERENCE: &str = "dereference";
|
||||
pub static FILE_SYSTEM: &str = "file-system";
|
||||
pub static FORMAT: &str = "format";
|
||||
pub static PRINTF: &str = "printf";
|
||||
pub static TERSE: &str = "terse";
|
||||
}
|
||||
|
||||
static ARG_FILES: &str = "files";
|
||||
|
||||
|
@ -464,15 +466,17 @@ impl Stater {
|
|||
.map(|v| v.map(ToString::to_string).collect())
|
||||
.unwrap_or_default();
|
||||
|
||||
let fmtstr = if matches.is_present(OPT_PRINTF) {
|
||||
matches.value_of(OPT_PRINTF).expect("Invalid format string")
|
||||
let fmtstr = if matches.is_present(options::PRINTF) {
|
||||
matches
|
||||
.value_of(options::PRINTF)
|
||||
.expect("Invalid format string")
|
||||
} else {
|
||||
matches.value_of(OPT_FORMAT).unwrap_or("")
|
||||
matches.value_of(options::FORMAT).unwrap_or("")
|
||||
};
|
||||
|
||||
let use_printf = matches.is_present(OPT_PRINTF);
|
||||
let terse = matches.is_present(OPT_TERSE);
|
||||
let showfs = matches.is_present(OPT_FILE_SYSTEM);
|
||||
let use_printf = matches.is_present(options::PRINTF);
|
||||
let terse = matches.is_present(options::TERSE);
|
||||
let showfs = matches.is_present(options::FILE_SYSTEM);
|
||||
|
||||
let default_tokens = if fmtstr.is_empty() {
|
||||
Stater::generate_tokens(&Stater::default_fmt(showfs, terse, false), use_printf).unwrap()
|
||||
|
@ -501,7 +505,7 @@ impl Stater {
|
|||
};
|
||||
|
||||
Ok(Stater {
|
||||
follow: matches.is_present(OPT_DEREFERENCE),
|
||||
follow: matches.is_present(options::DEREFERENCE),
|
||||
showfs,
|
||||
from_user: !fmtstr.is_empty(),
|
||||
files,
|
||||
|
@ -955,27 +959,27 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
|||
.usage(&usage[..])
|
||||
.after_help(&long_usage[..])
|
||||
.arg(
|
||||
Arg::with_name(OPT_DEREFERENCE)
|
||||
Arg::with_name(options::DEREFERENCE)
|
||||
.short("L")
|
||||
.long(OPT_DEREFERENCE)
|
||||
.long(options::DEREFERENCE)
|
||||
.help("follow links"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name(OPT_FILE_SYSTEM)
|
||||
Arg::with_name(options::FILE_SYSTEM)
|
||||
.short("f")
|
||||
.long(OPT_FILE_SYSTEM)
|
||||
.long(options::FILE_SYSTEM)
|
||||
.help("display file system status instead of file status"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name(OPT_TERSE)
|
||||
Arg::with_name(options::TERSE)
|
||||
.short("t")
|
||||
.long(OPT_TERSE)
|
||||
.long(options::TERSE)
|
||||
.help("print the information in terse form"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name(OPT_FORMAT)
|
||||
Arg::with_name(options::FORMAT)
|
||||
.short("c")
|
||||
.long(OPT_FORMAT)
|
||||
.long(options::FORMAT)
|
||||
.help(
|
||||
"use the specified FORMAT instead of the default;
|
||||
output a newline after each use of FORMAT",
|
||||
|
@ -983,8 +987,8 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
|||
.value_name("FORMAT"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name(OPT_PRINTF)
|
||||
.long(OPT_PRINTF)
|
||||
Arg::with_name(options::PRINTF)
|
||||
.long(options::PRINTF)
|
||||
.value_name("FORMAT")
|
||||
.help(
|
||||
"like --format, but interpret backslash escapes,
|
||||
|
|
|
@ -19,8 +19,10 @@ static EXIT_ERR: i32 = 1;
|
|||
|
||||
static ABOUT: &str = "Synchronize cached writes to persistent storage";
|
||||
static VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||
static OPT_FILE_SYSTEM: &str = "file-system";
|
||||
static OPT_DATA: &str = "data";
|
||||
pub mod options {
|
||||
pub static FILE_SYSTEM: &str = "file-system";
|
||||
pub static DATA: &str = "data";
|
||||
}
|
||||
|
||||
static ARG_FILES: &str = "files";
|
||||
|
||||
|
@ -170,17 +172,17 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
|||
.about(ABOUT)
|
||||
.usage(&usage[..])
|
||||
.arg(
|
||||
Arg::with_name(OPT_FILE_SYSTEM)
|
||||
Arg::with_name(options::FILE_SYSTEM)
|
||||
.short("f")
|
||||
.long(OPT_FILE_SYSTEM)
|
||||
.conflicts_with(OPT_DATA)
|
||||
.long(options::FILE_SYSTEM)
|
||||
.conflicts_with(options::DATA)
|
||||
.help("sync the file systems that contain the files (Linux and Windows only)"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name(OPT_DATA)
|
||||
Arg::with_name(options::DATA)
|
||||
.short("d")
|
||||
.long(OPT_DATA)
|
||||
.conflicts_with(OPT_FILE_SYSTEM)
|
||||
.long(options::DATA)
|
||||
.conflicts_with(options::FILE_SYSTEM)
|
||||
.help("sync only file data, no unneeded metadata (Linux only)"),
|
||||
)
|
||||
.arg(Arg::with_name(ARG_FILES).multiple(true).takes_value(true))
|
||||
|
@ -197,10 +199,10 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
|||
}
|
||||
}
|
||||
|
||||
if matches.is_present(OPT_FILE_SYSTEM) {
|
||||
if matches.is_present(options::FILE_SYSTEM) {
|
||||
#[cfg(any(target_os = "linux", target_os = "windows"))]
|
||||
syncfs(files);
|
||||
} else if matches.is_present(OPT_DATA) {
|
||||
} else if matches.is_present(options::DATA) {
|
||||
#[cfg(target_os = "linux")]
|
||||
fdatasync(files);
|
||||
} else {
|
||||
|
|
|
@ -27,15 +27,19 @@ use std::path::Path;
|
|||
use std::thread::sleep;
|
||||
use std::time::Duration;
|
||||
|
||||
static OPT_BYTES: &str = "bytes";
|
||||
static OPT_FOLLOW: &str = "follow";
|
||||
static OPT_LINES: &str = "lines";
|
||||
static OPT_PID: &str = "pid";
|
||||
static OPT_QUIET: &str = "quiet";
|
||||
static OPT_SILENT: &str = "silent";
|
||||
static OPT_SLEEP_INT: &str = "sleep-interval";
|
||||
static OPT_VERBOSE: &str = "verbose";
|
||||
static OPT_ZERO_TERM: &str = "zero-terminated";
|
||||
pub mod options {
|
||||
pub mod verbosity {
|
||||
pub static QUIET: &str = "quiet";
|
||||
pub static SILENT: &str = "silent";
|
||||
pub static VERBOSE: &str = "verbose";
|
||||
}
|
||||
pub static BYTES: &str = "bytes";
|
||||
pub static FOLLOW: &str = "follow";
|
||||
pub static LINES: &str = "lines";
|
||||
pub static PID: &str = "pid";
|
||||
pub static SLEEP_INT: &str = "sleep-interval";
|
||||
pub static ZERO_TERM: &str = "zero-terminated";
|
||||
}
|
||||
|
||||
static ARG_FILES: &str = "files";
|
||||
|
||||
|
@ -72,58 +76,58 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
|||
.version(crate_version!())
|
||||
.about("output the last part of files")
|
||||
.arg(
|
||||
Arg::with_name(OPT_BYTES)
|
||||
Arg::with_name(options::BYTES)
|
||||
.short("c")
|
||||
.long(OPT_BYTES)
|
||||
.long(options::BYTES)
|
||||
.takes_value(true)
|
||||
.help("Number of bytes to print"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name(OPT_FOLLOW)
|
||||
Arg::with_name(options::FOLLOW)
|
||||
.short("f")
|
||||
.long(OPT_FOLLOW)
|
||||
.long(options::FOLLOW)
|
||||
.help("Print the file as it grows"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name(OPT_LINES)
|
||||
Arg::with_name(options::LINES)
|
||||
.short("n")
|
||||
.long(OPT_LINES)
|
||||
.long(options::LINES)
|
||||
.takes_value(true)
|
||||
.help("Number of lines to print"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name(OPT_PID)
|
||||
.long(OPT_PID)
|
||||
Arg::with_name(options::PID)
|
||||
.long(options::PID)
|
||||
.takes_value(true)
|
||||
.help("with -f, terminate after process ID, PID dies"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name(OPT_QUIET)
|
||||
Arg::with_name(options::verbosity::QUIET)
|
||||
.short("q")
|
||||
.long(OPT_QUIET)
|
||||
.long(options::verbosity::QUIET)
|
||||
.help("never output headers giving file names"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name(OPT_SILENT)
|
||||
.long(OPT_SILENT)
|
||||
Arg::with_name(options::verbosity::SILENT)
|
||||
.long(options::verbosity::SILENT)
|
||||
.help("synonym of --quiet"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name(OPT_SLEEP_INT)
|
||||
Arg::with_name(options::SLEEP_INT)
|
||||
.short("s")
|
||||
.long(OPT_SLEEP_INT)
|
||||
.long(options::SLEEP_INT)
|
||||
.help("Number or seconds to sleep between polling the file when running with -f"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name(OPT_VERBOSE)
|
||||
Arg::with_name(options::verbosity::VERBOSE)
|
||||
.short("v")
|
||||
.long(OPT_VERBOSE)
|
||||
.long(options::verbosity::VERBOSE)
|
||||
.help("always output headers giving file names"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name(OPT_ZERO_TERM)
|
||||
Arg::with_name(options::ZERO_TERM)
|
||||
.short("z")
|
||||
.long(OPT_ZERO_TERM)
|
||||
.long(options::ZERO_TERM)
|
||||
.help("Line delimiter is NUL, not newline"),
|
||||
)
|
||||
.arg(
|
||||
|
@ -135,9 +139,9 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
|||
|
||||
let matches = app.get_matches_from(args);
|
||||
|
||||
settings.follow = matches.is_present(OPT_FOLLOW);
|
||||
settings.follow = matches.is_present(options::FOLLOW);
|
||||
if settings.follow {
|
||||
if let Some(n) = matches.value_of(OPT_SLEEP_INT) {
|
||||
if let Some(n) = matches.value_of(options::SLEEP_INT) {
|
||||
let parsed: Option<u32> = n.parse().ok();
|
||||
if let Some(m) = parsed {
|
||||
settings.sleep_msec = m * 1000
|
||||
|
@ -145,7 +149,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
|||
}
|
||||
}
|
||||
|
||||
if let Some(pid_str) = matches.value_of(OPT_PID) {
|
||||
if let Some(pid_str) = matches.value_of(options::PID) {
|
||||
if let Ok(pid) = pid_str.parse() {
|
||||
settings.pid = pid;
|
||||
if pid != 0 {
|
||||
|
@ -161,7 +165,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
|||
}
|
||||
}
|
||||
|
||||
match matches.value_of(OPT_LINES) {
|
||||
match matches.value_of(options::LINES) {
|
||||
Some(n) => {
|
||||
let mut slice: &str = n;
|
||||
if slice.chars().next().unwrap_or('_') == '+' {
|
||||
|
@ -177,7 +181,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
|||
}
|
||||
}
|
||||
None => {
|
||||
if let Some(n) = matches.value_of(OPT_BYTES) {
|
||||
if let Some(n) = matches.value_of(options::BYTES) {
|
||||
let mut slice: &str = n;
|
||||
if slice.chars().next().unwrap_or('_') == '+' {
|
||||
settings.beginning = true;
|
||||
|
@ -194,14 +198,15 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
|||
}
|
||||
};
|
||||
|
||||
if matches.is_present(OPT_ZERO_TERM) {
|
||||
if matches.is_present(options::ZERO_TERM) {
|
||||
if let FilterMode::Lines(count, _) = settings.mode {
|
||||
settings.mode = FilterMode::Lines(count, 0);
|
||||
}
|
||||
}
|
||||
|
||||
let verbose = matches.is_present(OPT_VERBOSE);
|
||||
let quiet = matches.is_present(OPT_QUIET) || matches.is_present(OPT_SILENT);
|
||||
let verbose = matches.is_present(options::verbosity::VERBOSE);
|
||||
let quiet = matches.is_present(options::verbosity::QUIET)
|
||||
|| matches.is_present(options::verbosity::SILENT);
|
||||
|
||||
let files: Vec<String> = matches
|
||||
.values_of(ARG_FILES)
|
||||
|
|
|
@ -21,14 +21,18 @@ use std::path::Path;
|
|||
|
||||
static VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||
static ABOUT: &str = "Update the access and modification times of each FILE to the current time.";
|
||||
static OPT_ACCESS: &str = "access";
|
||||
static OPT_CURRENT: &str = "current";
|
||||
static OPT_DATE: &str = "date";
|
||||
static OPT_MODIFICATION: &str = "modification";
|
||||
static OPT_NO_CREATE: &str = "no-create";
|
||||
static OPT_NO_DEREF: &str = "no-dereference";
|
||||
static OPT_REFERENCE: &str = "reference";
|
||||
static OPT_TIME: &str = "time";
|
||||
pub mod options {
|
||||
pub mod sources {
|
||||
pub static DATE: &str = "date";
|
||||
pub static REFERENCE: &str = "reference";
|
||||
pub static CURRENT: &str = "current";
|
||||
}
|
||||
pub static ACCESS: &str = "access";
|
||||
pub static MODIFICATION: &str = "modification";
|
||||
pub static NO_CREATE: &str = "no-create";
|
||||
pub static NO_DEREF: &str = "no-dereference";
|
||||
pub static TIME: &str = "time";
|
||||
}
|
||||
|
||||
static ARG_FILES: &str = "files";
|
||||
|
||||
|
@ -62,54 +66,54 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
|||
.about(ABOUT)
|
||||
.usage(&usage[..])
|
||||
.arg(
|
||||
Arg::with_name(OPT_ACCESS)
|
||||
Arg::with_name(options::ACCESS)
|
||||
.short("a")
|
||||
.help("change only the access time"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name(OPT_CURRENT)
|
||||
Arg::with_name(options::sources::CURRENT)
|
||||
.short("t")
|
||||
.help("use [[CC]YY]MMDDhhmm[.ss] instead of the current time")
|
||||
.value_name("STAMP")
|
||||
.takes_value(true),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name(OPT_DATE)
|
||||
Arg::with_name(options::sources::DATE)
|
||||
.short("d")
|
||||
.long(OPT_DATE)
|
||||
.long(options::sources::DATE)
|
||||
.help("parse argument and use it instead of current time")
|
||||
.value_name("STRING"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name(OPT_MODIFICATION)
|
||||
Arg::with_name(options::MODIFICATION)
|
||||
.short("m")
|
||||
.help("change only the modification time"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name(OPT_NO_CREATE)
|
||||
Arg::with_name(options::NO_CREATE)
|
||||
.short("c")
|
||||
.long(OPT_NO_CREATE)
|
||||
.long(options::NO_CREATE)
|
||||
.help("do not create any files"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name(OPT_NO_DEREF)
|
||||
Arg::with_name(options::NO_DEREF)
|
||||
.short("h")
|
||||
.long(OPT_NO_DEREF)
|
||||
.long(options::NO_DEREF)
|
||||
.help(
|
||||
"affect each symbolic link instead of any referenced file \
|
||||
(only for systems that can change the timestamps of a symlink)",
|
||||
),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name(OPT_REFERENCE)
|
||||
Arg::with_name(options::sources::REFERENCE)
|
||||
.short("r")
|
||||
.long(OPT_REFERENCE)
|
||||
.long(options::sources::REFERENCE)
|
||||
.help("use this file's times instead of the current time")
|
||||
.value_name("FILE"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name(OPT_TIME)
|
||||
.long(OPT_TIME)
|
||||
Arg::with_name(options::TIME)
|
||||
.long(options::TIME)
|
||||
.help(
|
||||
"change only the specified time: \"access\", \"atime\", or \
|
||||
\"use\" are equivalent to -a; \"modify\" or \"mtime\" are \
|
||||
|
@ -132,26 +136,36 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
|||
.map(|v| v.map(ToString::to_string).collect())
|
||||
.unwrap_or_default();
|
||||
|
||||
if matches.is_present(OPT_DATE)
|
||||
&& (matches.is_present(OPT_REFERENCE) || matches.is_present(OPT_CURRENT))
|
||||
|| matches.is_present(OPT_REFERENCE)
|
||||
&& (matches.is_present(OPT_DATE) || matches.is_present(OPT_CURRENT))
|
||||
|| matches.is_present(OPT_CURRENT)
|
||||
&& (matches.is_present(OPT_DATE) || matches.is_present(OPT_REFERENCE))
|
||||
if matches.is_present(options::sources::DATE)
|
||||
&& (matches.is_present(options::sources::REFERENCE)
|
||||
|| matches.is_present(options::sources::CURRENT))
|
||||
|| matches.is_present(options::sources::REFERENCE)
|
||||
&& (matches.is_present(options::sources::DATE)
|
||||
|| matches.is_present(options::sources::CURRENT))
|
||||
|| matches.is_present(options::sources::CURRENT)
|
||||
&& (matches.is_present(options::sources::DATE)
|
||||
|| matches.is_present(options::sources::REFERENCE))
|
||||
{
|
||||
panic!("Invalid options: cannot specify reference time from more than one source");
|
||||
}
|
||||
|
||||
let (mut atime, mut mtime) = if matches.is_present(OPT_REFERENCE) {
|
||||
let (mut atime, mut mtime) = if matches.is_present(options::sources::REFERENCE) {
|
||||
stat(
|
||||
&matches.value_of(OPT_REFERENCE).unwrap()[..],
|
||||
!matches.is_present(OPT_NO_DEREF),
|
||||
&matches.value_of(options::sources::REFERENCE).unwrap()[..],
|
||||
!matches.is_present(options::NO_DEREF),
|
||||
)
|
||||
} else if matches.is_present(OPT_DATE) || matches.is_present(OPT_CURRENT) {
|
||||
let timestamp = if matches.is_present(OPT_DATE) {
|
||||
parse_date(matches.value_of(OPT_DATE).unwrap().as_ref())
|
||||
} else if matches.is_present(options::sources::DATE)
|
||||
|| matches.is_present(options::sources::CURRENT)
|
||||
{
|
||||
let timestamp = if matches.is_present(options::sources::DATE) {
|
||||
parse_date(matches.value_of(options::sources::DATE).unwrap().as_ref())
|
||||
} else {
|
||||
parse_timestamp(matches.value_of(OPT_CURRENT).unwrap().as_ref())
|
||||
parse_timestamp(
|
||||
matches
|
||||
.value_of(options::sources::CURRENT)
|
||||
.unwrap()
|
||||
.as_ref(),
|
||||
)
|
||||
};
|
||||
(timestamp, timestamp)
|
||||
} else {
|
||||
|
@ -164,7 +178,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
|||
|
||||
if !Path::new(path).exists() {
|
||||
// no-dereference included here for compatibility
|
||||
if matches.is_present(OPT_NO_CREATE) || matches.is_present(OPT_NO_DEREF) {
|
||||
if matches.is_present(options::NO_CREATE) || matches.is_present(options::NO_DEREF) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -174,9 +188,9 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
|||
};
|
||||
|
||||
// Minor optimization: if no reference time was specified, we're done.
|
||||
if !(matches.is_present(OPT_DATE)
|
||||
|| matches.is_present(OPT_REFERENCE)
|
||||
|| matches.is_present(OPT_CURRENT))
|
||||
if !(matches.is_present(options::sources::DATE)
|
||||
|| matches.is_present(options::sources::REFERENCE)
|
||||
|| matches.is_present(options::sources::CURRENT))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
@ -184,14 +198,14 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
|||
|
||||
// If changing "only" atime or mtime, grab the existing value of the other.
|
||||
// Note that "-a" and "-m" may be passed together; this is not an xor.
|
||||
if matches.is_present(OPT_ACCESS)
|
||||
|| matches.is_present(OPT_MODIFICATION)
|
||||
|| matches.is_present(OPT_TIME)
|
||||
if matches.is_present(options::ACCESS)
|
||||
|| matches.is_present(options::MODIFICATION)
|
||||
|| matches.is_present(options::TIME)
|
||||
{
|
||||
let st = stat(path, !matches.is_present(OPT_NO_DEREF));
|
||||
let time = matches.value_of(OPT_TIME).unwrap_or("");
|
||||
let st = stat(path, !matches.is_present(options::NO_DEREF));
|
||||
let time = matches.value_of(options::TIME).unwrap_or("");
|
||||
|
||||
if !(matches.is_present(OPT_ACCESS)
|
||||
if !(matches.is_present(options::ACCESS)
|
||||
|| time.contains(&"access".to_owned())
|
||||
|| time.contains(&"atime".to_owned())
|
||||
|| time.contains(&"use".to_owned()))
|
||||
|
@ -199,7 +213,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
|||
atime = st.0;
|
||||
}
|
||||
|
||||
if !(matches.is_present(OPT_MODIFICATION)
|
||||
if !(matches.is_present(options::MODIFICATION)
|
||||
|| time.contains(&"modify".to_owned())
|
||||
|| time.contains(&"mtime".to_owned()))
|
||||
{
|
||||
|
@ -207,7 +221,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
|||
}
|
||||
}
|
||||
|
||||
if matches.is_present(OPT_NO_DEREF) {
|
||||
if matches.is_present(options::NO_DEREF) {
|
||||
if let Err(e) = set_symlink_file_times(path, atime, mtime) {
|
||||
show_warning!("cannot touch '{}': {}", path, e);
|
||||
}
|
||||
|
|
|
@ -29,10 +29,12 @@ enum TruncateMode {
|
|||
static ABOUT: &str = "Shrink or extend the size of each file to the specified size.";
|
||||
static VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||
|
||||
static OPT_IO_BLOCKS: &str = "io-blocks";
|
||||
static OPT_NO_CREATE: &str = "no-create";
|
||||
static OPT_REFERENCE: &str = "reference";
|
||||
static OPT_SIZE: &str = "size";
|
||||
pub mod options {
|
||||
pub static IO_BLOCKS: &str = "io-blocks";
|
||||
pub static NO_CREATE: &str = "no-create";
|
||||
pub static REFERENCE: &str = "reference";
|
||||
pub static SIZE: &str = "size";
|
||||
}
|
||||
|
||||
static ARG_FILES: &str = "files";
|
||||
|
||||
|
@ -72,26 +74,26 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
|||
.usage(&usage[..])
|
||||
.after_help(&long_usage[..])
|
||||
.arg(
|
||||
Arg::with_name(OPT_IO_BLOCKS)
|
||||
Arg::with_name(options::IO_BLOCKS)
|
||||
.short("o")
|
||||
.long(OPT_IO_BLOCKS)
|
||||
.long(options::IO_BLOCKS)
|
||||
.help("treat SIZE as the number of I/O blocks of the file rather than bytes (NOT IMPLEMENTED)")
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name(OPT_NO_CREATE)
|
||||
Arg::with_name(options::NO_CREATE)
|
||||
.short("c")
|
||||
.long(OPT_NO_CREATE)
|
||||
.long(options::NO_CREATE)
|
||||
.help("do not create files that do not exist")
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name(OPT_REFERENCE)
|
||||
Arg::with_name(options::REFERENCE)
|
||||
.short("r")
|
||||
.long(OPT_REFERENCE)
|
||||
.long(options::REFERENCE)
|
||||
.help("base the size of each file on the size of RFILE")
|
||||
.value_name("RFILE")
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name(OPT_SIZE)
|
||||
Arg::with_name(options::SIZE)
|
||||
.short("s")
|
||||
.long("size")
|
||||
.help("set or adjust the size of each file according to SIZE, which is in bytes unless --io-blocks is specified")
|
||||
|
@ -109,10 +111,10 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
|||
show_error!("Missing an argument");
|
||||
return 1;
|
||||
} else {
|
||||
let io_blocks = matches.is_present(OPT_IO_BLOCKS);
|
||||
let no_create = matches.is_present(OPT_NO_CREATE);
|
||||
let reference = matches.value_of(OPT_REFERENCE).map(String::from);
|
||||
let size = matches.value_of(OPT_SIZE).map(String::from);
|
||||
let io_blocks = matches.is_present(options::IO_BLOCKS);
|
||||
let no_create = matches.is_present(options::NO_CREATE);
|
||||
let reference = matches.value_of(options::REFERENCE).map(String::from);
|
||||
let size = matches.value_of(options::SIZE).map(String::from);
|
||||
if reference.is_none() && size.is_none() {
|
||||
crash!(1, "you must specify either --reference or --size");
|
||||
} else {
|
||||
|
|
|
@ -19,19 +19,17 @@ use platform_info::*;
|
|||
const VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||
const ABOUT: &str = "Print certain system information. With no OPTION, same as -s.";
|
||||
|
||||
const OPT_ALL: &str = "all";
|
||||
const OPT_KERNELNAME: &str = "kernel-name";
|
||||
const OPT_NODENAME: &str = "nodename";
|
||||
const OPT_KERNELVERSION: &str = "kernel-version";
|
||||
const OPT_KERNELRELEASE: &str = "kernel-release";
|
||||
const OPT_MACHINE: &str = "machine";
|
||||
const OPT_PROCESSOR: &str = "processor";
|
||||
const OPT_HWPLATFORM: &str = "hardware-platform";
|
||||
|
||||
//FIXME: unimplemented options
|
||||
//const OPT_PROCESSOR: &'static str = "processor";
|
||||
//const OPT_HWPLATFORM: &'static str = "hardware-platform";
|
||||
const OPT_OS: &str = "operating-system";
|
||||
pub mod options {
|
||||
pub static ALL: &str = "all";
|
||||
pub static KERNELNAME: &str = "kernel-name";
|
||||
pub static NODENAME: &str = "nodename";
|
||||
pub static KERNELVERSION: &str = "kernel-version";
|
||||
pub static KERNELRELEASE: &str = "kernel-release";
|
||||
pub static MACHINE: &str = "machine";
|
||||
pub static PROCESSOR: &str = "processor";
|
||||
pub static HWPLATFORM: &str = "hardware-platform";
|
||||
pub static OS: &str = "operating-system";
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
const HOST_OS: &str = "GNU/Linux";
|
||||
|
@ -54,58 +52,58 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
|||
.version(VERSION)
|
||||
.about(ABOUT)
|
||||
.usage(&usage[..])
|
||||
.arg(Arg::with_name(OPT_ALL)
|
||||
.arg(Arg::with_name(options::ALL)
|
||||
.short("a")
|
||||
.long(OPT_ALL)
|
||||
.long(options::ALL)
|
||||
.help("Behave as though all of the options -mnrsv were specified."))
|
||||
.arg(Arg::with_name(OPT_KERNELNAME)
|
||||
.arg(Arg::with_name(options::KERNELNAME)
|
||||
.short("s")
|
||||
.long(OPT_KERNELNAME)
|
||||
.long(options::KERNELNAME)
|
||||
.alias("sysname") // Obsolescent option in GNU uname
|
||||
.help("print the kernel name."))
|
||||
.arg(Arg::with_name(OPT_NODENAME)
|
||||
.arg(Arg::with_name(options::NODENAME)
|
||||
.short("n")
|
||||
.long(OPT_NODENAME)
|
||||
.long(options::NODENAME)
|
||||
.help("print the nodename (the nodename may be a name that the system is known by to a communications network)."))
|
||||
.arg(Arg::with_name(OPT_KERNELRELEASE)
|
||||
.arg(Arg::with_name(options::KERNELRELEASE)
|
||||
.short("r")
|
||||
.long(OPT_KERNELRELEASE)
|
||||
.long(options::KERNELRELEASE)
|
||||
.alias("release") // Obsolescent option in GNU uname
|
||||
.help("print the operating system release."))
|
||||
.arg(Arg::with_name(OPT_KERNELVERSION)
|
||||
.arg(Arg::with_name(options::KERNELVERSION)
|
||||
.short("v")
|
||||
.long(OPT_KERNELVERSION)
|
||||
.long(options::KERNELVERSION)
|
||||
.help("print the operating system version."))
|
||||
.arg(Arg::with_name(OPT_HWPLATFORM)
|
||||
.arg(Arg::with_name(options::HWPLATFORM)
|
||||
.short("i")
|
||||
.long(OPT_HWPLATFORM)
|
||||
.long(options::HWPLATFORM)
|
||||
.help("print the hardware platform (non-portable)"))
|
||||
.arg(Arg::with_name(OPT_MACHINE)
|
||||
.arg(Arg::with_name(options::MACHINE)
|
||||
.short("m")
|
||||
.long(OPT_MACHINE)
|
||||
.long(options::MACHINE)
|
||||
.help("print the machine hardware name."))
|
||||
.arg(Arg::with_name(OPT_PROCESSOR)
|
||||
.arg(Arg::with_name(options::PROCESSOR)
|
||||
.short("p")
|
||||
.long(OPT_PROCESSOR)
|
||||
.long(options::PROCESSOR)
|
||||
.help("print the processor type (non-portable)"))
|
||||
.arg(Arg::with_name(OPT_OS)
|
||||
.arg(Arg::with_name(options::OS)
|
||||
.short("o")
|
||||
.long(OPT_OS)
|
||||
.long(options::OS)
|
||||
.help("print the operating system name."))
|
||||
.get_matches_from(args);
|
||||
|
||||
let uname = return_if_err!(1, PlatformInfo::new());
|
||||
let mut output = String::new();
|
||||
|
||||
let all = matches.is_present(OPT_ALL);
|
||||
let kernelname = matches.is_present(OPT_KERNELNAME);
|
||||
let nodename = matches.is_present(OPT_NODENAME);
|
||||
let kernelrelease = matches.is_present(OPT_KERNELRELEASE);
|
||||
let kernelversion = matches.is_present(OPT_KERNELVERSION);
|
||||
let machine = matches.is_present(OPT_MACHINE);
|
||||
let processor = matches.is_present(OPT_PROCESSOR);
|
||||
let hwplatform = matches.is_present(OPT_HWPLATFORM);
|
||||
let os = matches.is_present(OPT_OS);
|
||||
let all = matches.is_present(options::ALL);
|
||||
let kernelname = matches.is_present(options::KERNELNAME);
|
||||
let nodename = matches.is_present(options::NODENAME);
|
||||
let kernelrelease = matches.is_present(options::KERNELRELEASE);
|
||||
let kernelversion = matches.is_present(options::KERNELVERSION);
|
||||
let machine = matches.is_present(options::MACHINE);
|
||||
let processor = matches.is_present(options::PROCESSOR);
|
||||
let hwplatform = matches.is_present(options::HWPLATFORM);
|
||||
let os = matches.is_present(options::OS);
|
||||
|
||||
let none = !(all
|
||||
|| kernelname
|
||||
|
|
|
@ -16,15 +16,17 @@ use std::str::FromStr;
|
|||
|
||||
static ABOUT: &str = "Report or omit repeated lines.";
|
||||
static VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||
static OPT_ALL_REPEATED: &str = "all-repeated";
|
||||
static OPT_CHECK_CHARS: &str = "check-chars";
|
||||
static OPT_COUNT: &str = "count";
|
||||
static OPT_IGNORE_CASE: &str = "ignore-case";
|
||||
static OPT_REPEATED: &str = "repeated";
|
||||
static OPT_SKIP_FIELDS: &str = "skip-fields";
|
||||
static OPT_SKIP_CHARS: &str = "skip-chars";
|
||||
static OPT_UNIQUE: &str = "unique";
|
||||
static OPT_ZERO_TERMINATED: &str = "zero-terminated";
|
||||
pub mod options {
|
||||
pub static ALL_REPEATED: &str = "all-repeated";
|
||||
pub static CHECK_CHARS: &str = "check-chars";
|
||||
pub static COUNT: &str = "count";
|
||||
pub static IGNORE_CASE: &str = "ignore-case";
|
||||
pub static REPEATED: &str = "repeated";
|
||||
pub static SKIP_FIELDS: &str = "skip-fields";
|
||||
pub static SKIP_CHARS: &str = "skip-chars";
|
||||
pub static UNIQUE: &str = "unique";
|
||||
pub static ZERO_TERMINATED: &str = "zero-terminated";
|
||||
}
|
||||
|
||||
static ARG_FILES: &str = "files";
|
||||
|
||||
|
@ -233,63 +235,63 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
|||
.usage(&usage[..])
|
||||
.after_help(&long_usage[..])
|
||||
.arg(
|
||||
Arg::with_name(OPT_ALL_REPEATED)
|
||||
Arg::with_name(options::ALL_REPEATED)
|
||||
.short("D")
|
||||
.long(OPT_ALL_REPEATED)
|
||||
.long(options::ALL_REPEATED)
|
||||
.possible_values(&["none", "prepend", "separate"])
|
||||
.help("print all duplicate lines. Delimiting is done with blank lines")
|
||||
.value_name("delimit-method")
|
||||
.default_value("none"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name(OPT_CHECK_CHARS)
|
||||
Arg::with_name(options::CHECK_CHARS)
|
||||
.short("w")
|
||||
.long(OPT_CHECK_CHARS)
|
||||
.long(options::CHECK_CHARS)
|
||||
.help("compare no more than N characters in lines")
|
||||
.value_name("N"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name(OPT_COUNT)
|
||||
Arg::with_name(options::COUNT)
|
||||
.short("c")
|
||||
.long(OPT_COUNT)
|
||||
.long(options::COUNT)
|
||||
.help("prefix lines by the number of occurrences"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name(OPT_IGNORE_CASE)
|
||||
Arg::with_name(options::IGNORE_CASE)
|
||||
.short("i")
|
||||
.long(OPT_IGNORE_CASE)
|
||||
.long(options::IGNORE_CASE)
|
||||
.help("ignore differences in case when comparing"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name(OPT_REPEATED)
|
||||
Arg::with_name(options::REPEATED)
|
||||
.short("d")
|
||||
.long(OPT_REPEATED)
|
||||
.long(options::REPEATED)
|
||||
.help("only print duplicate lines"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name(OPT_SKIP_CHARS)
|
||||
Arg::with_name(options::SKIP_CHARS)
|
||||
.short("s")
|
||||
.long(OPT_SKIP_CHARS)
|
||||
.long(options::SKIP_CHARS)
|
||||
.help("avoid comparing the first N characters")
|
||||
.value_name("N"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name(OPT_SKIP_FIELDS)
|
||||
Arg::with_name(options::SKIP_FIELDS)
|
||||
.short("f")
|
||||
.long(OPT_SKIP_FIELDS)
|
||||
.long(options::SKIP_FIELDS)
|
||||
.help("avoid comparing the first N fields")
|
||||
.value_name("N"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name(OPT_UNIQUE)
|
||||
Arg::with_name(options::UNIQUE)
|
||||
.short("u")
|
||||
.long(OPT_UNIQUE)
|
||||
.long(options::UNIQUE)
|
||||
.help("only print unique lines"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name(OPT_ZERO_TERMINATED)
|
||||
Arg::with_name(options::ZERO_TERMINATED)
|
||||
.short("z")
|
||||
.long(OPT_ZERO_TERMINATED)
|
||||
.long(options::ZERO_TERMINATED)
|
||||
.help("end lines with 0 byte, not newline"),
|
||||
)
|
||||
.arg(
|
||||
|
@ -316,11 +318,11 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
|||
};
|
||||
|
||||
let uniq = Uniq {
|
||||
repeats_only: matches.is_present(OPT_REPEATED)
|
||||
|| matches.occurrences_of(OPT_ALL_REPEATED) > 0,
|
||||
uniques_only: matches.is_present(OPT_UNIQUE),
|
||||
all_repeated: matches.occurrences_of(OPT_ALL_REPEATED) > 0,
|
||||
delimiters: match matches.value_of(OPT_ALL_REPEATED).map(String::from) {
|
||||
repeats_only: matches.is_present(options::REPEATED)
|
||||
|| matches.occurrences_of(options::ALL_REPEATED) > 0,
|
||||
uniques_only: matches.is_present(options::UNIQUE),
|
||||
all_repeated: matches.occurrences_of(options::ALL_REPEATED) > 0,
|
||||
delimiters: match matches.value_of(options::ALL_REPEATED).map(String::from) {
|
||||
Some(ref opt_arg) if opt_arg != "none" => match &(*opt_arg.as_str()) {
|
||||
"prepend" => Delimiters::Prepend,
|
||||
"separate" => Delimiters::Separate,
|
||||
|
@ -328,12 +330,12 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
|||
},
|
||||
_ => Delimiters::None,
|
||||
},
|
||||
show_counts: matches.is_present(OPT_COUNT),
|
||||
skip_fields: opt_parsed(OPT_SKIP_FIELDS, &matches),
|
||||
slice_start: opt_parsed(OPT_SKIP_CHARS, &matches),
|
||||
slice_stop: opt_parsed(OPT_CHECK_CHARS, &matches),
|
||||
ignore_case: matches.is_present(OPT_IGNORE_CASE),
|
||||
zero_terminated: matches.is_present(OPT_ZERO_TERMINATED),
|
||||
show_counts: matches.is_present(options::COUNT),
|
||||
skip_fields: opt_parsed(options::SKIP_FIELDS, &matches),
|
||||
slice_start: opt_parsed(options::SKIP_CHARS, &matches),
|
||||
slice_stop: opt_parsed(options::CHECK_CHARS, &matches),
|
||||
ignore_case: matches.is_present(options::IGNORE_CASE),
|
||||
zero_terminated: matches.is_present(options::ZERO_TERMINATED),
|
||||
};
|
||||
uniq.print_uniq(
|
||||
&mut open_input_file(in_file_name),
|
||||
|
|
|
@ -21,7 +21,9 @@ static VERSION: &str = env!("CARGO_PKG_VERSION");
|
|||
static ABOUT: &str = "Display the current time, the length of time the system has been up,\n\
|
||||
the number of users on the system, and the average number of jobs\n\
|
||||
in the run queue over the last 1, 5 and 15 minutes.";
|
||||
static OPT_SINCE: &str = "since";
|
||||
pub mod options {
|
||||
pub static SINCE: &str = "since";
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
use uucore::libc::getloadavg;
|
||||
|
@ -42,9 +44,9 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
|||
.about(ABOUT)
|
||||
.usage(&usage[..])
|
||||
.arg(
|
||||
Arg::with_name(OPT_SINCE)
|
||||
Arg::with_name(options::SINCE)
|
||||
.short("s")
|
||||
.long(OPT_SINCE)
|
||||
.long(options::SINCE)
|
||||
.help("system up since"),
|
||||
)
|
||||
.get_matches_from(args);
|
||||
|
@ -56,7 +58,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
|||
|
||||
1
|
||||
} else {
|
||||
if matches.is_present(OPT_SINCE) {
|
||||
if matches.is_present(options::SINCE) {
|
||||
let initial_date = Local.timestamp(Utc::now().timestamp() - uptime, 0);
|
||||
println!("{}", initial_date.format("%Y-%m-%d %H:%M:%S"));
|
||||
return 0;
|
||||
|
|
|
@ -29,11 +29,11 @@ struct Settings {
|
|||
impl Settings {
|
||||
fn new(matches: &ArgMatches) -> Settings {
|
||||
let settings = Settings {
|
||||
show_bytes: matches.is_present(OPT_BYTES),
|
||||
show_chars: matches.is_present(OPT_CHAR),
|
||||
show_lines: matches.is_present(OPT_LINES),
|
||||
show_words: matches.is_present(OPT_WORDS),
|
||||
show_max_line_length: matches.is_present(OPT_MAX_LINE_LENGTH),
|
||||
show_bytes: matches.is_present(options::BYTES),
|
||||
show_chars: matches.is_present(options::CHAR),
|
||||
show_lines: matches.is_present(options::LINES),
|
||||
show_words: matches.is_present(options::WORDS),
|
||||
show_max_line_length: matches.is_present(options::MAX_LINE_LENGTH),
|
||||
};
|
||||
|
||||
if settings.show_bytes
|
||||
|
@ -68,11 +68,13 @@ static ABOUT: &str = "Display newline, word, and byte counts for each FILE, and
|
|||
more than one FILE is specified.";
|
||||
static VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||
|
||||
static OPT_BYTES: &str = "bytes";
|
||||
static OPT_CHAR: &str = "chars";
|
||||
static OPT_LINES: &str = "lines";
|
||||
static OPT_MAX_LINE_LENGTH: &str = "max-line-length";
|
||||
static OPT_WORDS: &str = "words";
|
||||
pub mod options {
|
||||
pub static BYTES: &str = "bytes";
|
||||
pub static CHAR: &str = "chars";
|
||||
pub static LINES: &str = "lines";
|
||||
pub static MAX_LINE_LENGTH: &str = "max-line-length";
|
||||
pub static WORDS: &str = "words";
|
||||
}
|
||||
|
||||
static ARG_FILES: &str = "files";
|
||||
|
||||
|
@ -92,33 +94,33 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
|||
.about(ABOUT)
|
||||
.usage(&usage[..])
|
||||
.arg(
|
||||
Arg::with_name(OPT_BYTES)
|
||||
Arg::with_name(options::BYTES)
|
||||
.short("c")
|
||||
.long(OPT_BYTES)
|
||||
.long(options::BYTES)
|
||||
.help("print the byte counts"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name(OPT_CHAR)
|
||||
Arg::with_name(options::CHAR)
|
||||
.short("m")
|
||||
.long(OPT_CHAR)
|
||||
.long(options::CHAR)
|
||||
.help("print the character counts"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name(OPT_LINES)
|
||||
Arg::with_name(options::LINES)
|
||||
.short("l")
|
||||
.long(OPT_LINES)
|
||||
.long(options::LINES)
|
||||
.help("print the newline counts"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name(OPT_MAX_LINE_LENGTH)
|
||||
Arg::with_name(options::MAX_LINE_LENGTH)
|
||||
.short("L")
|
||||
.long(OPT_MAX_LINE_LENGTH)
|
||||
.long(options::MAX_LINE_LENGTH)
|
||||
.help("print the length of the longest line"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name(OPT_WORDS)
|
||||
Arg::with_name(options::WORDS)
|
||||
.short("w")
|
||||
.long(OPT_WORDS)
|
||||
.long(options::WORDS)
|
||||
.help("print the word counts"),
|
||||
)
|
||||
.arg(Arg::with_name(ARG_FILES).multiple(true).takes_value(true))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue