diff --git a/src/uu/sort/locales/en-US.ftl b/src/uu/sort/locales/en-US.ftl index d951a1c3736..bae3efeecf3 100644 --- a/src/uu/sort/locales/en-US.ftl +++ b/src/uu/sort/locales/en-US.ftl @@ -24,6 +24,7 @@ sort-file-operands-combined = extra operand {$file} file operands cannot be combined with --files0-from Try '{$help} --help' for more information. sort-multiple-output-files = multiple output files specified +sort-multiple-compress-programs = multiple compress programs specified sort-incompatible-tabs = incompatible tabs sort-minus-in-stdin = when reading file names from standard input, no file name of '-' allowed sort-no-input-from = no input from {$file} diff --git a/src/uu/sort/locales/fr-FR.ftl b/src/uu/sort/locales/fr-FR.ftl index f891ee1910b..6a00e99b9bd 100644 --- a/src/uu/sort/locales/fr-FR.ftl +++ b/src/uu/sort/locales/fr-FR.ftl @@ -24,6 +24,7 @@ sort-file-operands-combined = opérande supplémentaire {$file} les opérandes de fichier ne peuvent pas être combinées avec --files0-from Essayez '{$help} --help' pour plus d'informations. sort-multiple-output-files = plusieurs fichiers de sortie spécifiés +sort-multiple-compress-programs = plusieurs programmes de compression spécifiés sort-incompatible-tabs = tabulations incompatibles sort-minus-in-stdin = lors de la lecture des noms de fichiers depuis l'entrée standard, aucun nom de fichier '-' n'est autorisé sort-no-input-from = aucune entrée depuis {$file} diff --git a/src/uu/sort/src/sort.rs b/src/uu/sort/src/sort.rs index 34a5bd61184..215b186e247 100644 --- a/src/uu/sort/src/sort.rs +++ b/src/uu/sort/src/sort.rs @@ -185,6 +185,9 @@ pub enum SortError { #[error("{}", translate!("sort-multiple-output-files"))] MultipleOutputFiles, + #[error("{}", translate!("sort-multiple-compress-programs"))] + MultipleCompressPrograms, + #[error("{}", translate!("sort-incompatible-tabs"))] IncompatibleTabs, @@ -2179,6 +2182,11 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { return Err(SortError::MultipleOutputFiles.into()); } + // Same as -o: repeating --compress-program is fine as long as the value is the same + if has_conflicting_values::(&matches, options::COMPRESS_PROG) { + return Err(SortError::MultipleCompressPrograms.into()); + } + // Prevent -t/--field-separator from being given different values. Raw // values suffice: `\0` is the only spelling rewritten later, and argv cannot hold a NUL. if has_conflicting_values::(&matches, options::SEPARATOR) { @@ -2725,7 +2733,9 @@ pub fn uu_app() -> Command { .long(options::COMPRESS_PROG) .help(translate!("sort-help-compress-prog")) .value_name("PROG") - .value_hint(clap::ValueHint::CommandName), + .value_hint(clap::ValueHint::CommandName) + // To detect multiple occurrences and raise an error + .action(ArgAction::Append), ) .arg( Arg::new(options::BATCH_SIZE) diff --git a/tests/by-util/test_sort.rs b/tests/by-util/test_sort.rs index c309ad5b29e..afaac8dfc77 100644 --- a/tests/by-util/test_sort.rs +++ b/tests/by-util/test_sort.rs @@ -2448,6 +2448,24 @@ fn test_same_output_flag_twice_ok() { .no_stderr(); } +#[test] +fn test_error_on_multiple_compress_programs() { + new_ucmd!() + .args(&["--compress-program", "pwd", "--compress-program", "python3"]) + .fails_with_code(2) + .stderr_only("sort: multiple compress programs specified\n"); +} + +#[test] +fn test_same_compress_program_twice_ok() { + // The input is far below the buffer size, so the program is never spawned. + new_ucmd!() + .args(&["--compress-program", "gzip", "--compress-program", "gzip"]) + .pipe_in("b\na\n") + .succeeds() + .stdout_only("a\nb\n"); +} + #[test] fn test_output_file_with_leading_dash() { let test_cases = [