Skip to content

Commit

Permalink
dircolors: add support for stdin "-" (fix: #3589)
Browse files Browse the repository at this point in the history
  • Loading branch information
jhscheer committed Jun 3, 2022
1 parent 68cc931 commit f1b38e9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/uu/dircolors/src/dircolors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 10 additions & 0 deletions tests/by-util/test_dircolors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,16 @@ 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();
}

fn test_helper(file_name: &str, term: &str) {
new_ucmd!()
.env("TERM", term)
Expand Down

0 comments on commit f1b38e9

Please sign in to comment.