1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-29 20:17:45 +00:00

missing OPT_ s

This commit is contained in:
Felipe Lema 2021-03-09 18:10:04 -03:00
parent 75b3bc02eb
commit d1addc97cc
7 changed files with 199 additions and 172 deletions

View file

@ -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,

View file

@ -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 {

View file

@ -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)

View file

@ -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);
}

View file

@ -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 {

View file

@ -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

View file

@ -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;