From 0b06f2b4a8543a014afa15927728d16d9ba38eca Mon Sep 17 00:00:00 2001 From: Nikolai Date: Wed, 19 Apr 2023 05:06:32 +0100 Subject: [PATCH 1/7] fixing seq panic on none --- src/uu/seq/src/error.rs | 24 +++++++++++++++++++----- src/uu/seq/src/seq.rs | 11 +++++++---- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/src/uu/seq/src/error.rs b/src/uu/seq/src/error.rs index ae641a978..ad6b5733a 100644 --- a/src/uu/seq/src/error.rs +++ b/src/uu/seq/src/error.rs @@ -25,6 +25,9 @@ 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 { @@ -33,6 +36,7 @@ impl SeqError { match self { Self::ParseError(s, _) => s, Self::ZeroIncrement(s) => s, + Self::NoArguments => "", } } @@ -40,11 +44,12 @@ impl SeqError { 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", + ParseNumberError::Float => "invalid floating point argument: ", + ParseNumberError::Nan => "invalid 'not-a-number' argument: ", + ParseNumberError::Hex => "invalid hexadecimal argument: ", }, - Self::ZeroIncrement(_) => "Zero increment value", + Self::ZeroIncrement(_) => "invalid Zero increment value: ", + Self::NoArguments => "missing operand", } } } @@ -63,6 +68,15 @@ 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()) + write!( + f, + "{}{}", + self.argtype(), + if self.arg() != "" { + self.arg().quote().to_string() + } else { + "".to_string() + } + ) } } diff --git a/src/uu/seq/src/seq.rs b/src/uu/seq/src/seq.rs index 97382ed1b..44e0a7744 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 From 644fd1c93ed38a0752380f111c93b9c7b6ff6256 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Sun, 25 Jun 2023 22:29:08 +0200 Subject: [PATCH 2/7] fix some clippy warnings --- src/uu/seq/src/error.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/uu/seq/src/error.rs b/src/uu/seq/src/error.rs index ad6b5733a..4945914d1 100644 --- a/src/uu/seq/src/error.rs +++ b/src/uu/seq/src/error.rs @@ -72,10 +72,10 @@ impl Display for SeqError { f, "{}{}", self.argtype(), - if self.arg() != "" { - self.arg().quote().to_string() + if self.arg() == "" { + String::new() } else { - "".to_string() + self.arg().quote().to_string() } ) } From 98264e9cdf62cc891c5cfeaac8f20c8f3a04848e Mon Sep 17 00:00:00 2001 From: Daniel Hofstetter Date: Wed, 5 Jul 2023 15:51:23 +0200 Subject: [PATCH 3/7] seq: add test for call without args --- tests/by-util/test_seq.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/by-util/test_seq.rs b/tests/by-util/test_seq.rs index 63015b24a..187e7533f 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!() From ac4ff2ac0e3056550c292a5e862eb3e1aaa2480a Mon Sep 17 00:00:00 2001 From: Daniel Hofstetter Date: Thu, 6 Jul 2023 10:26:29 +0200 Subject: [PATCH 4/7] seq: simplify error handling Co-authored-by: Terts Diepraam --- src/uu/seq/src/error.rs | 45 +++++++++++------------------------------ 1 file changed, 12 insertions(+), 33 deletions(-) diff --git a/src/uu/seq/src/error.rs b/src/uu/seq/src/error.rs index 4945914d1..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; @@ -30,29 +30,6 @@ pub enum SeqError { 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, - Self::NoArguments => "", - } - } - - /// The type of argument that is causing the error. - fn argtype(&self) -> &str { - match self { - Self::ParseError(_, e) => match e { - ParseNumberError::Float => "invalid floating point argument: ", - ParseNumberError::Nan => "invalid 'not-a-number' argument: ", - ParseNumberError::Hex => "invalid hexadecimal argument: ", - }, - Self::ZeroIncrement(_) => "invalid Zero increment value: ", - Self::NoArguments => "missing operand", - } - } -} impl UError for SeqError { /// Always return 1. fn code(&self) -> i32 { @@ -68,15 +45,17 @@ impl Error for SeqError {} impl Display for SeqError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!( - f, - "{}{}", - self.argtype(), - if self.arg() == "" { - String::new() - } else { - self.arg().quote().to_string() + 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"), + } } } From cf6f7856e45c84acfad56c14f1b4174a1bc0d963 Mon Sep 17 00:00:00 2001 From: yt2b Date: Sat, 8 Jul 2023 10:43:20 +0900 Subject: [PATCH 5/7] ls: fix --l option --- src/uu/ls/src/ls.rs | 1 + tests/by-util/test_ls.rs | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/uu/ls/src/ls.rs b/src/uu/ls/src/ls.rs index 342c52cba..f45fa0cd6 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/tests/by-util/test_ls.rs b/tests/by-util/test_ls.rs index ad2c6424f..2eef69121 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", @@ -2411,6 +2410,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\""), @@ -2435,6 +2435,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'"), ] { @@ -2496,6 +2497,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\""), From bc25b5156760300c9b48c2f5cf7d675807e8aea4 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sun, 9 Jul 2023 12:08:10 +0000 Subject: [PATCH 6/7] chore(deps): update rust crate fundu to 1.2.0 --- Cargo.lock | 8 ++++---- Cargo.toml | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) 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" From f67ef7fb1176111f85e9f2b8aea335459b0d9786 Mon Sep 17 00:00:00 2001 From: Daniel Hofstetter Date: Sun, 9 Jul 2023 16:08:38 +0200 Subject: [PATCH 7/7] nl: change value name to match help text --- src/uu/nl/src/nl.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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)