From c32e730a1f0f0625158571dd528cde7519515f81 Mon Sep 17 00:00:00 2001 From: Terts Diepraam Date: Fri, 15 Dec 2023 14:38:27 +0100 Subject: [PATCH] all: remove collect_{lossy,ignore} calls where possible --- src/uu/base32/src/base_common.rs | 3 +-- src/uu/cat/src/cat.rs | 2 -- src/uu/chroot/src/chroot.rs | 2 -- src/uu/cksum/src/cksum.rs | 2 -- src/uu/comm/src/comm.rs | 2 -- src/uu/csplit/src/csplit.rs | 2 -- src/uu/dd/src/dd.rs | 2 -- src/uu/dircolors/src/dircolors.rs | 2 -- src/uu/dirname/src/dirname.rs | 2 -- src/uu/du/src/du.rs | 2 -- src/uu/echo/src/echo.rs | 1 - src/uu/expr/src/expr.rs | 2 -- src/uu/logname/src/logname.rs | 2 -- src/uu/mkfifo/src/mkfifo.rs | 2 -- src/uu/mknod/src/mknod.rs | 1 - src/uu/mktemp/src/mktemp.rs | 6 +++--- src/uu/more/src/more.rs | 1 - src/uu/nl/src/nl.rs | 2 -- src/uu/nohup/src/nohup.rs | 2 -- src/uu/pathchk/src/pathchk.rs | 2 -- src/uu/pinky/src/pinky.rs | 2 -- src/uu/printf/src/printf.rs | 1 - src/uu/ptx/src/ptx.rs | 2 -- src/uu/shred/src/shred.rs | 2 -- src/uu/shuf/src/shuf.rs | 2 -- src/uu/sort/src/sort.rs | 1 - src/uu/stdbuf/src/stdbuf.rs | 2 -- src/uu/stty/src/stty.rs | 2 -- src/uu/sum/src/sum.rs | 2 -- src/uu/tac/src/tac.rs | 2 -- src/uu/timeout/src/timeout.rs | 2 -- src/uu/tr/src/tr.rs | 2 -- src/uu/tsort/src/tsort.rs | 2 -- src/uu/who/src/who.rs | 2 -- 34 files changed, 4 insertions(+), 64 deletions(-) diff --git a/src/uu/base32/src/base_common.rs b/src/uu/base32/src/base_common.rs index 74c3dc808..2112a40ea 100644 --- a/src/uu/base32/src/base_common.rs +++ b/src/uu/base32/src/base_common.rs @@ -87,8 +87,7 @@ pub fn parse_base_cmd_args( usage: &str, ) -> UResult { let command = base_app(about, usage); - let arg_list = args.collect_lossy(); - Config::from(&command.try_get_matches_from(arg_list)?) + Config::from(&command.try_get_matches_from(args)?) } pub fn base_app(about: &'static str, usage: &str) -> Command { diff --git a/src/uu/cat/src/cat.rs b/src/uu/cat/src/cat.rs index 34eb26512..8aaecb8c1 100644 --- a/src/uu/cat/src/cat.rs +++ b/src/uu/cat/src/cat.rs @@ -174,8 +174,6 @@ mod options { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args.collect_ignore(); - let matches = uu_app().try_get_matches_from(args)?; let number_mode = if matches.get_flag(options::NUMBER_NONBLANK) { diff --git a/src/uu/chroot/src/chroot.rs b/src/uu/chroot/src/chroot.rs index 6366775c3..9ea861d46 100644 --- a/src/uu/chroot/src/chroot.rs +++ b/src/uu/chroot/src/chroot.rs @@ -33,8 +33,6 @@ mod options { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args.collect_lossy(); - let matches = uu_app().try_get_matches_from(args).with_exit_code(125)?; let default_shell: &'static str = "/bin/sh"; diff --git a/src/uu/cksum/src/cksum.rs b/src/uu/cksum/src/cksum.rs index 629bb457f..245760409 100644 --- a/src/uu/cksum/src/cksum.rs +++ b/src/uu/cksum/src/cksum.rs @@ -221,8 +221,6 @@ mod options { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args.collect_ignore(); - let matches = uu_app().try_get_matches_from(args)?; let algo_name: &str = match matches.get_one::(options::ALGORITHM) { diff --git a/src/uu/comm/src/comm.rs b/src/uu/comm/src/comm.rs index e6977142e..dd49ef53b 100644 --- a/src/uu/comm/src/comm.rs +++ b/src/uu/comm/src/comm.rs @@ -145,8 +145,6 @@ fn open_file(name: &str, line_ending: LineEnding) -> io::Result { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args.collect_lossy(); - let matches = uu_app().try_get_matches_from(args)?; let line_ending = LineEnding::from_zero_flag(matches.get_flag(options::ZERO_TERMINATED)); let filename1 = matches.get_one::(options::FILE_1).unwrap(); diff --git a/src/uu/csplit/src/csplit.rs b/src/uu/csplit/src/csplit.rs index d33be1a5d..00bebbf4d 100644 --- a/src/uu/csplit/src/csplit.rs +++ b/src/uu/csplit/src/csplit.rs @@ -552,8 +552,6 @@ where #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args.collect_ignore(); - let matches = uu_app().try_get_matches_from(args)?; // get the file to split diff --git a/src/uu/dd/src/dd.rs b/src/uu/dd/src/dd.rs index b721d1d72..e849fcd2a 100644 --- a/src/uu/dd/src/dd.rs +++ b/src/uu/dd/src/dd.rs @@ -1267,8 +1267,6 @@ fn is_fifo(filename: &str) -> bool { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args.collect_ignore(); - let matches = uu_app().try_get_matches_from(args)?; let settings: Settings = Parser::new().parse( diff --git a/src/uu/dircolors/src/dircolors.rs b/src/uu/dircolors/src/dircolors.rs index ecca9d160..531c3ee47 100644 --- a/src/uu/dircolors/src/dircolors.rs +++ b/src/uu/dircolors/src/dircolors.rs @@ -129,8 +129,6 @@ fn generate_ls_colors(fmt: &OutputFmt, sep: &str) -> String { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args.collect_ignore(); - let matches = uu_app().try_get_matches_from(args)?; let files = matches diff --git a/src/uu/dirname/src/dirname.rs b/src/uu/dirname/src/dirname.rs index 51935cb7f..a645b05fd 100644 --- a/src/uu/dirname/src/dirname.rs +++ b/src/uu/dirname/src/dirname.rs @@ -21,8 +21,6 @@ mod options { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args.collect_lossy(); - let matches = uu_app().after_help(AFTER_HELP).try_get_matches_from(args)?; let line_ending = LineEnding::from_zero_flag(matches.get_flag(options::ZERO)); diff --git a/src/uu/du/src/du.rs b/src/uu/du/src/du.rs index 7114ccc26..1213e004f 100644 --- a/src/uu/du/src/du.rs +++ b/src/uu/du/src/du.rs @@ -590,8 +590,6 @@ pub fn div_ceil(a: u64, b: u64) -> u64 { #[uucore::main] #[allow(clippy::cognitive_complexity)] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args.collect_ignore(); - let matches = uu_app().try_get_matches_from(args)?; let summarize = matches.get_flag(options::SUMMARIZE); diff --git a/src/uu/echo/src/echo.rs b/src/uu/echo/src/echo.rs index b3707b6f8..522cb0c94 100644 --- a/src/uu/echo/src/echo.rs +++ b/src/uu/echo/src/echo.rs @@ -118,7 +118,6 @@ fn print_escaped(input: &str, mut output: impl Write) -> io::Result UResult<()> { - let args = args.collect_lossy(); let matches = uu_app().get_matches_from(args); let no_newline = matches.get_flag(options::NO_NEWLINE); diff --git a/src/uu/expr/src/expr.rs b/src/uu/expr/src/expr.rs index c271f0935..1e19b6e12 100644 --- a/src/uu/expr/src/expr.rs +++ b/src/uu/expr/src/expr.rs @@ -98,8 +98,6 @@ pub fn uu_app() -> Command { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args.collect_lossy(); - // For expr utility we do not want getopts. // The following usage should work without escaping hyphens: `expr -15 = 1 + 2 \* \( 3 - -4 \)` let matches = uu_app().try_get_matches_from(args)?; diff --git a/src/uu/logname/src/logname.rs b/src/uu/logname/src/logname.rs index 55d4fec75..02a78cf4c 100644 --- a/src/uu/logname/src/logname.rs +++ b/src/uu/logname/src/logname.rs @@ -30,8 +30,6 @@ const USAGE: &str = help_usage!("logname.md"); #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args.collect_ignore(); - let _ = uu_app().try_get_matches_from(args)?; match get_userlogin() { diff --git a/src/uu/mkfifo/src/mkfifo.rs b/src/uu/mkfifo/src/mkfifo.rs index 39d112739..9320f76ed 100644 --- a/src/uu/mkfifo/src/mkfifo.rs +++ b/src/uu/mkfifo/src/mkfifo.rs @@ -22,8 +22,6 @@ mod options { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args.collect_ignore(); - let matches = uu_app().try_get_matches_from(args)?; if matches.contains_id(options::CONTEXT) { diff --git a/src/uu/mknod/src/mknod.rs b/src/uu/mknod/src/mknod.rs index ceafd235b..15a0fdacd 100644 --- a/src/uu/mknod/src/mknod.rs +++ b/src/uu/mknod/src/mknod.rs @@ -68,7 +68,6 @@ fn _mknod(file_name: &str, mode: mode_t, dev: dev_t) -> i32 { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args.collect_ignore(); // Linux-specific options, not implemented // 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"); diff --git a/src/uu/mktemp/src/mktemp.rs b/src/uu/mktemp/src/mktemp.rs index d52351a89..ae44225c9 100644 --- a/src/uu/mktemp/src/mktemp.rs +++ b/src/uu/mktemp/src/mktemp.rs @@ -12,6 +12,7 @@ use uucore::{format_usage, help_about, help_usage}; use std::env; use std::error::Error; +use std::ffi::OsStr; use std::fmt::Display; use std::io::ErrorKind; use std::iter; @@ -308,8 +309,7 @@ impl Params { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args.collect_lossy(); - + let args: Vec<_> = args.collect(); let matches = match uu_app().try_get_matches_from(&args) { Ok(m) => m, Err(e) => { @@ -333,7 +333,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { // If POSIXLY_CORRECT was set, template MUST be the last argument. if matches.contains_id(ARG_TEMPLATE) { // Template argument was provided, check if was the last one. - if args.last().unwrap() != &options.template { + if args.last().unwrap() != OsStr::new(&options.template) { return Err(Box::new(MkTempError::TooManyTemplates)); } } diff --git a/src/uu/more/src/more.rs b/src/uu/more/src/more.rs index b21b2ab1f..f651a033b 100644 --- a/src/uu/more/src/more.rs +++ b/src/uu/more/src/more.rs @@ -87,7 +87,6 @@ impl Options { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args.collect_lossy(); let matches = match uu_app().try_get_matches_from(args) { Ok(m) => m, Err(e) => return Err(e.into()), diff --git a/src/uu/nl/src/nl.rs b/src/uu/nl/src/nl.rs index eaf27f3b6..7d7688650 100644 --- a/src/uu/nl/src/nl.rs +++ b/src/uu/nl/src/nl.rs @@ -178,8 +178,6 @@ pub mod options { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args.collect_lossy(); - let matches = uu_app().try_get_matches_from(args)?; let mut settings = Settings::default(); diff --git a/src/uu/nohup/src/nohup.rs b/src/uu/nohup/src/nohup.rs index c64f7bf71..602cb7ca7 100644 --- a/src/uu/nohup/src/nohup.rs +++ b/src/uu/nohup/src/nohup.rs @@ -74,8 +74,6 @@ impl Display for NohupError { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args.collect_lossy(); - let matches = uu_app().try_get_matches_from(args).with_exit_code(125)?; replace_fds()?; diff --git a/src/uu/pathchk/src/pathchk.rs b/src/uu/pathchk/src/pathchk.rs index 81c352088..ffb214e2e 100644 --- a/src/uu/pathchk/src/pathchk.rs +++ b/src/uu/pathchk/src/pathchk.rs @@ -36,8 +36,6 @@ const POSIX_NAME_MAX: usize = 14; #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args.collect_lossy(); - let matches = uu_app().try_get_matches_from(args)?; // set working mode diff --git a/src/uu/pinky/src/pinky.rs b/src/uu/pinky/src/pinky.rs index 8ac8f6c84..02161cb36 100644 --- a/src/uu/pinky/src/pinky.rs +++ b/src/uu/pinky/src/pinky.rs @@ -47,8 +47,6 @@ fn get_long_usage() -> String { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args.collect_ignore(); - let matches = uu_app() .after_help(get_long_usage()) .try_get_matches_from(args)?; diff --git a/src/uu/printf/src/printf.rs b/src/uu/printf/src/printf.rs index 663411b89..ad42e3894 100644 --- a/src/uu/printf/src/printf.rs +++ b/src/uu/printf/src/printf.rs @@ -27,7 +27,6 @@ mod options { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args.collect_ignore(); let matches = uu_app().get_matches_from(args); let format_string = matches diff --git a/src/uu/ptx/src/ptx.rs b/src/uu/ptx/src/ptx.rs index 6dd2b2992..7caa8f4a5 100644 --- a/src/uu/ptx/src/ptx.rs +++ b/src/uu/ptx/src/ptx.rs @@ -715,8 +715,6 @@ mod options { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args.collect_ignore(); - let matches = uu_app().try_get_matches_from(args)?; let mut input_files: Vec = match &matches.get_many::(options::FILE) { diff --git a/src/uu/shred/src/shred.rs b/src/uu/shred/src/shred.rs index 711fd0485..d4209aa3a 100644 --- a/src/uu/shred/src/shred.rs +++ b/src/uu/shred/src/shred.rs @@ -200,8 +200,6 @@ impl BytesWriter { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args.collect_ignore(); - let matches = uu_app().try_get_matches_from(args)?; if !matches.contains_id(options::FILE) { diff --git a/src/uu/shuf/src/shuf.rs b/src/uu/shuf/src/shuf.rs index 8c636f1cb..de302435c 100644 --- a/src/uu/shuf/src/shuf.rs +++ b/src/uu/shuf/src/shuf.rs @@ -47,8 +47,6 @@ mod options { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args.collect_lossy(); - let matches = uu_app().try_get_matches_from(args)?; let mode = if let Some(args) = matches.get_many::(options::ECHO) { diff --git a/src/uu/sort/src/sort.rs b/src/uu/sort/src/sort.rs index 4e6e84187..bc331915b 100644 --- a/src/uu/sort/src/sort.rs +++ b/src/uu/sort/src/sort.rs @@ -1029,7 +1029,6 @@ fn make_sort_mode_arg(mode: &'static str, short: char, help: &'static str) -> Ar #[uucore::main] #[allow(clippy::cognitive_complexity)] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args.collect_ignore(); let mut settings = GlobalSettings::default(); let matches = match uu_app().try_get_matches_from(args) { diff --git a/src/uu/stdbuf/src/stdbuf.rs b/src/uu/stdbuf/src/stdbuf.rs index 38c4451ca..2436274e7 100644 --- a/src/uu/stdbuf/src/stdbuf.rs +++ b/src/uu/stdbuf/src/stdbuf.rs @@ -141,8 +141,6 @@ fn get_preload_env(tmp_dir: &TempDir) -> UResult<(String, PathBuf)> { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args.collect_ignore(); - let matches = uu_app().try_get_matches_from(args)?; let options = ProgramOptions::try_from(&matches).map_err(|e| UUsageError::new(125, e.0))?; diff --git a/src/uu/stty/src/stty.rs b/src/uu/stty/src/stty.rs index 669285750..5a5c31f5e 100644 --- a/src/uu/stty/src/stty.rs +++ b/src/uu/stty/src/stty.rs @@ -176,8 +176,6 @@ ioctl_write_ptr_bad!( #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args.collect_lossy(); - let matches = uu_app().try_get_matches_from(args)?; let opts = Options::from(&matches)?; diff --git a/src/uu/sum/src/sum.rs b/src/uu/sum/src/sum.rs index 38ad3964e..d1f383351 100644 --- a/src/uu/sum/src/sum.rs +++ b/src/uu/sum/src/sum.rs @@ -102,8 +102,6 @@ mod options { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args.collect_lossy(); - let matches = uu_app().try_get_matches_from(args)?; let files: Vec = match matches.get_many::(options::FILE) { diff --git a/src/uu/tac/src/tac.rs b/src/uu/tac/src/tac.rs index b8cb61029..3865c61ae 100644 --- a/src/uu/tac/src/tac.rs +++ b/src/uu/tac/src/tac.rs @@ -33,8 +33,6 @@ mod options { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args.collect_lossy(); - let matches = uu_app().try_get_matches_from(args)?; let before = matches.get_flag(options::BEFORE); diff --git a/src/uu/timeout/src/timeout.rs b/src/uu/timeout/src/timeout.rs index 5e73fe2ab..958bc647e 100644 --- a/src/uu/timeout/src/timeout.rs +++ b/src/uu/timeout/src/timeout.rs @@ -107,8 +107,6 @@ impl Config { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args.collect_lossy(); - let matches = uu_app().try_get_matches_from(args).with_exit_code(125)?; let config = Config::from(&matches)?; diff --git a/src/uu/tr/src/tr.rs b/src/uu/tr/src/tr.rs index 9c6e7a7da..010228260 100644 --- a/src/uu/tr/src/tr.rs +++ b/src/uu/tr/src/tr.rs @@ -33,8 +33,6 @@ mod options { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args.collect_lossy(); - let matches = uu_app().after_help(AFTER_HELP).try_get_matches_from(args)?; let delete_flag = matches.get_flag(options::DELETE); diff --git a/src/uu/tsort/src/tsort.rs b/src/uu/tsort/src/tsort.rs index e71710847..3ae4f4f97 100644 --- a/src/uu/tsort/src/tsort.rs +++ b/src/uu/tsort/src/tsort.rs @@ -20,8 +20,6 @@ mod options { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args.collect_lossy(); - let matches = uu_app().try_get_matches_from(args)?; let input = matches diff --git a/src/uu/who/src/who.rs b/src/uu/who/src/who.rs index 5d952efff..788368aaf 100644 --- a/src/uu/who/src/who.rs +++ b/src/uu/who/src/who.rs @@ -54,8 +54,6 @@ fn get_long_usage() -> String { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args.collect_ignore(); - let matches = uu_app() .after_help(get_long_usage()) .try_get_matches_from(args)?;