Merge pull request #5649 from tertsdiepraam/remove-collect-lossy-and-ignore

all: remove `collect_{lossy,ignore}` calls where possible
This commit is contained in:
Daniel Hofstetter 2023-12-15 16:30:08 +01:00 committed by GitHub
commit 88428cf5d7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
34 changed files with 4 additions and 64 deletions

View file

@ -87,8 +87,7 @@ pub fn parse_base_cmd_args(
usage: &str,
) -> UResult<Config> {
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 {

View file

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

View file

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

View file

@ -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::<String>(options::ALGORITHM) {

View file

@ -145,8 +145,6 @@ fn open_file(name: &str, line_ending: LineEnding) -> io::Result<LineReader> {
#[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::<String>(options::FILE_1).unwrap();

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -118,7 +118,6 @@ fn print_escaped(input: &str, mut output: impl Write) -> io::Result<ControlFlow<
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let args = args.collect_lossy();
let matches = uu_app().get_matches_from(args);
let no_newline = matches.get_flag(options::NO_NEWLINE);

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -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()?;

View file

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

View file

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

View file

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

View file

@ -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<String> = match &matches.get_many::<String>(options::FILE) {

View file

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

View file

@ -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::<String>(options::ECHO) {

View file

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

View file

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

View file

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

View file

@ -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<String> = match matches.get_many::<String>(options::FILE) {

View file

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

View file

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

View file

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

View file

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

View file

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