mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
Merge pull request #3591 from jhscheer/fix_3589
dircolors: add support for stdin "-" (fix: #3589)
This commit is contained in:
commit
c4c6d42f02
2 changed files with 27 additions and 6 deletions
|
@ -135,13 +135,15 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
|||
let result;
|
||||
if files.is_empty() {
|
||||
result = parse(INTERNAL_DB.lines(), &out_format, "");
|
||||
} else if files.len() > 1 {
|
||||
return Err(UUsageError::new(
|
||||
1,
|
||||
format!("extra operand {}", files[1].quote()),
|
||||
));
|
||||
} else if files[0].eq("-") {
|
||||
let fin = BufReader::new(std::io::stdin());
|
||||
result = parse(fin.lines().filter_map(Result::ok), &out_format, files[0]);
|
||||
} else {
|
||||
if files.len() > 1 {
|
||||
return Err(UUsageError::new(
|
||||
1,
|
||||
format!("extra operand {}", files[1].quote()),
|
||||
));
|
||||
}
|
||||
match File::open(files[0]) {
|
||||
Ok(f) => {
|
||||
let fin = BufReader::new(f);
|
||||
|
|
|
@ -131,6 +131,25 @@ fn test_exclusive_option() {
|
|||
.stderr_contains("mutually exclusive");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_stdin() {
|
||||
new_ucmd!()
|
||||
.pipe_in("owt 40;33\n")
|
||||
.args(&["-b", "-"])
|
||||
.succeeds()
|
||||
.stdout_is("LS_COLORS='tw=40;33:';\nexport LS_COLORS\n")
|
||||
.no_stderr();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_extra_operand() {
|
||||
new_ucmd!()
|
||||
.args(&["-c", "file1", "file2"])
|
||||
.fails()
|
||||
.stderr_contains("dircolors: extra operand 'file2'\n")
|
||||
.no_stdout();
|
||||
}
|
||||
|
||||
fn test_helper(file_name: &str, term: &str) {
|
||||
new_ucmd!()
|
||||
.env("TERM", term)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue