diff --git a/Cargo.lock b/Cargo.lock index 4abfb1fdb..825519bbe 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -915,18 +915,18 @@ dependencies = [ [[package]] name = "fundu" -version = "1.1.0" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d579dcb632d86591bdd7fc445e705b96cb2a7fb5488d918d956f392b6148e898" +checksum = "34804ed59f10b3a630c79822ebf7370b562b7281028369e9baa40547c17f8bdc" dependencies = [ "fundu-core", ] [[package]] name = "fundu-core" -version = "0.1.0" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a363b75dd1e4b5bd2cdc305c47399c524cae24638b368b66b1a4c2a36482801f" +checksum = "71a99190954ca83bade03ba054799b17a158ea948a6855c6bb8121adb6b49d9f" [[package]] name = "futures" diff --git a/Cargo.toml b/Cargo.toml index f6b4e19d3..cbd2deb69 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -280,7 +280,7 @@ filetime = "0.2" fnv = "1.0.7" fs_extra = "1.3.0" fts-sys = "0.2" -fundu = "1.1.0" +fundu = "1.2.0" gcd = "2.3" glob = "0.3.1" half = "2.2" diff --git a/src/uu/ls/src/ls.rs b/src/uu/ls/src/ls.rs index 8ddec03e1..ae19b133f 100644 --- a/src/uu/ls/src/ls.rs +++ b/src/uu/ls/src/ls.rs @@ -1202,6 +1202,7 @@ pub fn uu_app() -> Command { Arg::new(options::quoting::LITERAL) .short('N') .long(options::quoting::LITERAL) + .alias("l") .help("Use literal quoting style. Equivalent to `--quoting-style=literal`") .overrides_with_all([ options::QUOTING_STYLE, diff --git a/src/uu/nl/src/nl.rs b/src/uu/nl/src/nl.rs index 2e9bf92a0..ffb276f11 100644 --- a/src/uu/nl/src/nl.rs +++ b/src/uu/nl/src/nl.rs @@ -165,7 +165,7 @@ pub fn uu_app() -> Command { .short('b') .long(options::BODY_NUMBERING) .help("use STYLE for numbering body lines") - .value_name("SYNTAX"), + .value_name("STYLE"), ) .arg( Arg::new(options::SECTION_DELIMITER) diff --git a/src/uu/seq/src/error.rs b/src/uu/seq/src/error.rs index ae641a978..fc8452e13 100644 --- a/src/uu/seq/src/error.rs +++ b/src/uu/seq/src/error.rs @@ -2,7 +2,7 @@ // * // * For the full copyright and license information, please view the LICENSE // * file that was distributed with this source code. -// spell-checker:ignore numberparse argtype +// spell-checker:ignore numberparse //! Errors returned by seq. use std::error::Error; use std::fmt::Display; @@ -25,29 +25,11 @@ pub enum SeqError { /// The parameter is the increment argument as a [`String`] as read /// from the command line. ZeroIncrement(String), + + /// No arguments were passed to this function, 1 or more is required + NoArguments, } -impl SeqError { - /// The [`String`] argument as read from the command-line. - fn arg(&self) -> &str { - match self { - Self::ParseError(s, _) => s, - Self::ZeroIncrement(s) => s, - } - } - - /// The type of argument that is causing the error. - fn argtype(&self) -> &str { - match self { - Self::ParseError(_, e) => match e { - ParseNumberError::Float => "floating point argument", - ParseNumberError::Nan => "'not-a-number' argument", - ParseNumberError::Hex => "hexadecimal argument", - }, - Self::ZeroIncrement(_) => "Zero increment value", - } - } -} impl UError for SeqError { /// Always return 1. fn code(&self) -> i32 { @@ -63,6 +45,17 @@ impl Error for SeqError {} impl Display for SeqError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "invalid {}: {}", self.argtype(), self.arg().quote()) + match self { + Self::ParseError(s, e) => { + let error_type = match e { + ParseNumberError::Float => "floating point", + ParseNumberError::Nan => "'not-a-number'", + ParseNumberError::Hex => "hexadecimal", + }; + write!(f, "invalid {error_type} argument: {}", s.quote()) + } + Self::ZeroIncrement(s) => write!(f, "invalid Zero increment value: {}", s.quote()), + Self::NoArguments => write!(f, "missing operand"), + } } } diff --git a/src/uu/seq/src/seq.rs b/src/uu/seq/src/seq.rs index 4562ddb7d..2e55efa4a 100644 --- a/src/uu/seq/src/seq.rs +++ b/src/uu/seq/src/seq.rs @@ -58,10 +58,13 @@ type RangeFloat = (ExtendedBigDecimal, ExtendedBigDecimal, ExtendedBigDecimal); pub fn uumain(args: impl uucore::Args) -> UResult<()> { let matches = uu_app().try_get_matches_from(args)?; - let numbers = matches - .get_many::(ARG_NUMBERS) - .unwrap() - .collect::>(); + let numbers_option = matches.get_many::(ARG_NUMBERS); + + if numbers_option.is_none() { + return Err(SeqError::NoArguments.into()); + } + + let numbers = numbers_option.unwrap().collect::>(); let options = SeqOptions { separator: matches diff --git a/tests/by-util/test_ls.rs b/tests/by-util/test_ls.rs index f376cf53d..a6835f279 100644 --- a/tests/by-util/test_ls.rs +++ b/tests/by-util/test_ls.rs @@ -22,7 +22,6 @@ use std::time::Duration; const LONG_ARGS: &[&str] = &[ "-l", "--long", - "--l", "--format=long", "--for=long", "--format=verbose", @@ -2370,6 +2369,7 @@ fn test_ls_quoting_style() { ("--quoting-style=literal", "one?two"), ("-N", "one?two"), ("--literal", "one?two"), + ("--l", "one?two"), ("--quoting-style=c", "\"one\\ntwo\""), ("-Q", "\"one\\ntwo\""), ("--quote-name", "\"one\\ntwo\""), @@ -2394,6 +2394,7 @@ fn test_ls_quoting_style() { ("--quoting-style=literal", "one\ntwo"), ("-N", "one\ntwo"), ("--literal", "one\ntwo"), + ("--l", "one\ntwo"), ("--quoting-style=shell", "one\ntwo"), // FIXME: GNU ls quotes this case ("--quoting-style=shell-always", "'one\ntwo'"), ] { @@ -2455,6 +2456,7 @@ fn test_ls_quoting_style() { ("--quoting-style=literal", "one two"), ("-N", "one two"), ("--literal", "one two"), + ("--l", "one two"), ("--quoting-style=c", "\"one two\""), ("-Q", "\"one two\""), ("--quote-name", "\"one two\""), diff --git a/tests/by-util/test_seq.rs b/tests/by-util/test_seq.rs index 02509b3b5..de0781912 100644 --- a/tests/by-util/test_seq.rs +++ b/tests/by-util/test_seq.rs @@ -7,6 +7,14 @@ fn test_invalid_arg() { new_ucmd!().arg("--definitely-invalid").fails().code_is(1); } +#[test] +fn test_no_args() { + new_ucmd!() + .fails() + .code_is(1) + .stderr_contains("missing operand"); +} + #[test] fn test_hex_rejects_sign_after_identifier() { new_ucmd!()