1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 03:27:44 +00:00

Merge pull request #7646 from drinkcat/seq-w-f

seq: Do not allow -w and -f to be specified at the same time
This commit is contained in:
Sylvestre Ledru 2025-04-04 10:56:47 +02:00 committed by GitHub
commit 97fb15b02d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 16 additions and 0 deletions

View file

@ -28,6 +28,10 @@ pub enum SeqError {
/// No arguments were passed to this function, 1 or more is required
#[error("missing operand")]
NoArguments,
/// Both a format and equal width where passed to seq
#[error("format string may not be specified when printing equal width strings")]
FormatAndEqualWidth,
}
fn parse_error_type(e: &ParseNumberError) -> &'static str {

View file

@ -114,6 +114,10 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
format: matches.get_one::<String>(OPT_FORMAT).map(|s| s.as_str()),
};
if options.equal_width && options.format.is_some() {
return Err(SeqError::FormatAndEqualWidth.into());
}
let first = if numbers.len() > 1 {
match numbers[0].parse() {
Ok(num) => num,

View file

@ -19,6 +19,14 @@ fn test_no_args() {
.stderr_contains("missing operand");
}
#[test]
fn test_format_and_equal_width() {
new_ucmd!()
.args(&["-w", "-f", "%f", "1"])
.fails_with_code(1)
.stderr_contains("format string may not be specified");
}
#[test]
fn test_hex_rejects_sign_after_identifier() {
new_ucmd!()