Skip to content

Commit aea13ed

Browse files
authored
Merge pull request #6955 from cakebaker/bump_clap
Bump `clap` to `4.5.23` & fix failing `seq` tests
2 parents 5007bf2 + a8ad6d9 commit aea13ed

File tree

6 files changed

+61
-26
lines changed

6 files changed

+61
-26
lines changed

Cargo.lock

Lines changed: 24 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ chrono = { version = "0.4.38", default-features = false, features = [
276276
"alloc",
277277
"clock",
278278
] }
279-
clap = { version = "4.4", features = ["wrap_help", "cargo"] }
279+
clap = { version = "4.5", features = ["wrap_help", "cargo"] }
280280
clap_complete = "4.4"
281281
clap_mangen = "0.2"
282282
compare = "0.1.0"

src/uu/seq/src/seq.rs

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// For the full copyright and license information, please view the LICENSE
44
// file that was distributed with this source code.
55
// spell-checker:ignore (ToDO) extendedbigdecimal numberparse
6+
use std::ffi::OsString;
67
use std::io::{stdout, ErrorKind, Write};
78

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

51+
// Turn short args with attached value, for example "-s,", into two args "-s" and "," to make
52+
// them work with clap.
53+
fn split_short_args_with_value(args: impl uucore::Args) -> impl uucore::Args {
54+
let mut v: Vec<OsString> = Vec::new();
55+
56+
for arg in args {
57+
let bytes = arg.as_encoded_bytes();
58+
59+
if bytes.len() > 2
60+
&& (bytes.starts_with(b"-f") || bytes.starts_with(b"-s") || bytes.starts_with(b"-t"))
61+
{
62+
let (short_arg, value) = bytes.split_at(2);
63+
// SAFETY:
64+
// Both `short_arg` and `value` only contain content that originated from `OsStr::as_encoded_bytes`
65+
v.push(unsafe { OsString::from_encoded_bytes_unchecked(short_arg.to_vec()) });
66+
v.push(unsafe { OsString::from_encoded_bytes_unchecked(value.to_vec()) });
67+
} else {
68+
v.push(arg);
69+
}
70+
}
71+
72+
v.into_iter()
73+
}
74+
5075
#[uucore::main]
5176
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
52-
let matches = uu_app().try_get_matches_from(args)?;
77+
let matches = uu_app().try_get_matches_from(split_short_args_with_value(args))?;
5378

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

@@ -138,7 +163,6 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
138163
pub fn uu_app() -> Command {
139164
Command::new(uucore::util_name())
140165
.trailing_var_arg(true)
141-
.allow_negative_numbers(true)
142166
.infer_long_args(true)
143167
.version(crate_version!())
144168
.about(ABOUT)
@@ -169,7 +193,10 @@ pub fn uu_app() -> Command {
169193
.help("use printf style floating-point FORMAT"),
170194
)
171195
.arg(
196+
// we use allow_hyphen_values instead of allow_negative_numbers because clap removed
197+
// the support for "exotic" negative numbers like -.1 (see https://github.com/clap-rs/clap/discussions/5837)
172198
Arg::new(ARG_NUMBERS)
199+
.allow_hyphen_values(true)
173200
.action(ArgAction::Append)
174201
.num_args(1..=3),
175202
)

tests/by-util/test_seq.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,12 @@ fn test_hex_rejects_sign_after_identifier() {
4848
.args(&["-0x-123ABC"])
4949
.fails()
5050
.no_stdout()
51-
.stderr_contains("unexpected argument '-0' found");
51+
.usage_error("invalid floating point argument: '-0x-123ABC'");
5252
new_ucmd!()
5353
.args(&["-0x+123ABC"])
5454
.fails()
5555
.no_stdout()
56-
.stderr_contains("unexpected argument '-0' found");
56+
.usage_error("invalid floating point argument: '-0x+123ABC'");
5757
}
5858

5959
#[test]

util/build-gnu.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ sed -i -e "s|mv: cannot overwrite 'a/t': Directory not empty|mv: cannot move 'b/
314314
# disable these test cases
315315
sed -i -E "s|^([^#]*2_31.*)$|#\1|g" tests/printf/printf-cov.pl
316316

317-
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
317+
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
318318

319319
# Remove the extra output check
320320
sed -i -e "s|Try '\$prog --help' for more information.\\\n||" tests/du/files0-from.pl

util/gnu-patches/tests_factor_factor.pl.patch

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
diff --git a/tests/factor/factor.pl b/tests/factor/factor.pl
2-
index 6e612e418..f19c06ca0 100755
2+
index b1406c266..3d97cd6a5 100755
33
--- a/tests/factor/factor.pl
44
+++ b/tests/factor/factor.pl
5-
@@ -61,12 +61,13 @@ my @Tests =
5+
@@ -61,12 +61,14 @@ my @Tests =
66
# Map newer glibc diagnostic to expected.
77
# Also map OpenBSD 5.1's "unknown option" to expected "invalid option".
88
{ERR_SUBST => q!s/'1'/1/;s/unknown/invalid/!},
99
- {ERR => "$prog: invalid option -- 1\n"
1010
- . "Try '$prog --help' for more information.\n"},
1111
+ {ERR => "error: unexpected argument '-1' found\n\n"
1212
+ . " tip: to pass '-1' as a value, use '-- -1'\n\n"
13-
+ . "Usage: factor [OPTION]... [NUMBER]...\n"},
13+
+ . "Usage: factor [OPTION]... [NUMBER]...\n\n"
14+
+ . "For more information, try '--help'.\n"},
1415
{EXIT => 1}],
1516
['cont', 'a 4',
1617
{OUT => "4: 2 2\n"},

0 commit comments

Comments
 (0)