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

change remaining usage codes of 2 to 1 for GNU compat

This commit is contained in:
Terts Diepraam 2022-09-10 17:08:03 +02:00
parent 70714bc3cd
commit 975a1d170d
74 changed files with 121 additions and 99 deletions

View file

@ -16,7 +16,7 @@ static SUMMARY: &str = "Determine architecture name for current machine.";
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
uu_app().get_matches_from(args);
uu_app().try_get_matches_from(args)?;
let uts = PlatformInfo::new().map_err_context(|| "cannot get system name".to_string())?;
println!("{}", uts.machine().trim());

View file

@ -49,7 +49,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
//
// Argument parsing
//
let matches = uu_app().get_matches_from(args);
let matches = uu_app().try_get_matches_from(args)?;
// too few arguments
if !matches.contains_id(options::NAME) {

View file

@ -54,7 +54,9 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let after_help = get_long_usage();
let matches = uu_app().after_help(&after_help[..]).get_matches_from(args);
let matches = uu_app()
.after_help(&after_help[..])
.try_get_matches_from(args)?;
let changes = matches.contains_id(options::CHANGES);
let quiet = matches.contains_id(options::QUIET);

View file

@ -15,7 +15,7 @@ use std::ffi::CString;
use std::io::Error;
use std::path::Path;
use std::process;
use uucore::error::{set_exit_code, UResult};
use uucore::error::{set_exit_code, UClapError, UResult};
use uucore::libc::{self, chroot, setgid, setgroups, setuid};
use uucore::{entries, format_usage};
@ -35,7 +35,7 @@ mod options {
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let args = args.collect_lossy();
let matches = uu_app().get_matches_from(args);
let matches = uu_app().try_get_matches_from(args).with_exit_code(125)?;
let default_shell: &'static str = "/bin/sh";
let default_option: &'static str = "-i";

View file

@ -115,7 +115,7 @@ mod options {
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let args = args.collect_ignore();
let matches = uu_app().get_matches_from(args);
let matches = uu_app().try_get_matches_from(args)?;
let files: Vec<String> = match matches.get_many::<String>(options::FILE) {
Some(v) => v.clone().map(|v| v.to_owned()).collect(),

View file

@ -134,7 +134,7 @@ fn open_file(name: &str) -> io::Result<LineReader> {
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let args = args.collect_lossy();
let matches = uu_app().get_matches_from(args);
let matches = uu_app().try_get_matches_from(args)?;
let filename1 = matches.value_of(options::FILE_1).unwrap();
let filename2 = matches.value_of(options::FILE_2).unwrap();
let mut f1 = open_file(filename1).map_err_context(|| filename1.to_string())?;

View file

@ -715,7 +715,7 @@ mod tests {
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let args = args.collect_ignore();
let matches = uu_app().get_matches_from(args);
let matches = uu_app().try_get_matches_from(args)?;
// get the file to split
let file_name = matches.value_of(options::FILE).unwrap();

View file

@ -401,7 +401,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let args = args.collect_ignore();
let delimiter_is_equal = args.contains(&"-d=".to_string()); // special case
let matches = uu_app().get_matches_from(args);
let matches = uu_app().try_get_matches_from(args)?;
let complement = matches.contains_id(options::COMPLEMENT);

View file

@ -144,7 +144,7 @@ impl<'a> From<&'a str> for Rfc3339Format {
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().get_matches_from(args);
let matches = uu_app().try_get_matches_from(args)?;
let format = if let Some(form) = matches.value_of(OPT_FORMAT) {
if !form.starts_with('+') {

View file

@ -712,7 +712,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app()
//.after_help(TODO: Add note about multiplier strings here.)
.get_matches_from(dashed_args);
.try_get_matches_from(dashed_args)?;
match (
matches.contains_id(options::INFILE),

View file

@ -431,7 +431,7 @@ impl fmt::Display for DfError {
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().get_matches_from(args);
let matches = uu_app().try_get_matches_from(args)?;
#[cfg(windows)]
{

View file

@ -67,7 +67,7 @@ pub fn guess_syntax() -> OutputFmt {
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let args = args.collect_ignore();
let matches = uu_app().get_matches_from(&args);
let matches = uu_app().try_get_matches_from(&args)?;
let files = matches
.get_many::<String>(options::FILE)

View file

@ -32,7 +32,9 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let after_help = get_long_usage();
let matches = uu_app().after_help(&after_help[..]).get_matches_from(args);
let matches = uu_app()
.after_help(&after_help[..])
.try_get_matches_from(args)?;
let separator = if matches.contains_id(options::ZERO) {
"\0"

View file

@ -517,7 +517,7 @@ fn build_exclude_patterns(matches: &ArgMatches) -> UResult<Vec<Pattern>> {
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let args = args.collect_ignore();
let matches = uu_app().get_matches_from(args);
let matches = uu_app().try_get_matches_from(args)?;
let summarize = matches.contains_id(options::SUMMARIZE);

View file

@ -26,7 +26,7 @@ use std::iter::Iterator;
use std::os::unix::process::ExitStatusExt;
use std::process;
use uucore::display::Quotable;
use uucore::error::{UResult, USimpleError, UUsageError};
use uucore::error::{UClapError, UResult, USimpleError, UUsageError};
use uucore::format_usage;
#[cfg(unix)]
use uucore::signals::signal_name_by_value;
@ -173,7 +173,7 @@ pub fn uu_app<'a>() -> Command<'a> {
fn run_env(args: impl uucore::Args) -> UResult<()> {
let app = uu_app();
let matches = app.get_matches_from(args);
let matches = app.try_get_matches_from(args).with_exit_code(125)?;
let ignore_env = matches.contains_id("ignore-environment");
let null = matches.contains_id("null");

View file

@ -271,7 +271,7 @@ fn expand_shortcuts(args: &[String]) -> Vec<String> {
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let args = args.collect_ignore();
let matches = uu_app().get_matches_from(expand_shortcuts(&args));
let matches = uu_app().try_get_matches_from(expand_shortcuts(&args))?;
expand(&Options::new(&matches)?).map_err_context(|| "failed to write output".to_string())
}

View file

@ -47,7 +47,7 @@ fn print_factors_str(
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().get_matches_from(args);
let matches = uu_app().try_get_matches_from(args)?;
let stdout = stdout();
// We use a smaller buffer here to pass a gnu test. 4KiB appears to be the default pipe size for bash.
let mut w = io::BufWriter::with_capacity(4 * 1024, stdout.lock());

View file

@ -67,7 +67,7 @@ pub struct FmtOptions {
#[uucore::main]
#[allow(clippy::cognitive_complexity)]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().get_matches_from(args);
let matches = uu_app().try_get_matches_from(args)?;
let mut files: Vec<String> = matches
.get_many::<String>(ARG_FILES)

View file

@ -34,7 +34,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let args = args.collect_lossy();
let (args, obs_width) = handle_obsolete(&args[..]);
let matches = uu_app().get_matches_from(args);
let matches = uu_app().try_get_matches_from(args)?;
let bytes = matches.contains_id(options::BYTES);
let spaces = matches.contains_id(options::SPACES);

View file

@ -70,7 +70,7 @@ fn infallible_gid2grp(gid: &u32) -> String {
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().get_matches_from(args);
let matches = uu_app().try_get_matches_from(args)?;
let users: Vec<String> = matches
.get_many::<String>(options::USERS)

View file

@ -284,7 +284,7 @@ pub fn uumain(mut args: impl uucore::Args) -> UResult<()> {
// causes "error: " to be printed twice (once from crash!() and once from clap). With
// the current setup, the name of the utility is not printed, but I think this is at
// least somewhat better from a user's perspective.
let matches = command.get_matches_from(args);
let matches = command.try_get_matches_from(args)?;
let (name, algo, bits) = detect_algo(&binary_name, &matches);

View file

@ -154,7 +154,7 @@ impl Mode {
fn arg_iterate<'a>(
mut args: impl uucore::Args + 'a,
) -> Result<Box<dyn Iterator<Item = OsString> + 'a>, String> {
) -> UResult<Box<dyn Iterator<Item = OsString> + 'a>> {
// argv[0] is always present
let first = args.next().unwrap();
if let Some(second) = args.next() {
@ -162,16 +162,22 @@ fn arg_iterate<'a>(
match parse::parse_obsolete(s) {
Some(Ok(iter)) => Ok(Box::new(vec![first].into_iter().chain(iter).chain(args))),
Some(Err(e)) => match e {
parse::ParseError::Syntax => Err(format!("bad argument format: {}", s.quote())),
parse::ParseError::Overflow => Err(format!(
parse::ParseError::Syntax => Err(USimpleError::new(
1,
format!("bad argument format: {}", s.quote()),
)),
parse::ParseError::Overflow => Err(USimpleError::new(
1,
format!(
"invalid argument: {} Value too large for defined datatype",
s.quote()
),
)),
},
None => Ok(Box::new(vec![first, second].into_iter().chain(args))),
}
} else {
Err("bad argument encoding".to_owned())
Err(USimpleError::new(1, "bad argument encoding".to_owned()))
}
} else {
Ok(Box::new(vec![first].into_iter()))
@ -190,9 +196,7 @@ struct HeadOptions {
impl HeadOptions {
///Construct options from matches
pub fn get_from(args: impl uucore::Args) -> Result<Self, String> {
let matches = uu_app().get_matches_from(arg_iterate(args)?);
pub fn get_from(matches: &clap::ArgMatches) -> Result<Self, String> {
let mut options = Self::default();
options.quiet = matches.contains_id(options::QUIET_NAME);
@ -200,7 +204,7 @@ impl HeadOptions {
options.zeroed = matches.contains_id(options::ZERO_NAME);
options.presume_input_pipe = matches.contains_id(options::PRESUME_INPUT_PIPE);
options.mode = Mode::from(&matches)?;
options.mode = Mode::from(matches)?;
options.files = match matches.get_many::<String>(options::FILES_NAME) {
Some(v) => v.map(|s| s.to_owned()).collect(),
@ -514,7 +518,8 @@ fn uu_head(options: &HeadOptions) -> UResult<()> {
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let args = match HeadOptions::get_from(args) {
let matches = uu_app().try_get_matches_from(arg_iterate(args)?)?;
let args = match HeadOptions::get_from(&matches) {
Ok(o) => o,
Err(s) => {
return Err(USimpleError::new(1, s));
@ -531,8 +536,10 @@ mod tests {
use super::*;
fn options(args: &str) -> Result<HeadOptions, String> {
let combined = "head ".to_owned() + args;
let args = combined.split_whitespace();
HeadOptions::get_from(args.map(OsString::from))
let args = combined.split_whitespace().map(OsString::from);
let matches = uu_app()
.get_matches_from(arg_iterate(args).map_err(|_| String::from("Arg iterate failed"))?);
HeadOptions::get_from(&matches)
}
#[test]
fn test_args_modes() {
@ -579,7 +586,7 @@ mod tests {
assert_eq!(opts.mode, Mode::FirstLines(10));
assert!(opts.files.is_empty());
}
fn arg_outputs(src: &str) -> Result<String, String> {
fn arg_outputs(src: &str) -> Result<String, ()> {
let split = src.split_whitespace().map(OsString::from);
match arg_iterate(split) {
Ok(args) => {
@ -588,7 +595,7 @@ mod tests {
.collect::<Vec<_>>();
Ok(vec.join(" "))
}
Err(e) => Err(e),
Err(_) => Err(()),
}
}
#[test]

View file

@ -61,7 +61,7 @@ mod wsa {
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().get_matches_from(args);
let matches = uu_app().try_get_matches_from(args)?;
#[cfg(windows)]
let _handle = wsa::start().map_err_context(|| "failed to start Winsock".to_owned())?;

View file

@ -128,7 +128,9 @@ struct State {
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let after_help = get_description();
let matches = uu_app().after_help(&after_help[..]).get_matches_from(args);
let matches = uu_app()
.after_help(&after_help[..])
.try_get_matches_from(args)?;
let users: Vec<String> = matches
.get_many::<String>(options::ARG_USERS)

View file

@ -171,7 +171,7 @@ static ARG_FILES: &str = "files";
///
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().get_matches_from(args);
let matches = uu_app().try_get_matches_from(args)?;
let paths: Vec<String> = matches
.get_many::<String>(ARG_FILES)

View file

@ -602,7 +602,7 @@ impl<'a> State<'a> {
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().get_matches_from(args);
let matches = uu_app().try_get_matches_from(args)?;
let keys = parse_field_number_option(matches.value_of("j"))?;
let key1 = parse_field_number_option(matches.value_of("1"))?;

View file

@ -41,7 +41,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let mut args = args.collect_ignore();
let obs_signal = handle_obsolete(&mut args);
let matches = uu_app().get_matches_from(args);
let matches = uu_app().try_get_matches_from(args)?;
let mode = if matches.contains_id(options::TABLE) {
Mode::Table

View file

@ -22,7 +22,7 @@ pub mod options {
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().get_matches_from(args);
let matches = uu_app().try_get_matches_from(args)?;
let files: Vec<_> = matches
.get_many::<OsString>(options::FILES)

View file

@ -136,7 +136,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
long_usage,
backup_control::BACKUP_CONTROL_LONG_HELP
))
.get_matches_from(args);
.try_get_matches_from(args)?;
/* the list of files */

View file

@ -38,7 +38,7 @@ static ABOUT: &str = "Print user's login name";
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let args = args.collect_ignore();
let _ = uu_app().get_matches_from(args);
let _ = uu_app().try_get_matches_from(args)?;
match get_userlogin() {
Some(userlogin) => println!("{}", userlogin),

View file

@ -96,7 +96,9 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
// Linux-specific options, not implemented
// opts.optflag("Z", "context", "set SELinux security context" +
// " of each created directory to CTX"),
let matches = uu_app().after_help(&after_help[..]).get_matches_from(args);
let matches = uu_app()
.after_help(&after_help[..])
.try_get_matches_from(args)?;
let dirs = matches
.get_many::<OsString>(options::DIRS)

View file

@ -30,7 +30,7 @@ mod options {
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let args = args.collect_ignore();
let matches = uu_app().get_matches_from(args);
let matches = uu_app().try_get_matches_from(args)?;
if matches.contains_id(options::CONTEXT) {
return Err(USimpleError::new(1, "--context is not implemented"));

View file

@ -86,7 +86,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
// opts.optflag("Z", "", "set the SELinux security context to default type");
// opts.optopt("", "context", "like -Z, or if CTX is specified then set the SELinux or SMACK security context to CTX");
let matches = uu_app().get_matches_from(args);
let matches = uu_app().try_get_matches_from(args)?;
let mode = get_mode(&matches).map_err(|e| USimpleError::new(1, e))?;

View file

@ -77,9 +77,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
backup_control::BACKUP_CONTROL_LONG_HELP
);
let mut app = uu_app().after_help(&*help);
let matches = app
.try_get_matches_from_mut(args)
.unwrap_or_else(|e| e.exit());
let matches = app.try_get_matches_from_mut(args)?;
if !matches.contains_id(OPT_TARGET_DIRECTORY)
&& matches

View file

@ -86,7 +86,7 @@ pub mod options {
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let args = args.collect_lossy();
let matches = uu_app().get_matches_from(args);
let matches = uu_app().try_get_matches_from(args)?;
// A mutable settings object, initialized with the defaults.
let mut settings = Settings {

View file

@ -21,7 +21,7 @@ use std::io::Error;
use std::os::unix::prelude::*;
use std::path::{Path, PathBuf};
use uucore::display::Quotable;
use uucore::error::{set_exit_code, UError, UResult};
use uucore::error::{set_exit_code, UClapError, UError, UResult};
use uucore::format_usage;
static ABOUT: &str = "Run COMMAND ignoring hangup signals.";
@ -88,7 +88,7 @@ impl Display for NohupError {
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let args = args.collect_lossy();
let matches = uu_app().get_matches_from(args);
let matches = uu_app().try_get_matches_from(args).with_exit_code(125)?;
replace_fds()?;

View file

@ -32,7 +32,7 @@ const USAGE: &str = "{} [OPTIONS]...";
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().get_matches_from(args);
let matches = uu_app().try_get_matches_from(args)?;
let ignore = match matches.value_of(OPT_IGNORE) {
Some(numstr) => match numstr.trim().parse() {

View file

@ -229,7 +229,7 @@ fn concat_format_arg_and_value(args: &[String]) -> Vec<String> {
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let args = args.collect_ignore();
let matches = uu_app().get_matches_from(concat_format_arg_and_value(&args));
let matches = uu_app().try_get_matches_from(concat_format_arg_and_value(&args))?;
let options = parse_options(&matches).map_err(NumfmtError::IllegalArgument)?;

View file

@ -259,9 +259,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let clap_opts = uu_app();
let clap_matches = clap_opts
.clone() // Clone to reuse clap_opts to print help
.get_matches_from(args.clone());
let clap_matches = clap_opts.try_get_matches_from(&args)?;
let od_options = OdOptions::new(&clap_matches, &args)?;

View file

@ -54,7 +54,7 @@ fn read_until<R: Read>(
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().get_matches_from(args);
let matches = uu_app().try_get_matches_from(args)?;
let serial = matches.contains_id(options::SERIAL);
let delimiters = matches.value_of(options::DELIMITER).unwrap();

View file

@ -41,7 +41,7 @@ const POSIX_NAME_MAX: usize = 14;
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let args = args.collect_lossy();
let matches = uu_app().get_matches_from(args);
let matches = uu_app().try_get_matches_from(args)?;
// set working mode
let is_posix = matches.get_many::<String>(options::POSIX).is_some();

View file

@ -53,7 +53,9 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let after_help = get_long_usage();
let matches = uu_app().after_help(&after_help[..]).get_matches_from(args);
let matches = uu_app()
.after_help(&after_help[..])
.try_get_matches_from(args)?;
let users: Vec<String> = matches
.get_many::<String>(options::USER)

View file

@ -724,8 +724,7 @@ mod options {
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let args = args.collect_ignore();
// let mut opts = Options::new();
let matches = uu_app().get_matches_from(args);
let matches = uu_app().try_get_matches_from(args)?;
let mut input_files: Vec<String> = match &matches.get_many::<String>(options::FILE) {
Some(v) => v.clone().map(|v| v.to_owned()).collect(),

View file

@ -124,7 +124,7 @@ fn logical_path() -> io::Result<PathBuf> {
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().get_matches_from(args);
let matches = uu_app().try_get_matches_from(args)?;
let cwd = if matches.contains_id(OPT_LOGICAL) {
logical_path()
} else {

View file

@ -34,7 +34,7 @@ const ARG_FILES: &str = "files";
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().get_matches_from(args);
let matches = uu_app().try_get_matches_from(args)?;
let mut no_trailing_delimiter = matches.contains_id(OPT_NO_NEWLINE);
let use_zero = matches.contains_id(OPT_ZERO);

View file

@ -81,7 +81,9 @@ fn get_long_usage() -> String {
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let long_usage = get_long_usage();
let matches = uu_app().after_help(&long_usage[..]).get_matches_from(args);
let matches = uu_app()
.after_help(&long_usage[..])
.try_get_matches_from(args)?;
let files: Vec<String> = matches
.get_many::<String>(ARG_FILES)

View file

@ -33,7 +33,7 @@ static ARG_DIRS: &str = "dirs";
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().get_matches_from(args);
let matches = uu_app().try_get_matches_from(args)?;
let opts = Opts {
ignore: matches.contains_id(OPT_IGNORE_FAIL_NON_EMPTY),

View file

@ -59,7 +59,7 @@ type RangeFloat = (ExtendedBigDecimal, ExtendedBigDecimal, ExtendedBigDecimal);
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().get_matches_from(args);
let matches = uu_app().try_get_matches_from(args)?;
let numbers = matches
.get_many::<String>(ARG_NUMBERS)

View file

@ -268,7 +268,7 @@ pub mod options {
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let args = args.collect_ignore();
let matches = uu_app().get_matches_from(args);
let matches = uu_app().try_get_matches_from(args)?;
if !matches.contains_id(options::FILE) {
return Err(UUsageError::new(1, "missing file operand"));

View file

@ -58,7 +58,7 @@ mod options {
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let args = args.collect_lossy();
let matches = uu_app().get_matches_from(args);
let matches = uu_app().try_get_matches_from(args)?;
let mode = if let Some(args) = matches.get_many::<String>(options::ECHO) {
Mode::Echo(args.map(String::from).collect())

View file

@ -53,7 +53,7 @@ const AFTER_HELP: &str = "\
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().get_matches_from(args);
let matches = uu_app().try_get_matches_from(args)?;
match Settings::from(&matches) {
Ok(settings) => split(&settings),
Err(e) if e.requires_usage() => Err(UUsageError::new(1, format!("{}", e))),

View file

@ -985,7 +985,9 @@ for details about the options it supports.
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let long_usage = get_long_usage();
let matches = uu_app().after_help(&long_usage[..]).get_matches_from(args);
let matches = uu_app()
.after_help(&long_usage[..])
.try_get_matches_from(args)?;
let stater = Stater::new(&matches)?;
let exit_status = stater.exec();

View file

@ -158,7 +158,7 @@ fn get_preload_env(tmp_dir: &mut TempDir) -> io::Result<(String, PathBuf)> {
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let args = args.collect_ignore();
let matches = uu_app().get_matches_from(args);
let matches = uu_app().try_get_matches_from(args)?;
let options = ProgramOptions::try_from(&matches).map_err(|e| UUsageError::new(125, e.0))?;

View file

@ -139,7 +139,7 @@ ioctl_write_ptr_bad!(
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let args = args.collect_lossy();
let matches = uu_app().get_matches_from(args);
let matches = uu_app().try_get_matches_from(args)?;
let opts = Options::from(&matches)?;

View file

@ -111,7 +111,7 @@ mod options {
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let args = args.collect_lossy();
let matches = uu_app().get_matches_from(args);
let matches = uu_app().try_get_matches_from(args)?;
let files: Vec<String> = match matches.get_many::<String>(options::FILE) {
Some(v) => v.clone().map(|v| v.to_owned()).collect(),

View file

@ -162,7 +162,7 @@ mod platform {
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().get_matches_from(args);
let matches = uu_app().try_get_matches_from(args)?;
let files: Vec<String> = matches
.get_many::<String>(ARG_FILES)

View file

@ -38,7 +38,7 @@ mod options {
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let args = args.collect_lossy();
let matches = uu_app().get_matches_from(args);
let matches = uu_app().try_get_matches_from(args)?;
let before = matches.contains_id(options::BEFORE);
let regex = matches.contains_id(options::REGEX);

View file

@ -295,7 +295,7 @@ impl Settings {
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().get_matches_from(arg_iterate(args)?);
let matches = uu_app().try_get_matches_from(arg_iterate(args)?)?;
let mut settings = Settings::from(&matches)?;
// skip expensive call to fstat if PRESUME_INPUT_PIPE is selected

View file

@ -51,7 +51,7 @@ enum OutputErrorMode {
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().get_matches_from(args);
let matches = uu_app().try_get_matches_from(args)?;
let options = Options {
append: matches.contains_id(options::APPEND),

View file

@ -19,7 +19,7 @@ use std::io::ErrorKind;
use std::process::{self, Child, Stdio};
use std::time::Duration;
use uucore::display::Quotable;
use uucore::error::{UResult, USimpleError, UUsageError};
use uucore::error::{UClapError, UResult, USimpleError, UUsageError};
use uucore::format_usage;
use uucore::process::ChildExt;
use uucore::signals::{signal_by_name_or_value, signal_name_by_value};
@ -108,9 +108,7 @@ impl Config {
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let args = args.collect_lossy();
let command = uu_app();
let matches = command.get_matches_from(args);
let matches = uu_app().try_get_matches_from(args).with_exit_code(125)?;
let config = Config::from(&matches)?;
timeout(

View file

@ -69,7 +69,7 @@ fn dt_to_filename(tm: time::PrimitiveDateTime) -> FileTime {
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().get_matches_from(args);
let matches = uu_app().try_get_matches_from(args)?;
let files = matches.get_many::<OsString>(ARG_FILES).ok_or_else(|| {
USimpleError::new(

View file

@ -44,7 +44,9 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let after_help = get_long_usage();
let matches = uu_app().after_help(&after_help[..]).get_matches_from(args);
let matches = uu_app()
.after_help(&after_help[..])
.try_get_matches_from(args)?;
let delete_flag = matches.contains_id(options::DELETE);
let complement_flag = matches.contains_id(options::COMPLEMENT);

View file

@ -27,7 +27,7 @@ mod options {
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let args = args.collect_lossy();
let matches = uu_app().get_matches_from(args);
let matches = uu_app().try_get_matches_from(args)?;
let input = matches
.value_of(options::FILE)

View file

@ -56,7 +56,7 @@ const HOST_OS: &str = "Redox";
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().get_matches_from(args);
let matches = uu_app().try_get_matches_from(args)?;
let uname =
PlatformInfo::new().map_err_context(|| "failed to create PlatformInfo".to_string())?;

View file

@ -167,7 +167,7 @@ fn expand_shortcuts(args: &[String]) -> Vec<String> {
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let args = args.collect_ignore();
let matches = uu_app().get_matches_from(expand_shortcuts(&args));
let matches = uu_app().try_get_matches_from(expand_shortcuts(&args))?;
unexpand(&Options::new(&matches)?).map_err_context(String::new)
}

View file

@ -257,7 +257,9 @@ fn get_long_usage() -> String {
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let long_usage = get_long_usage();
let matches = uu_app().after_help(&long_usage[..]).get_matches_from(args);
let matches = uu_app()
.after_help(&long_usage[..])
.try_get_matches_from(args)?;
let files: Vec<String> = matches
.get_many::<String>(ARG_FILES)

View file

@ -22,7 +22,7 @@ static OPT_PATH: &str = "FILE";
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().get_matches_from(args);
let matches = uu_app().try_get_matches_from(args)?;
let path: &Path = matches.get_one::<OsString>(OPT_PATH).unwrap().as_ref();

View file

@ -36,7 +36,7 @@ extern "C" {
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().get_matches_from(args);
let matches = uu_app().try_get_matches_from(args)?;
let (boot_time, user_count) = process_utmpx();
let uptime = get_uptime(boot_time);

View file

@ -33,7 +33,9 @@ If FILE is not specified, use {}. /var/log/wtmp as FILE is common.",
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let after_help = get_long_usage();
let matches = uu_app().after_help(&after_help[..]).get_matches_from(args);
let matches = uu_app()
.after_help(&after_help[..])
.try_get_matches_from(args)?;
let files: Vec<&Path> = matches
.get_many::<OsString>(ARG_FILES)

View file

@ -196,7 +196,7 @@ impl Display for WcError {
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().get_matches_from(args);
let matches = uu_app().try_get_matches_from(args)?;
let inputs = inputs(&matches)?;

View file

@ -60,7 +60,9 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let after_help = get_long_usage();
let matches = uu_app().after_help(&after_help[..]).get_matches_from(args);
let matches = uu_app()
.after_help(&after_help[..])
.try_get_matches_from(args)?;
let files: Vec<String> = matches
.get_many::<String>(options::FILE)

View file

@ -21,7 +21,7 @@ static ABOUT: &str = "Print the current username.";
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
uu_app().get_matches_from(args);
uu_app().try_get_matches_from(args)?;
let username = platform::get_username().map_err_context(|| "failed to get username".into())?;
println_verbatim(&username).map_err_context(|| "failed to print username".into())?;
Ok(())

View file

@ -26,7 +26,7 @@ const BUF_SIZE: usize = 16 * 1024;
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().get_matches_from(args);
let matches = uu_app().try_get_matches_from(args)?;
let string = if let Some(values) = matches.get_many::<String>("STRING") {
let mut result = values.fold(String::new(), |res, s| res + s + " ");

View file

@ -463,7 +463,7 @@ pub fn chown_base<'a>(
.required(true)
.min_values(1),
);
let matches = command.get_matches_from(args);
let matches = command.try_get_matches_from(args)?;
let files: Vec<String> = matches
.get_many::<String>(options::ARG_FILES)