Skip to content

Commit

Permalink
Merge pull request #6955 from cakebaker/bump_clap
Browse files Browse the repository at this point in the history
Bump `clap` to `4.5.23` & fix failing `seq` tests
  • Loading branch information
sylvestre authored Dec 15, 2024
2 parents 5007bf2 + a8ad6d9 commit aea13ed
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 26 deletions.
41 changes: 24 additions & 17 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ chrono = { version = "0.4.38", default-features = false, features = [
"alloc",
"clock",
] }
clap = { version = "4.4", features = ["wrap_help", "cargo"] }
clap = { version = "4.5", features = ["wrap_help", "cargo"] }
clap_complete = "4.4"
clap_mangen = "0.2"
compare = "0.1.0"
Expand Down
31 changes: 29 additions & 2 deletions src/uu/seq/src/seq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.
// spell-checker:ignore (ToDO) extendedbigdecimal numberparse
use std::ffi::OsString;
use std::io::{stdout, ErrorKind, Write};

use clap::{crate_version, Arg, ArgAction, Command};
Expand Down Expand Up @@ -47,9 +48,33 @@ struct SeqOptions<'a> {
/// The elements are (first, increment, last).
type RangeFloat = (ExtendedBigDecimal, ExtendedBigDecimal, ExtendedBigDecimal);

// Turn short args with attached value, for example "-s,", into two args "-s" and "," to make
// them work with clap.
fn split_short_args_with_value(args: impl uucore::Args) -> impl uucore::Args {
let mut v: Vec<OsString> = Vec::new();

for arg in args {
let bytes = arg.as_encoded_bytes();

if bytes.len() > 2
&& (bytes.starts_with(b"-f") || bytes.starts_with(b"-s") || bytes.starts_with(b"-t"))
{
let (short_arg, value) = bytes.split_at(2);
// SAFETY:
// Both `short_arg` and `value` only contain content that originated from `OsStr::as_encoded_bytes`
v.push(unsafe { OsString::from_encoded_bytes_unchecked(short_arg.to_vec()) });
v.push(unsafe { OsString::from_encoded_bytes_unchecked(value.to_vec()) });
} else {
v.push(arg);
}
}

v.into_iter()
}

#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().try_get_matches_from(args)?;
let matches = uu_app().try_get_matches_from(split_short_args_with_value(args))?;

let numbers_option = matches.get_many::<String>(ARG_NUMBERS);

Expand Down Expand Up @@ -138,7 +163,6 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
pub fn uu_app() -> Command {
Command::new(uucore::util_name())
.trailing_var_arg(true)
.allow_negative_numbers(true)
.infer_long_args(true)
.version(crate_version!())
.about(ABOUT)
Expand Down Expand Up @@ -169,7 +193,10 @@ pub fn uu_app() -> Command {
.help("use printf style floating-point FORMAT"),
)
.arg(
// we use allow_hyphen_values instead of allow_negative_numbers because clap removed
// the support for "exotic" negative numbers like -.1 (see https://github.com/clap-rs/clap/discussions/5837)
Arg::new(ARG_NUMBERS)
.allow_hyphen_values(true)
.action(ArgAction::Append)
.num_args(1..=3),
)
Expand Down
4 changes: 2 additions & 2 deletions tests/by-util/test_seq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ fn test_hex_rejects_sign_after_identifier() {
.args(&["-0x-123ABC"])
.fails()
.no_stdout()
.stderr_contains("unexpected argument '-0' found");
.usage_error("invalid floating point argument: '-0x-123ABC'");
new_ucmd!()
.args(&["-0x+123ABC"])
.fails()
.no_stdout()
.stderr_contains("unexpected argument '-0' found");
.usage_error("invalid floating point argument: '-0x+123ABC'");
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion util/build-gnu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ sed -i -e "s|mv: cannot overwrite 'a/t': Directory not empty|mv: cannot move 'b/
# disable these test cases
sed -i -E "s|^([^#]*2_31.*)$|#\1|g" tests/printf/printf-cov.pl

sed -i -e "s/du: invalid -t argument/du: invalid --threshold argument/" -e "s/du: option requires an argument/error: a value is required for '--threshold <SIZE>' but none was supplied/" -e "/Try 'du --help' for more information./d" tests/du/threshold.sh
sed -i -e "s/du: invalid -t argument/du: invalid --threshold argument/" -e "s/du: option requires an argument/error: a value is required for '--threshold <SIZE>' but none was supplied/" -e "s/Try 'du --help' for more information./\nFor more information, try '--help'./" tests/du/threshold.sh

# Remove the extra output check
sed -i -e "s|Try '\$prog --help' for more information.\\\n||" tests/du/files0-from.pl
Expand Down
7 changes: 4 additions & 3 deletions util/gnu-patches/tests_factor_factor.pl.patch
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
diff --git a/tests/factor/factor.pl b/tests/factor/factor.pl
index 6e612e418..f19c06ca0 100755
index b1406c266..3d97cd6a5 100755
--- a/tests/factor/factor.pl
+++ b/tests/factor/factor.pl
@@ -61,12 +61,13 @@ my @Tests =
@@ -61,12 +61,14 @@ my @Tests =
# Map newer glibc diagnostic to expected.
# Also map OpenBSD 5.1's "unknown option" to expected "invalid option".
{ERR_SUBST => q!s/'1'/1/;s/unknown/invalid/!},
- {ERR => "$prog: invalid option -- 1\n"
- . "Try '$prog --help' for more information.\n"},
+ {ERR => "error: unexpected argument '-1' found\n\n"
+ . " tip: to pass '-1' as a value, use '-- -1'\n\n"
+ . "Usage: factor [OPTION]... [NUMBER]...\n"},
+ . "Usage: factor [OPTION]... [NUMBER]...\n\n"
+ . "For more information, try '--help'.\n"},
{EXIT => 1}],
['cont', 'a 4',
{OUT => "4: 2 2\n"},
Expand Down

0 comments on commit aea13ed

Please sign in to comment.