diff --git a/build.rs b/build.rs index 5a9ce3cd5..625a3ccc8 100644 --- a/build.rs +++ b/build.rs @@ -43,10 +43,10 @@ pub fn main() { let mut tf = File::create(Path::new(&out_dir).join("test_modules.rs")).unwrap(); mf.write_all( - "type UtilityMap = HashMap<&'static str, fn(Vec) -> i32>;\n\ + "type UtilityMap = HashMap<&'static str, fn(T) -> i32>;\n\ \n\ - fn util_map() -> UtilityMap {\n\ - \tlet mut map: UtilityMap = HashMap::new();\n\ + fn util_map() -> UtilityMap {\n\ + \tlet mut map = UtilityMap::new();\n\ " .as_bytes(), ) diff --git a/src/bin/coreutils.rs b/src/bin/coreutils.rs index f76628520..4647ce962 100644 --- a/src/bin/coreutils.rs +++ b/src/bin/coreutils.rs @@ -5,108 +5,112 @@ // For the full copyright and license information, please view the LICENSE // file that was distributed with this source code. -extern crate lazy_static; extern crate textwrap; extern crate uucore; -use lazy_static::lazy_static; +use std::cmp; use std::collections::hash_map::HashMap; -use std::io::Write; +use std::ffi::OsString; +use std::io::{self, Write}; +use std::path::{Path, PathBuf}; +use std::process; -static VERSION: &str = env!("CARGO_PKG_VERSION"); - -lazy_static! { - static ref BINARY_PATH: std::path::PathBuf = { - // support symlinks by using args[0], when possible, with fallback to current_exe() - match std::env::args().next() { - Some(ref s) if !s.is_empty() => std::path::PathBuf::from(s), - _ => std::env::current_exe().unwrap(), - } - }; - static ref NAME: &'static str = &*BINARY_PATH.file_stem().unwrap().to_str().unwrap(); -} +const VERSION: &str = env!("CARGO_PKG_VERSION"); include!(concat!(env!("OUT_DIR"), "/uutils_map.rs")); -fn usage(utils: &UtilityMap) { - println!("{} {} (multi-call binary)\n", *NAME, VERSION); - println!("Usage: {} [function [arguments...]]\n", *NAME); +fn usage(utils: &UtilityMap, name: &str) { + println!("{} {} (multi-call binary)\n", name, VERSION); + println!("Usage: {} [function [arguments...]]\n", name); println!("Currently defined functions/utilities:\n"); #[allow(clippy::map_clone)] let mut utils: Vec<&str> = utils.keys().map(|&s| s).collect(); utils.sort(); let display_list = utils.join(", "); - let width = std::cmp::min(textwrap::termwidth(), 100) - 4 * 2; // (opinion/heuristic) max 100 chars wide with 4 character side indentions + let width = cmp::min(textwrap::termwidth(), 100) - 4 * 2; // (opinion/heuristic) max 100 chars wide with 4 character side indentions println!( "{}", textwrap::indent(&textwrap::fill(&display_list, width), " ") ); } +fn binary_path(args: &mut impl Iterator) -> PathBuf { + match args.next() { + Some(s) if !s.is_empty() => PathBuf::from(s), + _ => std::env::current_exe().unwrap(), + } +} + +fn name(binary_path: &Path) -> &str { + binary_path.file_stem().unwrap().to_str().unwrap() +} + fn main() { uucore::panic::mute_sigpipe_panic(); let utils = util_map(); - let mut args: Vec = uucore::args().collect(); + let mut args = uucore::args_os(); - let binary = &BINARY_PATH; - let binary_as_util = binary.file_stem().unwrap().to_str().unwrap(); + let binary = binary_path(&mut args); + let binary_as_util = name(&binary); // binary name equals util name? if let Some(&uumain) = utils.get(binary_as_util) { - std::process::exit(uumain(args)); + process::exit(uumain((vec![binary.into()].into_iter()).chain(args))); } // binary name equals prefixed util name? // * prefix/stem may be any string ending in a non-alphanumeric character - if let Some(util) = utils.keys().find(|util| { - binary_as_util.ends_with(*util) - && !(&binary_as_util[..binary_as_util.len() - (*util).len()]) - .ends_with(char::is_alphanumeric) - }) { - // prefixed util => replace 0th (aka, executable name) argument - args[0] = (*util).to_owned(); - } else { - // unmatched binary name => regard as multi-binary container and advance argument list - args.remove(0); - } + let utilname = + if let Some(util) = utils.keys().find(|util| { + binary_as_util.ends_with(*util) + && !(&binary_as_util[..binary_as_util.len() - (*util).len()]) + .ends_with(char::is_alphanumeric) + }) { + // prefixed util => replace 0th (aka, executable name) argument + Some(OsString::from(*util)) + } else { + // unmatched binary name => regard as multi-binary container and advance argument list + args.next() + }; // 0th argument equals util name? - if !args.is_empty() { - let util = &args[0][..]; + if let Some(util_os) = utilname { + let util = util_os.as_os_str().to_string_lossy(); - match utils.get(util) { + match utils.get(&util[..]) { Some(&uumain) => { - std::process::exit(uumain(args.clone())); + process::exit(uumain((vec![util_os].into_iter()).chain(args))); } None => { - if &args[0][..] == "--help" || &args[0][..] == "-h" { + if util == "--help" || util == "-h" { // see if they want help on a specific util - if args.len() >= 2 { - let util = &args[1][..]; - match utils.get(util) { + if let Some(util_os) = args.next() { + let util = util_os.as_os_str().to_string_lossy(); + + match utils.get(&util[..]) { Some(&uumain) => { - let code = uumain(vec![util.to_owned(), "--help".to_owned()]); - std::io::stdout().flush().expect("could not flush stdout"); - std::process::exit(code); + let code = uumain((vec![util_os, OsString::from("--help")].into_iter()).chain(args)); + io::stdout().flush().expect("could not flush stdout"); + process::exit(code); } None => { println!("{}: function/utility not found", util); - std::process::exit(1); + process::exit(1); } } } - usage(&utils); - std::process::exit(0); + usage(&utils, binary_as_util); + process::exit(0); } else { println!("{}: function/utility not found", util); - std::process::exit(1); + process::exit(1); } } } } else { // no arguments provided - usage(&utils); - std::process::exit(0); + usage(&utils, binary_as_util); + process::exit(0); } } diff --git a/src/uu/arch/src/arch.rs b/src/uu/arch/src/arch.rs index 69747add2..20c278942 100644 --- a/src/uu/arch/src/arch.rs +++ b/src/uu/arch/src/arch.rs @@ -16,8 +16,8 @@ static SYNTAX: &str = "Display machine architecture"; static SUMMARY: &str = "Determine architecture name for current machine."; static LONG_HELP: &str = ""; -pub fn uumain(args: Vec) -> i32 { - app!(SYNTAX, SUMMARY, LONG_HELP).parse(args); +pub fn uumain(args: impl uucore::Args) -> i32 { + app!(SYNTAX, SUMMARY, LONG_HELP).parse(args.collect_str()); let uts = return_if_err!(1, PlatformInfo::new()); println!("{}", uts.machine().trim()); 0 diff --git a/src/uu/base32/src/base32.rs b/src/uu/base32/src/base32.rs index f98a7814f..0bfb12c69 100644 --- a/src/uu/base32/src/base32.rs +++ b/src/uu/base32/src/base32.rs @@ -23,6 +23,6 @@ static LONG_HELP: &str = " encoded stream. "; -pub fn uumain(args: Vec) -> i32 { - base_common::execute(args, SYNTAX, SUMMARY, LONG_HELP, Format::Base32) +pub fn uumain(args: impl uucore::Args) -> i32 { + base_common::execute(args.collect_str(), SYNTAX, SUMMARY, LONG_HELP, Format::Base32) } diff --git a/src/uu/base64/src/base64.rs b/src/uu/base64/src/base64.rs index 595e2ece7..da982f391 100644 --- a/src/uu/base64/src/base64.rs +++ b/src/uu/base64/src/base64.rs @@ -24,6 +24,6 @@ static LONG_HELP: &str = " encoded stream. "; -pub fn uumain(args: Vec) -> i32 { - base_common::execute(args, SYNTAX, SUMMARY, LONG_HELP, Format::Base64) +pub fn uumain(args: impl uucore::Args) -> i32 { + base_common::execute(args.collect_str(), SYNTAX, SUMMARY, LONG_HELP, Format::Base64) } diff --git a/src/uu/basename/src/basename.rs b/src/uu/basename/src/basename.rs index 55995ad4f..84521bdd1 100644 --- a/src/uu/basename/src/basename.rs +++ b/src/uu/basename/src/basename.rs @@ -18,7 +18,9 @@ static SUMMARY: &str = "Print NAME with any leading directory components removed If specified, also remove a trailing SUFFIX"; static LONG_HELP: &str = ""; -pub fn uumain(args: Vec) -> i32 { +pub fn uumain(args: impl uucore::Args) -> i32 { + let args = args.collect_str(); + // // Argument parsing // diff --git a/src/uu/cat/src/cat.rs b/src/uu/cat/src/cat.rs index f207dae1e..0b4cd0530 100644 --- a/src/uu/cat/src/cat.rs +++ b/src/uu/cat/src/cat.rs @@ -124,7 +124,9 @@ enum InputType { type CatResult = Result; -pub fn uumain(args: Vec) -> i32 { +pub fn uumain(args: impl uucore::Args) -> i32 { + let args = args.collect_str(); + let matches = app!(SYNTAX, SUMMARY, LONG_HELP) .optflag("A", "show-all", "equivalent to -vET") .optflag( diff --git a/src/uu/chgrp/src/chgrp.rs b/src/uu/chgrp/src/chgrp.rs index f381bcbb3..e60efa0c6 100644 --- a/src/uu/chgrp/src/chgrp.rs +++ b/src/uu/chgrp/src/chgrp.rs @@ -36,7 +36,9 @@ const FTS_COMFOLLOW: u8 = 1; const FTS_PHYSICAL: u8 = 1 << 1; const FTS_LOGICAL: u8 = 1 << 2; -pub fn uumain(args: Vec) -> i32 { +pub fn uumain(args: impl uucore::Args) -> i32 { + let args = args.collect_str(); + let mut opts = app!(SYNTAX, SUMMARY, ""); opts.optflag("c", "changes", diff --git a/src/uu/chmod/src/chmod.rs b/src/uu/chmod/src/chmod.rs index 77a56c071..ce3c3dd96 100644 --- a/src/uu/chmod/src/chmod.rs +++ b/src/uu/chmod/src/chmod.rs @@ -29,7 +29,9 @@ static LONG_HELP: &str = " Each MODE is of the form '[ugoa]*([-+=]([rwxXst]*|[ugo]))+|[-+=]?[0-7]+'. "; -pub fn uumain(mut args: Vec) -> i32 { +pub fn uumain(args: impl uucore::Args) -> i32 { + let mut args = args.collect_str(); + let syntax = format!( "[OPTION]... MODE[,MODE]... FILE... {0} [OPTION]... OCTAL-MODE FILE... diff --git a/src/uu/chown/src/chown.rs b/src/uu/chown/src/chown.rs index 81f2d1e5b..09801769a 100644 --- a/src/uu/chown/src/chown.rs +++ b/src/uu/chown/src/chown.rs @@ -36,7 +36,9 @@ const FTS_COMFOLLOW: u8 = 1; const FTS_PHYSICAL: u8 = 1 << 1; const FTS_LOGICAL: u8 = 1 << 2; -pub fn uumain(args: Vec) -> i32 { +pub fn uumain(args: impl uucore::Args) -> i32 { + let args = args.collect_str(); + let mut opts = app!(SYNTAX, SUMMARY, ""); opts.optflag("c", "changes", diff --git a/src/uu/chroot/src/chroot.rs b/src/uu/chroot/src/chroot.rs index f439e1f4f..89da2109e 100644 --- a/src/uu/chroot/src/chroot.rs +++ b/src/uu/chroot/src/chroot.rs @@ -29,7 +29,9 @@ static LONG_HELP: &str = " If $(SHELL) is not set, /bin/sh is used. "; -pub fn uumain(args: Vec) -> i32 { +pub fn uumain(args: impl uucore::Args) -> i32 { + let args = args.collect_str(); + let matches = app!(SYNTAX, SUMMARY, LONG_HELP) .optopt( "u", diff --git a/src/uu/cksum/src/cksum.rs b/src/uu/cksum/src/cksum.rs index f22cf91f5..f589e6f81 100644 --- a/src/uu/cksum/src/cksum.rs +++ b/src/uu/cksum/src/cksum.rs @@ -71,8 +71,8 @@ fn cksum(fname: &str) -> io::Result<(u32, usize)> { //Ok((0 as u32,0 as usize)) } -pub fn uumain(args: Vec) -> i32 { - let matches = app!(SYNTAX, SUMMARY, LONG_HELP).parse(args); +pub fn uumain(args: impl uucore::Args) -> i32 { + let matches = app!(SYNTAX, SUMMARY, LONG_HELP).parse(args.collect_str()); let files = matches.free; diff --git a/src/uu/comm/src/comm.rs b/src/uu/comm/src/comm.rs index e2517ee60..8c43f3a17 100644 --- a/src/uu/comm/src/comm.rs +++ b/src/uu/comm/src/comm.rs @@ -121,7 +121,9 @@ fn open_file(name: &str) -> io::Result { } } -pub fn uumain(args: Vec) -> i32 { +pub fn uumain(args: impl uucore::Args) -> i32 { + let args = args.collect_str(); + let matches = app!(SYNTAX, SUMMARY, LONG_HELP) .optflag("1", "", "suppress column 1 (lines uniq to FILE1)") .optflag("2", "", "suppress column 2 (lines uniq to FILE2)") diff --git a/src/uu/cp/src/cp.rs b/src/uu/cp/src/cp.rs index 01e911b58..f7e1afd21 100644 --- a/src/uu/cp/src/cp.rs +++ b/src/uu/cp/src/cp.rs @@ -302,7 +302,7 @@ static DEFAULT_ATTRIBUTES: &[Attribute] = &[ Attribute::Timestamps, ]; -pub fn uumain(args: Vec) -> i32 { +pub fn uumain(args: impl uucore::Args) -> i32 { let usage = get_usage(); let matches = App::new(executable!()) .version(VERSION) @@ -465,7 +465,7 @@ pub fn uumain(args: Vec) -> i32 { .arg(Arg::with_name(OPT_PATHS) .multiple(true)) - .get_matches_from(&args); + .get_matches_from(args); if matches.is_present(OPT_VERSION) { print_version(); diff --git a/src/uu/cut/src/cut.rs b/src/uu/cut/src/cut.rs index 4c2dd8b58..33399aba0 100644 --- a/src/uu/cut/src/cut.rs +++ b/src/uu/cut/src/cut.rs @@ -423,7 +423,9 @@ fn cut_files(mut filenames: Vec, mode: Mode) -> i32 { exit_code } -pub fn uumain(args: Vec) -> i32 { +pub fn uumain(args: impl uucore::Args) -> i32 { + let args = args.collect_str(); + let matches = app!(SYNTAX, SUMMARY, LONG_HELP) .optopt("b", "bytes", "filter byte columns from the input source", "sequence") .optopt("c", "characters", "alias for character mode", "sequence") diff --git a/src/uu/date/src/date.rs b/src/uu/date/src/date.rs index a82bb06cb..895c68b8c 100644 --- a/src/uu/date/src/date.rs +++ b/src/uu/date/src/date.rs @@ -129,7 +129,7 @@ impl<'a> From<&'a str> for Rfc3339Format { } } -pub fn uumain(args: Vec) -> i32 { +pub fn uumain(args: impl uucore::Args) -> i32 { let syntax = format!( "{0} [OPTION]... [+FORMAT]... {0} [OPTION]... [MMDDhhmm[[CC]YY][.ss]]", @@ -199,7 +199,7 @@ pub fn uumain(args: Vec) -> i32 { .help("print or set Coordinated Universal Time (UTC)"), ) .arg(Arg::with_name(OPT_FORMAT).multiple(true)) - .get_matches_from(&args); + .get_matches_from(args); let format = if let Some(form) = matches.value_of(OPT_FORMAT) { let form = form[1..].into(); diff --git a/src/uu/df/src/df.rs b/src/uu/df/src/df.rs index 95ee21f2f..0f9f440e2 100644 --- a/src/uu/df/src/df.rs +++ b/src/uu/df/src/df.rs @@ -741,7 +741,7 @@ fn use_size(free_size: u64, total_size: u64) -> String { ); } -pub fn uumain(args: Vec) -> i32 { +pub fn uumain(args: impl uucore::Args) -> i32 { let usage = get_usage(); let matches = App::new(executable!()) .version(VERSION) @@ -862,7 +862,7 @@ pub fn uumain(args: Vec) -> i32 { ) .arg(Arg::with_name(OPT_PATHS).multiple(true)) .help("Filesystem(s) to list") - .get_matches_from(&args); + .get_matches_from(args); if matches.is_present(OPT_VERSION) { println!("{} {}", executable!(), VERSION); diff --git a/src/uu/dircolors/src/dircolors.rs b/src/uu/dircolors/src/dircolors.rs index c88a1aa24..0b6072999 100644 --- a/src/uu/dircolors/src/dircolors.rs +++ b/src/uu/dircolors/src/dircolors.rs @@ -54,7 +54,9 @@ pub fn guess_syntax() -> OutputFmt { } } -pub fn uumain(args: Vec) -> i32 { +pub fn uumain(args: impl uucore::Args) -> i32 { + let args = args.collect_str(); + let matches = app!(SYNTAX, SUMMARY, LONG_HELP) .optflag("b", "sh", "output Bourne shell code to set LS_COLORS") .optflag( diff --git a/src/uu/dirname/src/dirname.rs b/src/uu/dirname/src/dirname.rs index 987708adc..59f47ff01 100644 --- a/src/uu/dirname/src/dirname.rs +++ b/src/uu/dirname/src/dirname.rs @@ -19,7 +19,9 @@ static LONG_HELP: &str = " directory). "; -pub fn uumain(args: Vec) -> i32 { +pub fn uumain(args: impl uucore::Args) -> i32 { + let args = args.collect_str(); + let matches = app!(SYNTAX, SUMMARY, LONG_HELP) .optflag("z", "zero", "separate output with NUL rather than newline") .parse(args); diff --git a/src/uu/du/src/du.rs b/src/uu/du/src/du.rs index 51fb5dd2c..f5071e749 100644 --- a/src/uu/du/src/du.rs +++ b/src/uu/du/src/du.rs @@ -225,7 +225,9 @@ fn convert_size_other(size: u64, _multiplier: u64, block_size: u64) -> String { } #[allow(clippy::cognitive_complexity)] -pub fn uumain(args: Vec) -> i32 { +pub fn uumain(args: impl uucore::Args) -> i32 { + let args = args.collect_str(); + let syntax = format!( "[OPTION]... [FILE]... {0} [OPTION]... --files0-from=F", diff --git a/src/uu/echo/src/echo.rs b/src/uu/echo/src/echo.rs index 94013393f..93c395391 100644 --- a/src/uu/echo/src/echo.rs +++ b/src/uu/echo/src/echo.rs @@ -102,7 +102,9 @@ fn print_escaped(input: &str, mut output: impl Write) -> io::Result { Ok(should_stop) } -pub fn uumain(args: Vec) -> i32 { +pub fn uumain(args: impl uucore::Args) -> i32 { + let args = args.collect_str(); + let matches = app!(SYNTAX, SUMMARY, HELP) .optflag("n", "", "do not output the trailing newline") .optflag("e", "", "enable interpretation of backslash escapes") diff --git a/src/uu/env/src/env.rs b/src/uu/env/src/env.rs index 741348019..545dd687d 100644 --- a/src/uu/env/src/env.rs +++ b/src/uu/env/src/env.rs @@ -152,7 +152,7 @@ fn create_app() -> App<'static, 'static> { .help("remove variable from the environment")) } -fn run_env(args: Vec) -> Result<(), i32> { +fn run_env(args: impl uucore::Args) -> Result<(), i32> { let app = create_app(); let matches = app.get_matches_from(args); @@ -251,7 +251,7 @@ fn run_env(args: Vec) -> Result<(), i32> { Ok(()) } -pub fn uumain(args: Vec) -> i32 { +pub fn uumain(args: impl uucore::Args) -> i32 { match run_env(args) { Ok(()) => 0, Err(code) => code, diff --git a/src/uu/expand/src/expand.rs b/src/uu/expand/src/expand.rs index 7ad5db4b0..560ffc840 100644 --- a/src/uu/expand/src/expand.rs +++ b/src/uu/expand/src/expand.rs @@ -100,7 +100,9 @@ impl Options { } } -pub fn uumain(args: Vec) -> i32 { +pub fn uumain(args: impl uucore::Args) -> i32 { + let args = args.collect_str(); + let matches = app!(SYNTAX, SUMMARY, LONG_HELP) .optflag("i", "initial", "do not convert tabs after non blanks") .optopt( diff --git a/src/uu/expr/src/expr.rs b/src/uu/expr/src/expr.rs index b30c30f74..db970f8a6 100644 --- a/src/uu/expr/src/expr.rs +++ b/src/uu/expr/src/expr.rs @@ -15,7 +15,9 @@ mod tokens; static NAME: &str = "expr"; static VERSION: &str = env!("CARGO_PKG_VERSION"); -pub fn uumain(args: Vec) -> i32 { +pub fn uumain(args: impl uucore::Args) -> i32 { + let args = args.collect_str(); + // For expr utility we do not want getopts. // The following usage should work without escaping hyphens: `expr -15 = 1 + 2 \* \( 3 - -4 \)` diff --git a/src/uu/factor/src/factor.rs b/src/uu/factor/src/factor.rs index 2fcf66ad4..d152124c7 100644 --- a/src/uu/factor/src/factor.rs +++ b/src/uu/factor/src/factor.rs @@ -115,8 +115,8 @@ fn print_factors_str(num_str: &str) { } } -pub fn uumain(args: Vec) -> i32 { - let matches = app!(SYNTAX, SUMMARY, LONG_HELP).parse(args); +pub fn uumain(args: impl uucore::Args) -> i32 { + let matches = app!(SYNTAX, SUMMARY, LONG_HELP).parse(args.collect_str()); if matches.free.is_empty() { let stdin = stdin(); diff --git a/src/uu/false/src/false.rs b/src/uu/false/src/false.rs index b7b8a396e..917c43fa0 100644 --- a/src/uu/false/src/false.rs +++ b/src/uu/false/src/false.rs @@ -5,6 +5,6 @@ // * For the full copyright and license information, please view the LICENSE // * file that was distributed with this source code. -pub fn uumain(_: Vec) -> i32 { +pub fn uumain(_: impl uucore::Args) -> i32 { 1 } diff --git a/src/uu/fmt/src/fmt.rs b/src/uu/fmt/src/fmt.rs index 0797ce30d..a7a3103b4 100644 --- a/src/uu/fmt/src/fmt.rs +++ b/src/uu/fmt/src/fmt.rs @@ -57,7 +57,9 @@ pub struct FmtOptions { } #[allow(clippy::cognitive_complexity)] -pub fn uumain(args: Vec) -> i32 { +pub fn uumain(args: impl uucore::Args) -> i32 { + let args = args.collect_str(); + let matches = app!(SYNTAX, SUMMARY, LONG_HELP) .optflag("c", "crown-margin", "First and second line of paragraph may have different indentations, in which case the first line's indentation is preserved, and each subsequent line's indentation matches the second line.") .optflag("t", "tagged-paragraph", "Like -c, except that the first and second line of a paragraph *must* have different indentation or they are treated as separate paragraphs.") diff --git a/src/uu/fold/src/fold.rs b/src/uu/fold/src/fold.rs index 066c05de1..75d007dce 100644 --- a/src/uu/fold/src/fold.rs +++ b/src/uu/fold/src/fold.rs @@ -19,7 +19,9 @@ static SUMMARY: &str = "Writes each file (or standard input if no files are give to standard output whilst breaking long lines"; static LONG_HELP: &str = ""; -pub fn uumain(args: Vec) -> i32 { +pub fn uumain(args: impl uucore::Args) -> i32 { + let args = args.collect_str(); + let (args, obs_width) = handle_obsolete(&args[..]); let matches = app!(SYNTAX, SUMMARY, LONG_HELP) .optflag( diff --git a/src/uu/groups/src/groups.rs b/src/uu/groups/src/groups.rs index 1ad5de7be..e2ae61a91 100644 --- a/src/uu/groups/src/groups.rs +++ b/src/uu/groups/src/groups.rs @@ -23,7 +23,7 @@ fn get_usage() -> String { format!("{0} [USERNAME]", executable!()) } -pub fn uumain(args: Vec) -> i32 { +pub fn uumain(args: impl uucore::Args) -> i32 { let usage = get_usage(); let matches = App::new(executable!()) @@ -31,7 +31,7 @@ pub fn uumain(args: Vec) -> i32 { .about(ABOUT) .usage(&usage[..]) .arg(Arg::with_name(OPT_USER)) - .get_matches_from(&args); + .get_matches_from(args); match matches.value_of(OPT_USER) { None => { diff --git a/src/uu/hashsum/src/hashsum.rs b/src/uu/hashsum/src/hashsum.rs index 9f59ed4a4..60d2c631f 100644 --- a/src/uu/hashsum/src/hashsum.rs +++ b/src/uu/hashsum/src/hashsum.rs @@ -234,7 +234,9 @@ fn detect_algo( } } -pub fn uumain(args: Vec) -> i32 { +pub fn uumain(args: impl uucore::Args) -> i32 { + let args = args.collect_str(); + let program = &args[0]; let binary_name = Path::new(program).file_name().unwrap().to_str().unwrap(); diff --git a/src/uu/head/src/head.rs b/src/uu/head/src/head.rs index e05f0d448..56d7e8452 100644 --- a/src/uu/head/src/head.rs +++ b/src/uu/head/src/head.rs @@ -40,7 +40,9 @@ impl Default for Settings { } } -pub fn uumain(args: Vec) -> i32 { +pub fn uumain(args: impl uucore::Args) -> i32 { + let args = args.collect_str(); + let mut settings: Settings = Default::default(); // handle obsolete -number syntax diff --git a/src/uu/hostid/src/hostid.rs b/src/uu/hostid/src/hostid.rs index d357e6d8a..162335b3a 100644 --- a/src/uu/hostid/src/hostid.rs +++ b/src/uu/hostid/src/hostid.rs @@ -23,8 +23,8 @@ extern "C" { pub fn gethostid() -> c_long; } -pub fn uumain(args: Vec) -> i32 { - app!(SYNTAX, SUMMARY, LONG_HELP).parse(args); +pub fn uumain(args: impl uucore::Args) -> i32 { + app!(SYNTAX, SUMMARY, LONG_HELP).parse(args.collect_str()); hostid(); 0 } diff --git a/src/uu/hostname/src/hostname.rs b/src/uu/hostname/src/hostname.rs index 99eadaa17..2e742da9a 100644 --- a/src/uu/hostname/src/hostname.rs +++ b/src/uu/hostname/src/hostname.rs @@ -35,7 +35,7 @@ static OPT_FQDN: &str = "fqdn"; static OPT_SHORT: &str = "short"; static OPT_HOST: &str = "host"; -pub fn uumain(args: Vec) -> i32 { +pub fn uumain(args: impl uucore::Args) -> i32 { #![allow(clippy::let_and_return)] #[cfg(windows)] unsafe { @@ -57,7 +57,7 @@ pub fn uumain(args: Vec) -> i32 { fn get_usage() -> String { format!("{0} [OPTION]... [HOSTNAME]", executable!()) } -fn execute(args: Vec) -> i32 { +fn execute(args: impl uucore::Args) -> i32 { let usage = get_usage(); let matches = App::new(executable!()) .version(VERSION) @@ -87,7 +87,7 @@ fn execute(args: Vec) -> i32 { possible", )) .arg(Arg::with_name(OPT_HOST)) - .get_matches_from(&args); + .get_matches_from(args); match matches.value_of(OPT_HOST) { None => display_hostname(&matches), diff --git a/src/uu/id/src/id.rs b/src/uu/id/src/id.rs index 97fa517f2..252f0b395 100644 --- a/src/uu/id/src/id.rs +++ b/src/uu/id/src/id.rs @@ -71,7 +71,9 @@ mod audit { static SYNTAX: &str = "[OPTION]... [USER]"; static SUMMARY: &str = "Print user and group information for the specified USER,\n or (when USER omitted) for the current user."; -pub fn uumain(args: Vec) -> i32 { +pub fn uumain(args: impl uucore::Args) -> i32 { + let args = args.collect_str(); + let mut opts = app!(SYNTAX, SUMMARY, ""); opts.optflag( "A", diff --git a/src/uu/install/src/install.rs b/src/uu/install/src/install.rs index c3e13e52a..4970689fb 100644 --- a/src/uu/install/src/install.rs +++ b/src/uu/install/src/install.rs @@ -56,7 +56,9 @@ impl Behavior { /// /// Returns a program return code. /// -pub fn uumain(args: Vec) -> i32 { +pub fn uumain(args: impl uucore::Args) -> i32 { + let args = args.collect_str(); + let matches = parse_opts(args); if let Err(s) = check_unimplemented(&matches) { diff --git a/src/uu/join/src/join.rs b/src/uu/join/src/join.rs index 5d0e0e561..23feae662 100644 --- a/src/uu/join/src/join.rs +++ b/src/uu/join/src/join.rs @@ -444,7 +444,7 @@ impl<'a> State<'a> { } } -pub fn uumain(args: Vec) -> i32 { +pub fn uumain(args: impl uucore::Args) -> i32 { let matches = App::new(NAME) .version(VERSION) .about( diff --git a/src/uu/kill/src/kill.rs b/src/uu/kill/src/kill.rs index 9ce4b3c11..d0df6fa3c 100644 --- a/src/uu/kill/src/kill.rs +++ b/src/uu/kill/src/kill.rs @@ -30,7 +30,9 @@ pub enum Mode { List, } -pub fn uumain(args: Vec) -> i32 { +pub fn uumain(args: impl uucore::Args) -> i32 { + let args = args.collect_str(); + let (args, obs_signal) = handle_obsolete(args); let matches = app!(SYNTAX, SUMMARY, LONG_HELP) .optopt("s", "signal", "specify the to be sent", "SIGNAL") diff --git a/src/uu/link/src/link.rs b/src/uu/link/src/link.rs index 23de5e3b4..51c7acb5f 100644 --- a/src/uu/link/src/link.rs +++ b/src/uu/link/src/link.rs @@ -23,8 +23,8 @@ pub fn normalize_error_message(e: Error) -> String { } } -pub fn uumain(args: Vec) -> i32 { - let matches = app!(SYNTAX, SUMMARY, LONG_HELP).parse(args); +pub fn uumain(args: impl uucore::Args) -> i32 { + let matches = app!(SYNTAX, SUMMARY, LONG_HELP).parse(args.collect_str()); if matches.free.len() != 2 { crash!(1, "{}", msg_wrong_number_of_arguments!(2)); } diff --git a/src/uu/ln/src/ln.rs b/src/uu/ln/src/ln.rs index a00052950..a82b9b3b5 100644 --- a/src/uu/ln/src/ln.rs +++ b/src/uu/ln/src/ln.rs @@ -56,7 +56,9 @@ pub enum BackupMode { ExistingBackup, } -pub fn uumain(args: Vec) -> i32 { +pub fn uumain(args: impl uucore::Args) -> i32 { + let args = args.collect_str(); + let syntax = format!( "[OPTION]... [-T] TARGET LINK_NAME (1st form) {0} [OPTION]... TARGET (2nd form) diff --git a/src/uu/logname/src/logname.rs b/src/uu/logname/src/logname.rs index 7c5e2024b..4537bb9cd 100644 --- a/src/uu/logname/src/logname.rs +++ b/src/uu/logname/src/logname.rs @@ -36,8 +36,8 @@ static SYNTAX: &str = ""; static SUMMARY: &str = "Print user's login name"; static LONG_HELP: &str = ""; -pub fn uumain(args: Vec) -> i32 { - app!(SYNTAX, SUMMARY, LONG_HELP).parse(args); +pub fn uumain(args: impl uucore::Args) -> i32 { + app!(SYNTAX, SUMMARY, LONG_HELP).parse(args.collect_str()); match get_userlogin() { Some(userlogin) => println!("{}", userlogin), diff --git a/src/uu/ls/src/ls.rs b/src/uu/ls/src/ls.rs index 5d946dd8d..d69ed4254 100644 --- a/src/uu/ls/src/ls.rs +++ b/src/uu/ls/src/ls.rs @@ -76,7 +76,9 @@ lazy_static! { static ref END_CODE: &'static str = COLOR_MAP.get("ec").unwrap_or(&""); } -pub fn uumain(args: Vec) -> i32 { +pub fn uumain(args: impl uucore::Args) -> i32 { + let args = args.collect_str(); + let syntax = format!( "[OPTION]... DIRECTORY {0} [OPTION]... [FILE]...", diff --git a/src/uu/mkdir/src/mkdir.rs b/src/uu/mkdir/src/mkdir.rs index 9a01b1202..c1c03d8f2 100644 --- a/src/uu/mkdir/src/mkdir.rs +++ b/src/uu/mkdir/src/mkdir.rs @@ -19,7 +19,9 @@ static VERSION: &str = env!("CARGO_PKG_VERSION"); /** * Handles option parsing */ -pub fn uumain(args: Vec) -> i32 { +pub fn uumain(args: impl uucore::Args) -> i32 { + let args = args.collect_str(); + let mut opts = getopts::Options::new(); // Linux-specific options, not implemented diff --git a/src/uu/mkfifo/src/mkfifo.rs b/src/uu/mkfifo/src/mkfifo.rs index 3bc424c31..1906e604a 100644 --- a/src/uu/mkfifo/src/mkfifo.rs +++ b/src/uu/mkfifo/src/mkfifo.rs @@ -18,7 +18,9 @@ use std::io::Error; static NAME: &str = "mkfifo"; static VERSION: &str = env!("CARGO_PKG_VERSION"); -pub fn uumain(args: Vec) -> i32 { +pub fn uumain(args: impl uucore::Args) -> i32 { + let args = args.collect_str(); + let mut opts = getopts::Options::new(); opts.optopt( diff --git a/src/uu/mknod/src/mknod.rs b/src/uu/mknod/src/mknod.rs index 9e4eb161c..59d6b129f 100644 --- a/src/uu/mknod/src/mknod.rs +++ b/src/uu/mknod/src/mknod.rs @@ -44,7 +44,9 @@ fn _makenod(path: CString, mode: mode_t, dev: dev_t) -> i32 { } #[allow(clippy::cognitive_complexity)] -pub fn uumain(args: Vec) -> i32 { +pub fn uumain(args: impl uucore::Args) -> i32 { + let args = args.collect_str(); + let mut opts = Options::new(); // Linux-specific options, not implemented diff --git a/src/uu/mktemp/src/mktemp.rs b/src/uu/mktemp/src/mktemp.rs index 436d4f91b..8cae1f70d 100644 --- a/src/uu/mktemp/src/mktemp.rs +++ b/src/uu/mktemp/src/mktemp.rs @@ -29,7 +29,9 @@ static NAME: &str = "mktemp"; static VERSION: &str = env!("CARGO_PKG_VERSION"); static DEFAULT_TEMPLATE: &str = "tmp.XXXXXXXXXX"; -pub fn uumain(args: Vec) -> i32 { +pub fn uumain(args: impl uucore::Args) -> i32 { + let args = args.collect_str(); + let mut opts = getopts::Options::new(); opts.optflag("d", "directory", "Make a directory instead of a file"); opts.optflag( diff --git a/src/uu/more/src/more.rs b/src/uu/more/src/more.rs index 18e69a836..5e0646b78 100644 --- a/src/uu/more/src/more.rs +++ b/src/uu/more/src/more.rs @@ -36,7 +36,9 @@ pub enum Mode { static NAME: &str = "more"; static VERSION: &str = env!("CARGO_PKG_VERSION"); -pub fn uumain(args: Vec) -> i32 { +pub fn uumain(args: impl uucore::Args) -> i32 { + let args = args.collect_str(); + let mut opts = Options::new(); // FixME: fail without panic for now; but `more` should work with no arguments (ie, for piped input) diff --git a/src/uu/mv/src/mv.rs b/src/uu/mv/src/mv.rs index 42f4f3134..d0d98dafa 100644 --- a/src/uu/mv/src/mv.rs +++ b/src/uu/mv/src/mv.rs @@ -53,7 +53,9 @@ pub enum BackupMode { ExistingBackup, } -pub fn uumain(args: Vec) -> i32 { +pub fn uumain(args: impl uucore::Args) -> i32 { + let args = args.collect_str(); + let mut opts = getopts::Options::new(); opts.optflagopt( diff --git a/src/uu/nice/src/nice.rs b/src/uu/nice/src/nice.rs index 16692dfdd..5d5647a51 100644 --- a/src/uu/nice/src/nice.rs +++ b/src/uu/nice/src/nice.rs @@ -29,7 +29,9 @@ extern "C" { fn setpriority(which: c_int, who: c_int, prio: c_int) -> c_int; } -pub fn uumain(args: Vec) -> i32 { +pub fn uumain(args: impl uucore::Args) -> i32 { + let args = args.collect_str(); + let mut opts = getopts::Options::new(); opts.optopt( diff --git a/src/uu/nl/src/nl.rs b/src/uu/nl/src/nl.rs index 14f710d5f..6bf134704 100644 --- a/src/uu/nl/src/nl.rs +++ b/src/uu/nl/src/nl.rs @@ -73,7 +73,9 @@ enum NumberFormat { RightZero, } -pub fn uumain(args: Vec) -> i32 { +pub fn uumain(args: impl uucore::Args) -> i32 { + let args = args.collect_str(); + let mut opts = getopts::Options::new(); opts.optopt( diff --git a/src/uu/nohup/src/nohup.rs b/src/uu/nohup/src/nohup.rs index 68d7e2a9a..76919cd7e 100644 --- a/src/uu/nohup/src/nohup.rs +++ b/src/uu/nohup/src/nohup.rs @@ -36,7 +36,9 @@ unsafe fn _vprocmgr_detach_from_console(_: u32) -> *const libc::c_int { std::ptr::null() } -pub fn uumain(args: Vec) -> i32 { +pub fn uumain(args: impl uucore::Args) -> i32 { + let args = args.collect_str(); + let mut opts = getopts::Options::new(); opts.optflag("h", "help", "Show help and exit"); diff --git a/src/uu/nproc/src/nproc.rs b/src/uu/nproc/src/nproc.rs index 07a4a1b05..d18952276 100644 --- a/src/uu/nproc/src/nproc.rs +++ b/src/uu/nproc/src/nproc.rs @@ -39,7 +39,7 @@ fn get_usage() -> String { format!("{0} [OPTIONS]...", executable!()) } -pub fn uumain(args: Vec) -> i32 { +pub fn uumain(args: impl uucore::Args) -> i32 { let usage = get_usage(); let matches = App::new(executable!()) .version(VERSION) @@ -58,7 +58,7 @@ pub fn uumain(args: Vec) -> i32 { .takes_value(true) .help("ignore up to N cores"), ) - .get_matches_from(&args); + .get_matches_from(args); let mut ignore = match matches.value_of(OPT_IGNORE) { Some(numstr) => match numstr.parse() { diff --git a/src/uu/numfmt/src/numfmt.rs b/src/uu/numfmt/src/numfmt.rs index 46b4667a2..bf7c51c9e 100644 --- a/src/uu/numfmt/src/numfmt.rs +++ b/src/uu/numfmt/src/numfmt.rs @@ -280,7 +280,9 @@ fn handle_stdin(options: NumfmtOptions) -> Result<()> { Ok(()) } -pub fn uumain(args: Vec) -> i32 { +pub fn uumain(args: impl uucore::Args) -> i32 { + let args = args.collect_str(); + let mut opts = Options::new(); opts.optflag("h", "help", "display this help and exit"); diff --git a/src/uu/od/src/od.rs b/src/uu/od/src/od.rs index e4e7b3a89..84848a72c 100644 --- a/src/uu/od/src/od.rs +++ b/src/uu/od/src/od.rs @@ -290,7 +290,9 @@ impl OdOptions { /// parses and validates command line parameters, prepares data structures, /// opens the input and calls `odfunc` to process the input. -pub fn uumain(args: Vec) -> i32 { +pub fn uumain(args: impl uucore::Args) -> i32 { + let args = args.collect_str(); + let opts = create_getopts_options(); let matches = match opts.parse(&args[1..]) { diff --git a/src/uu/paste/src/paste.rs b/src/uu/paste/src/paste.rs index 0b0d1880a..345e3722a 100644 --- a/src/uu/paste/src/paste.rs +++ b/src/uu/paste/src/paste.rs @@ -20,7 +20,9 @@ use std::path::Path; static NAME: &str = "paste"; static VERSION: &str = env!("CARGO_PKG_VERSION"); -pub fn uumain(args: Vec) -> i32 { +pub fn uumain(args: impl uucore::Args) -> i32 { + let args = args.collect_str(); + let mut opts = getopts::Options::new(); opts.optflag( diff --git a/src/uu/pathchk/src/pathchk.rs b/src/uu/pathchk/src/pathchk.rs index dd0cee3ef..972cd4873 100644 --- a/src/uu/pathchk/src/pathchk.rs +++ b/src/uu/pathchk/src/pathchk.rs @@ -36,7 +36,9 @@ static VERSION: &str = env!("CARGO_PKG_VERSION"); const POSIX_PATH_MAX: usize = 256; const POSIX_NAME_MAX: usize = 14; -pub fn uumain(args: Vec) -> i32 { +pub fn uumain(args: impl uucore::Args) -> i32 { + let args = args.collect_str(); + // add options let mut opts = Options::new(); opts.optflag("p", "posix", "check for (most) POSIX systems"); diff --git a/src/uu/pinky/src/pinky.rs b/src/uu/pinky/src/pinky.rs index 1d089450c..772e311d6 100644 --- a/src/uu/pinky/src/pinky.rs +++ b/src/uu/pinky/src/pinky.rs @@ -27,7 +27,9 @@ static SUMMARY: &str = "A lightweight 'finger' program; print user information. const BUFSIZE: usize = 1024; -pub fn uumain(args: Vec) -> i32 { +pub fn uumain(args: impl uucore::Args) -> i32 { + let args = args.collect_str(); + let long_help = &format!( " -l produce long format output for the specified USERs diff --git a/src/uu/printenv/src/printenv.rs b/src/uu/printenv/src/printenv.rs index 10b64213e..16dd6f0b0 100644 --- a/src/uu/printenv/src/printenv.rs +++ b/src/uu/printenv/src/printenv.rs @@ -17,7 +17,9 @@ use std::env; static NAME: &str = "printenv"; static VERSION: &str = env!("CARGO_PKG_VERSION"); -pub fn uumain(args: Vec) -> i32 { +pub fn uumain(args: impl uucore::Args) -> i32 { + let args = args.collect_str(); + let mut opts = getopts::Options::new(); opts.optflag( "0", diff --git a/src/uu/printf/src/printf.rs b/src/uu/printf/src/printf.rs index 3062d52de..246a1dcea 100644 --- a/src/uu/printf/src/printf.rs +++ b/src/uu/printf/src/printf.rs @@ -275,7 +275,9 @@ COPYRIGHT : "; -pub fn uumain(args: Vec) -> i32 { +pub fn uumain(args: impl uucore::Args) -> i32 { + let args = args.collect_str(); + let location = &args[0]; if args.len() <= 1 { println!( diff --git a/src/uu/ptx/src/ptx.rs b/src/uu/ptx/src/ptx.rs index 5c52c2680..3621e1bdf 100644 --- a/src/uu/ptx/src/ptx.rs +++ b/src/uu/ptx/src/ptx.rs @@ -491,7 +491,9 @@ fn write_traditional_output( } } -pub fn uumain(args: Vec) -> i32 { +pub fn uumain(args: impl uucore::Args) -> i32 { + let args = args.collect_str(); + let mut opts = Options::new(); opts.optflag( "A", diff --git a/src/uu/pwd/src/pwd.rs b/src/uu/pwd/src/pwd.rs index 3b678b756..1861c8084 100644 --- a/src/uu/pwd/src/pwd.rs +++ b/src/uu/pwd/src/pwd.rs @@ -32,7 +32,9 @@ pub fn absolute_path(path: &Path) -> io::Result { Ok(path_buf) } -pub fn uumain(args: Vec) -> i32 { +pub fn uumain(args: impl uucore::Args) -> i32 { + let args = args.collect_str(); + let mut opts = getopts::Options::new(); opts.optflag("", "help", "display this help and exit"); diff --git a/src/uu/readlink/src/readlink.rs b/src/uu/readlink/src/readlink.rs index d81ca8e14..c4721c58f 100644 --- a/src/uu/readlink/src/readlink.rs +++ b/src/uu/readlink/src/readlink.rs @@ -20,7 +20,9 @@ use uucore::fs::{canonicalize, CanonicalizeMode}; const NAME: &str = "readlink"; const VERSION: &str = env!("CARGO_PKG_VERSION"); -pub fn uumain(args: Vec) -> i32 { +pub fn uumain(args: impl uucore::Args) -> i32 { + let args = args.collect_str(); + let mut opts = getopts::Options::new(); opts.optflag( diff --git a/src/uu/realpath/src/realpath.rs b/src/uu/realpath/src/realpath.rs index 780b7964b..db7ce846b 100644 --- a/src/uu/realpath/src/realpath.rs +++ b/src/uu/realpath/src/realpath.rs @@ -19,7 +19,9 @@ use uucore::fs::{canonicalize, CanonicalizeMode}; static NAME: &str = "realpath"; static VERSION: &str = env!("CARGO_PKG_VERSION"); -pub fn uumain(args: Vec) -> i32 { +pub fn uumain(args: impl uucore::Args) -> i32 { + let args = args.collect_str(); + let mut opts = getopts::Options::new(); opts.optflag("h", "help", "Show help and exit"); diff --git a/src/uu/relpath/src/relpath.rs b/src/uu/relpath/src/relpath.rs index f66d7ae41..e48d43b44 100644 --- a/src/uu/relpath/src/relpath.rs +++ b/src/uu/relpath/src/relpath.rs @@ -19,7 +19,9 @@ use uucore::fs::{canonicalize, CanonicalizeMode}; static NAME: &str = "relpath"; static VERSION: &str = env!("CARGO_PKG_VERSION"); -pub fn uumain(args: Vec) -> i32 { +pub fn uumain(args: impl uucore::Args) -> i32 { + let args = args.collect_str(); + let mut opts = getopts::Options::new(); opts.optflag("h", "help", "Show help and exit"); diff --git a/src/uu/rm/src/rm.rs b/src/uu/rm/src/rm.rs index 4b08a5789..42c7be557 100644 --- a/src/uu/rm/src/rm.rs +++ b/src/uu/rm/src/rm.rs @@ -43,7 +43,9 @@ struct Options { static NAME: &str = "rm"; static VERSION: &str = env!("CARGO_PKG_VERSION"); -pub fn uumain(args: Vec) -> i32 { +pub fn uumain(args: impl uucore::Args) -> i32 { + let args = args.collect_str(); + // TODO: make getopts support -R in addition to -r let mut opts = getopts::Options::new(); diff --git a/src/uu/rmdir/src/rmdir.rs b/src/uu/rmdir/src/rmdir.rs index 881a79d82..65ea630d1 100644 --- a/src/uu/rmdir/src/rmdir.rs +++ b/src/uu/rmdir/src/rmdir.rs @@ -16,7 +16,9 @@ use std::path::Path; static NAME: &str = "rmdir"; static VERSION: &str = env!("CARGO_PKG_VERSION"); -pub fn uumain(args: Vec) -> i32 { +pub fn uumain(args: impl uucore::Args) -> i32 { + let args = args.collect_str(); + let mut opts = getopts::Options::new(); opts.optflag( diff --git a/src/uu/seq/src/seq.rs b/src/uu/seq/src/seq.rs index 1ca4c8a9b..57890ab28 100644 --- a/src/uu/seq/src/seq.rs +++ b/src/uu/seq/src/seq.rs @@ -170,7 +170,9 @@ fn print_version() { println!("{} {}", NAME, VERSION); } -pub fn uumain(args: Vec) -> i32 { +pub fn uumain(args: impl uucore::Args) -> i32 { + let args = args.collect_str(); + let mut options = SeqOptions { separator: "\n".to_owned(), terminator: None, diff --git a/src/uu/shred/src/shred.rs b/src/uu/shred/src/shred.rs index 27ba1e1a2..307684375 100644 --- a/src/uu/shred/src/shred.rs +++ b/src/uu/shred/src/shred.rs @@ -203,7 +203,9 @@ impl<'a> Iterator for BytesGenerator<'a> { } } -pub fn uumain(args: Vec) -> i32 { +pub fn uumain(args: impl uucore::Args) -> i32 { + let args = args.collect_str(); + let mut opts = getopts::Options::new(); // TODO: Add force option diff --git a/src/uu/shuf/src/shuf.rs b/src/uu/shuf/src/shuf.rs index 6b4a34121..6006b7875 100644 --- a/src/uu/shuf/src/shuf.rs +++ b/src/uu/shuf/src/shuf.rs @@ -27,7 +27,9 @@ enum Mode { static NAME: &str = "shuf"; static VERSION: &str = env!("CARGO_PKG_VERSION"); -pub fn uumain(args: Vec) -> i32 { +pub fn uumain(args: impl uucore::Args) -> i32 { + let args = args.collect_str(); + let mut opts = getopts::Options::new(); opts.optflag("e", "echo", "treat each ARG as an input line"); opts.optopt( diff --git a/src/uu/sleep/src/sleep.rs b/src/uu/sleep/src/sleep.rs index fbab77dc5..1097da886 100644 --- a/src/uu/sleep/src/sleep.rs +++ b/src/uu/sleep/src/sleep.rs @@ -16,10 +16,13 @@ use std::time::Duration; static NAME: &str = "sleep"; static VERSION: &str = env!("CARGO_PKG_VERSION"); -pub fn uumain(args: Vec) -> i32 { +pub fn uumain(args: impl uucore::Args) -> i32 { + let args = args.collect_str(); + let mut opts = getopts::Options::new(); opts.optflag("h", "help", "display this help and exit"); opts.optflag("V", "version", "output version information and exit"); + let matches = match opts.parse(&args[1..]) { Ok(m) => m, Err(f) => { diff --git a/src/uu/sort/src/sort.rs b/src/uu/sort/src/sort.rs index 92b91bf29..dc4dc1d90 100644 --- a/src/uu/sort/src/sort.rs +++ b/src/uu/sort/src/sort.rs @@ -143,7 +143,9 @@ impl<'a> Iterator for FileMerger<'a> { } } -pub fn uumain(args: Vec) -> i32 { +pub fn uumain(args: impl uucore::Args) -> i32 { + let args = args.collect_str(); + let mut settings: Settings = Default::default(); let mut opts = getopts::Options::new(); diff --git a/src/uu/split/src/split.rs b/src/uu/split/src/split.rs index 181224f2a..904ed9095 100644 --- a/src/uu/split/src/split.rs +++ b/src/uu/split/src/split.rs @@ -20,7 +20,9 @@ use std::path::Path; static NAME: &str = "split"; static VERSION: &str = env!("CARGO_PKG_VERSION"); -pub fn uumain(args: Vec) -> i32 { +pub fn uumain(args: impl uucore::Args) -> i32 { + let args = args.collect_str(); + let mut opts = getopts::Options::new(); opts.optopt( diff --git a/src/uu/stat/src/stat.rs b/src/uu/stat/src/stat.rs index af02bbbeb..dd04eb0fa 100644 --- a/src/uu/stat/src/stat.rs +++ b/src/uu/stat/src/stat.rs @@ -872,7 +872,9 @@ impl Stater { } } -pub fn uumain(args: Vec) -> i32 { +pub fn uumain(args: impl uucore::Args) -> i32 { + let args = args.collect_str(); + let mut opts = Options::new(); opts.optflag("h", "help", "display this help and exit"); diff --git a/src/uu/stdbuf/src/stdbuf.rs b/src/uu/stdbuf/src/stdbuf.rs index 6f5eacde7..dcae42d99 100644 --- a/src/uu/stdbuf/src/stdbuf.rs +++ b/src/uu/stdbuf/src/stdbuf.rs @@ -217,7 +217,9 @@ fn get_preload_env(tmp_dir: &mut TempDir) -> io::Result<(String, PathBuf)> { Ok((preload.to_owned(), inject_path)) } -pub fn uumain(args: Vec) -> i32 { +pub fn uumain(args: impl uucore::Args) -> i32 { + let args = args.collect_str(); + let mut opts = Options::new(); opts.optopt( diff --git a/src/uu/sum/src/sum.rs b/src/uu/sum/src/sum.rs index 9f5afe2d2..3fb28d15d 100644 --- a/src/uu/sum/src/sum.rs +++ b/src/uu/sum/src/sum.rs @@ -72,7 +72,9 @@ fn open(name: &str) -> Result> { } } -pub fn uumain(args: Vec) -> i32 { +pub fn uumain(args: impl uucore::Args) -> i32 { + let args = args.collect_str(); + let mut opts = getopts::Options::new(); opts.optflag("r", "", "use the BSD compatible algorithm (default)"); diff --git a/src/uu/sync/src/sync.rs b/src/uu/sync/src/sync.rs index fe417fb8d..bb6d8cd80 100644 --- a/src/uu/sync/src/sync.rs +++ b/src/uu/sync/src/sync.rs @@ -118,7 +118,9 @@ mod platform { } } -pub fn uumain(args: Vec) -> i32 { +pub fn uumain(args: impl uucore::Args) -> i32 { + let args = args.collect_str(); + let mut opts = getopts::Options::new(); opts.optflag("h", "help", "display this help and exit"); diff --git a/src/uu/tac/src/tac.rs b/src/uu/tac/src/tac.rs index b833efa2a..91bbea4d8 100644 --- a/src/uu/tac/src/tac.rs +++ b/src/uu/tac/src/tac.rs @@ -18,7 +18,9 @@ use std::io::{stdin, stdout, BufReader, Read, Stdout, Write}; static NAME: &str = "tac"; static VERSION: &str = env!("CARGO_PKG_VERSION"); -pub fn uumain(args: Vec) -> i32 { +pub fn uumain(args: impl uucore::Args) -> i32 { + let args = args.collect_str(); + let mut opts = getopts::Options::new(); opts.optflag( diff --git a/src/uu/tail/src/tail.rs b/src/uu/tail/src/tail.rs index 10b82bd92..949c7e5ca 100644 --- a/src/uu/tail/src/tail.rs +++ b/src/uu/tail/src/tail.rs @@ -56,7 +56,9 @@ impl Default for Settings { } #[allow(clippy::cognitive_complexity)] -pub fn uumain(args: Vec) -> i32 { +pub fn uumain(args: impl uucore::Args) -> i32 { + let args = args.collect_str(); + let mut settings: Settings = Default::default(); // handle obsolete -number syntax diff --git a/src/uu/tee/src/tee.rs b/src/uu/tee/src/tee.rs index 32a71c48a..a75287d97 100644 --- a/src/uu/tee/src/tee.rs +++ b/src/uu/tee/src/tee.rs @@ -16,7 +16,9 @@ use std::path::{Path, PathBuf}; static NAME: &str = "tee"; static VERSION: &str = env!("CARGO_PKG_VERSION"); -pub fn uumain(args: Vec) -> i32 { +pub fn uumain(args: impl uucore::Args) -> i32 { + let args = args.collect_str(); + match options(&args).and_then(exec) { Ok(_) => 0, Err(_) => 1, diff --git a/src/uu/test/src/test.rs b/src/uu/test/src/test.rs index fa0e3bc58..dafe1913c 100644 --- a/src/uu/test/src/test.rs +++ b/src/uu/test/src/test.rs @@ -12,16 +12,12 @@ extern crate libc; extern crate syscall; use std::collections::HashMap; -use std::env::args_os; -use std::ffi::OsString; use std::str::from_utf8; static NAME: &str = "test"; -// TODO: decide how to handle non-UTF8 input for all the utils -// Definitely don't use [u8], try keeping it as OsStr or OsString instead -pub fn uumain(_: Vec) -> i32 { - let args = args_os().collect::>(); +pub fn uumain(args: impl uucore::Args) -> i32 { + let args: Vec<_> = args.collect(); // This is completely disregarding valid windows paths that aren't valid unicode let args = args .iter() diff --git a/src/uu/timeout/src/timeout.rs b/src/uu/timeout/src/timeout.rs index d307f755b..59bbeca8f 100644 --- a/src/uu/timeout/src/timeout.rs +++ b/src/uu/timeout/src/timeout.rs @@ -24,7 +24,9 @@ static VERSION: &str = env!("CARGO_PKG_VERSION"); const ERR_EXIT_STATUS: i32 = 125; -pub fn uumain(args: Vec) -> i32 { +pub fn uumain(args: impl uucore::Args) -> i32 { + let args = args.collect_str(); + let program = args[0].clone(); let mut opts = getopts::Options::new(); diff --git a/src/uu/touch/src/touch.rs b/src/uu/touch/src/touch.rs index 6c1b7c0c9..48abd63a2 100644 --- a/src/uu/touch/src/touch.rs +++ b/src/uu/touch/src/touch.rs @@ -41,7 +41,9 @@ macro_rules! local_tm_to_filetime( }) ); -pub fn uumain(args: Vec) -> i32 { +pub fn uumain(args: impl uucore::Args) -> i32 { + let args = args.collect_str(); + let mut opts = getopts::Options::new(); opts.optflag("a", "", "change only the access time"); diff --git a/src/uu/tr/src/tr.rs b/src/uu/tr/src/tr.rs index d8d78a318..19f123a02 100644 --- a/src/uu/tr/src/tr.rs +++ b/src/uu/tr/src/tr.rs @@ -183,7 +183,9 @@ fn usage(opts: &Options) { println!("{}", opts.usage("Translate or delete characters.")); } -pub fn uumain(args: Vec) -> i32 { +pub fn uumain(args: impl uucore::Args) -> i32 { + let args = args.collect_str(); + let mut opts = Options::new(); opts.optflag("c", "complement", "use the complement of SET1"); diff --git a/src/uu/true/src/true.rs b/src/uu/true/src/true.rs index 1589b7113..7cb23f621 100644 --- a/src/uu/true/src/true.rs +++ b/src/uu/true/src/true.rs @@ -5,6 +5,6 @@ // * For the full copyright and license information, please view the LICENSE // * file that was distributed with this source code. -pub fn uumain(_: Vec) -> i32 { +pub fn uumain(_: impl uucore::Args) -> i32 { 0 } diff --git a/src/uu/truncate/src/truncate.rs b/src/uu/truncate/src/truncate.rs index ed34f41c1..6e36eb76e 100644 --- a/src/uu/truncate/src/truncate.rs +++ b/src/uu/truncate/src/truncate.rs @@ -30,7 +30,9 @@ enum TruncateMode { static NAME: &str = "truncate"; static VERSION: &str = env!("CARGO_PKG_VERSION"); -pub fn uumain(args: Vec) -> i32 { +pub fn uumain(args: impl uucore::Args) -> i32 { + let args = args.collect_str(); + let mut opts = getopts::Options::new(); opts.optflag("c", "no-create", "do not create files that do not exist"); diff --git a/src/uu/tsort/src/tsort.rs b/src/uu/tsort/src/tsort.rs index 0b8a05206..e8a1010e1 100644 --- a/src/uu/tsort/src/tsort.rs +++ b/src/uu/tsort/src/tsort.rs @@ -19,7 +19,9 @@ use std::path::Path; static NAME: &str = "tsort"; static VERSION: &str = env!("CARGO_PKG_VERSION"); -pub fn uumain(args: Vec) -> i32 { +pub fn uumain(args: impl uucore::Args) -> i32 { + let args = args.collect_str(); + let mut opts = getopts::Options::new(); opts.optflag("h", "help", "display this help and exit"); diff --git a/src/uu/tty/src/tty.rs b/src/uu/tty/src/tty.rs index 20f64c886..177fc8668 100644 --- a/src/uu/tty/src/tty.rs +++ b/src/uu/tty/src/tty.rs @@ -25,7 +25,9 @@ extern "C" { static NAME: &str = "tty"; static VERSION: &str = env!("CARGO_PKG_VERSION"); -pub fn uumain(args: Vec) -> i32 { +pub fn uumain(args: impl uucore::Args) -> i32 { + let args = args.collect_str(); + let mut opts = getopts::Options::new(); opts.optflag("s", "silent", "print nothing, only return an exit status"); diff --git a/src/uu/uname/src/uname.rs b/src/uu/uname/src/uname.rs index f96edd8a5..c81c9cfa1 100644 --- a/src/uu/uname/src/uname.rs +++ b/src/uu/uname/src/uname.rs @@ -48,7 +48,7 @@ const HOST_OS: &str = "Fuchsia"; #[cfg(target_os = "redox")] const HOST_OS: &str = "Redox"; -pub fn uumain(args: Vec) -> i32 { +pub fn uumain(args: impl uucore::Args) -> i32 { let usage = format!("{} [OPTION]...", executable!()); let matches = App::new(executable!()) .version(VERSION) @@ -94,34 +94,43 @@ pub fn uumain(args: Vec) -> i32 { .short("o") .long(OPT_OS) .help("print the operating system name.")) - .get_matches_from(&args); + .get_matches_from(args); - let argc = args.len(); let uname = return_if_err!(1, PlatformInfo::new()); let mut output = String::new(); - if matches.is_present(OPT_KERNELNAME) || matches.is_present(OPT_ALL) || argc == 1 { + 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 os = matches.is_present(OPT_OS); + + let none = !(all || kernelname || nodename || kernelrelease || kernelversion || machine || os); + + if kernelname || all || none { output.push_str(&uname.sysname()); output.push_str(" "); } - if matches.is_present(OPT_NODENAME) || matches.is_present(OPT_ALL) { + if nodename || all { output.push_str(&uname.nodename()); output.push_str(" "); } - if matches.is_present(OPT_KERNELRELEASE) || matches.is_present(OPT_ALL) { + if kernelrelease || all { output.push_str(&uname.release()); output.push_str(" "); } - if matches.is_present(OPT_KERNELVERSION) || matches.is_present(OPT_ALL) { + if kernelversion || all { output.push_str(&uname.version()); output.push_str(" "); } - if matches.is_present(OPT_MACHINE) || matches.is_present(OPT_ALL) { + if machine || all { output.push_str(&uname.machine()); output.push_str(" "); } - if matches.is_present(OPT_OS) || matches.is_present(OPT_ALL) { + if os || all { output.push_str(HOST_OS); output.push_str(" "); } diff --git a/src/uu/unexpand/src/unexpand.rs b/src/uu/unexpand/src/unexpand.rs index 148f8960f..1ca12ba87 100644 --- a/src/uu/unexpand/src/unexpand.rs +++ b/src/uu/unexpand/src/unexpand.rs @@ -83,7 +83,9 @@ impl Options { } } -pub fn uumain(args: Vec) -> i32 { +pub fn uumain(args: impl uucore::Args) -> i32 { + let args = args.collect_str(); + let mut opts = getopts::Options::new(); opts.optflag( diff --git a/src/uu/uniq/src/uniq.rs b/src/uu/uniq/src/uniq.rs index 79b8857cf..4c4ed1ed4 100644 --- a/src/uu/uniq/src/uniq.rs +++ b/src/uu/uniq/src/uniq.rs @@ -201,7 +201,9 @@ fn opt_parsed(opt_name: &str, matches: &Matches) -> Option { }) } -pub fn uumain(args: Vec) -> i32 { +pub fn uumain(args: impl uucore::Args) -> i32 { + let args = args.collect_str(); + let mut opts = Options::new(); opts.optflag("c", "count", "prefix lines by the number of occurrences"); diff --git a/src/uu/unlink/src/unlink.rs b/src/uu/unlink/src/unlink.rs index 2ba716959..6fad6ca48 100644 --- a/src/uu/unlink/src/unlink.rs +++ b/src/uu/unlink/src/unlink.rs @@ -24,7 +24,9 @@ use std::io::{Error, ErrorKind}; static NAME: &str = "unlink"; static VERSION: &str = env!("CARGO_PKG_VERSION"); -pub fn uumain(args: Vec) -> i32 { +pub fn uumain(args: impl uucore::Args) -> i32 { + let args = args.collect_str(); + let mut opts = Options::new(); opts.optflag("h", "help", "display this help and exit"); diff --git a/src/uu/uptime/src/uptime.rs b/src/uu/uptime/src/uptime.rs index eb0329cd0..5c51a535b 100644 --- a/src/uu/uptime/src/uptime.rs +++ b/src/uu/uptime/src/uptime.rs @@ -41,7 +41,7 @@ fn get_usage() -> String { format!("{0} [OPTION]...", executable!()) } -pub fn uumain(args: Vec) -> i32 { +pub fn uumain(args: impl uucore::Args) -> i32 { let usage = get_usage(); let matches = App::new(executable!()) .version(VERSION) @@ -53,7 +53,7 @@ pub fn uumain(args: Vec) -> i32 { .long("since") .help("system up since"), ) - .get_matches_from(&args); + .get_matches_from(args); let (boot_time, user_count) = process_utmpx(); let uptime = get_uptime(boot_time); diff --git a/src/uu/users/src/users.rs b/src/uu/users/src/users.rs index 72284dee7..850b3112c 100644 --- a/src/uu/users/src/users.rs +++ b/src/uu/users/src/users.rs @@ -20,7 +20,9 @@ use getopts::Options; static NAME: &str = "users"; static VERSION: &str = env!("CARGO_PKG_VERSION"); -pub fn uumain(args: Vec) -> i32 { +pub fn uumain(args: impl uucore::Args) -> i32 { + let args = args.collect_str(); + let mut opts = Options::new(); opts.optflag("h", "help", "display this help and exit"); diff --git a/src/uu/wc/src/wc.rs b/src/uu/wc/src/wc.rs index a7c9cda13..3aa1b0510 100644 --- a/src/uu/wc/src/wc.rs +++ b/src/uu/wc/src/wc.rs @@ -69,7 +69,9 @@ struct Result { static NAME: &str = "wc"; static VERSION: &str = env!("CARGO_PKG_VERSION"); -pub fn uumain(args: Vec) -> i32 { +pub fn uumain(args: impl uucore::Args) -> i32 { + let args = args.collect_str(); + let mut opts = Options::new(); opts.optflag("c", "bytes", "print the byte counts"); diff --git a/src/uu/who/src/who.rs b/src/uu/who/src/who.rs index dd6090669..b028be0a0 100644 --- a/src/uu/who/src/who.rs +++ b/src/uu/who/src/who.rs @@ -43,7 +43,9 @@ If FILE is not specified, use /var/run/utmp. /var/log/wtmp as FILE is common. If ARG1 ARG2 given, -m presumed: 'am i' or 'mom likes' are usual. "; -pub fn uumain(args: Vec) -> i32 { +pub fn uumain(args: impl uucore::Args) -> i32 { + let args = args.collect_str(); + let mut opts = app!(SYNTAX, SUMMARY, LONG_HELP); opts.optflag("a", "all", "same as -b -d --login -p -r -t -T -u"); opts.optflag("b", "boot", "time of last system boot"); diff --git a/src/uu/whoami/src/whoami.rs b/src/uu/whoami/src/whoami.rs index 65b8e73fb..21e170dec 100644 --- a/src/uu/whoami/src/whoami.rs +++ b/src/uu/whoami/src/whoami.rs @@ -16,7 +16,7 @@ extern crate uucore; mod platform; -pub fn uumain(args: Vec) -> i32 { +pub fn uumain(args: impl uucore::Args) -> i32 { let app = app_from_crate!(); if let Err(err) = app.get_matches_from_safe(args) { diff --git a/src/uu/yes/src/yes.rs b/src/uu/yes/src/yes.rs index 0a5d56ec1..7932a1486 100644 --- a/src/uu/yes/src/yes.rs +++ b/src/uu/yes/src/yes.rs @@ -21,7 +21,7 @@ use uucore::zero_copy::ZeroCopyWriter; // systems, but honestly this is good enough const BUF_SIZE: usize = 16 * 1024; -pub fn uumain(args: Vec) -> i32 { +pub fn uumain(args: impl uucore::Args) -> i32 { let app = app_from_crate!().arg(Arg::with_name("STRING").index(1).multiple(true)); let matches = match app.get_matches_from_safe(args) {