mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
Merge pull request #7991 from RenjiSann/sort-multiple-outputs
sort: prevent -o/--output to be specified multiple times
This commit is contained in:
commit
be77e142aa
2 changed files with 23 additions and 1 deletions
|
@ -156,6 +156,9 @@ pub enum SortError {
|
||||||
|
|
||||||
#[error("{error}")]
|
#[error("{error}")]
|
||||||
Uft8Error { error: Utf8Error },
|
Uft8Error { error: Utf8Error },
|
||||||
|
|
||||||
|
#[error("multiple output files specified")]
|
||||||
|
MultipleOutputFiles,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl UError for SortError {
|
impl UError for SortError {
|
||||||
|
@ -1034,6 +1037,14 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Prevent -o/--output to be specified multiple times
|
||||||
|
if matches
|
||||||
|
.get_occurrences::<String>(options::OUTPUT)
|
||||||
|
.is_some_and(|out| out.len() > 1)
|
||||||
|
{
|
||||||
|
return Err(SortError::MultipleOutputFiles.into());
|
||||||
|
}
|
||||||
|
|
||||||
settings.debug = matches.get_flag(options::DEBUG);
|
settings.debug = matches.get_flag(options::DEBUG);
|
||||||
|
|
||||||
// check whether user specified a zero terminated list of files for input, otherwise read files from args
|
// check whether user specified a zero terminated list of files for input, otherwise read files from args
|
||||||
|
@ -1427,7 +1438,9 @@ pub fn uu_app() -> Command {
|
||||||
.long(options::OUTPUT)
|
.long(options::OUTPUT)
|
||||||
.help("write output to FILENAME instead of stdout")
|
.help("write output to FILENAME instead of stdout")
|
||||||
.value_name("FILENAME")
|
.value_name("FILENAME")
|
||||||
.value_hint(clap::ValueHint::FilePath),
|
.value_hint(clap::ValueHint::FilePath)
|
||||||
|
// To detect multiple occurrences and raise an error
|
||||||
|
.action(ArgAction::Append),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new(options::REVERSE)
|
Arg::new(options::REVERSE)
|
||||||
|
|
|
@ -1345,3 +1345,12 @@ fn test_failed_write_is_reported() {
|
||||||
.fails()
|
.fails()
|
||||||
.stderr_is("sort: write failed: 'standard output': No space left on device\n");
|
.stderr_is("sort: write failed: 'standard output': No space left on device\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
// Test for GNU tests/sort/sort.pl "o2"
|
||||||
|
fn test_multiple_output_files() {
|
||||||
|
new_ucmd!()
|
||||||
|
.args(&["-o", "foo", "-o", "bar"])
|
||||||
|
.fails_with_code(2)
|
||||||
|
.stderr_is("sort: multiple output files specified\n");
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue