Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/uu/sort/locales/en-US.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
1 change: 1 addition & 0 deletions src/uu/sort/locales/fr-FR.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
12 changes: 11 additions & 1 deletion src/uu/sort/src/sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand Down Expand Up @@ -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::<String>(&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::<OsString>(&matches, options::SEPARATOR) {
Expand Down Expand Up @@ -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)
Expand Down
18 changes: 18 additions & 0 deletions tests/by-util/test_sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
Loading