mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-27 19:17:43 +00:00
Merge pull request #1079 from shutefan/add-quiet-flag-to-tail
tail: suppress headers when --quiet flag is used
This commit is contained in:
commit
618531b366
3 changed files with 33 additions and 6 deletions
|
@ -79,6 +79,8 @@ pub fn uumain(args: Vec<String>) -> i32 {
|
|||
opts.optflag("h", "help", "help");
|
||||
opts.optflag("V", "version", "version");
|
||||
opts.optflag("v", "verbose", "always output headers giving file names");
|
||||
// TODO: --silent flag as alias to --quiet
|
||||
opts.optflag("q", "quiet", "never output headers giving file names");
|
||||
|
||||
let given_options = match opts.parse(&args) {
|
||||
Ok (m) => { m }
|
||||
|
@ -165,6 +167,7 @@ pub fn uumain(args: Vec<String>) -> i32 {
|
|||
}
|
||||
|
||||
let verbose = given_options.opt_present("v");
|
||||
let quiet = given_options.opt_present("q");
|
||||
|
||||
let files = given_options.free;
|
||||
|
||||
|
@ -172,16 +175,12 @@ pub fn uumain(args: Vec<String>) -> i32 {
|
|||
let mut buffer = BufReader::new(stdin());
|
||||
unbounded_tail(&mut buffer, &settings);
|
||||
} else {
|
||||
let mut multiple = false;
|
||||
let multiple = files.len() > 1;
|
||||
let mut first_header = true;
|
||||
let mut readers = Vec::new();
|
||||
|
||||
if files.len() > 1 {
|
||||
multiple = true;
|
||||
}
|
||||
|
||||
for filename in &files {
|
||||
if multiple || verbose {
|
||||
if (multiple || verbose) && !quiet {
|
||||
if !first_header { println!(""); }
|
||||
println!("==> {} <==", filename);
|
||||
}
|
||||
|
|
12
tests/fixtures/tail/foobar_multiple_quiet.expected
vendored
Normal file
12
tests/fixtures/tail/foobar_multiple_quiet.expected
vendored
Normal file
|
@ -0,0 +1,12 @@
|
|||
dos
|
||||
tres
|
||||
quattro
|
||||
cinco
|
||||
seis
|
||||
siette
|
||||
ocho
|
||||
nueve
|
||||
diez
|
||||
once
|
||||
un
|
||||
deux
|
|
@ -245,3 +245,19 @@ fn test_lines_with_size_suffix() {
|
|||
|
||||
ucmd.arg(FILE).arg("-n").arg("2K").run().stdout_is_fixture(EXPECTED_FILE);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_multiple_input_files() {
|
||||
new_ucmd!().arg(FOOBAR_TXT).arg(FOOBAR_2_TXT).run().stdout_is_fixture("foobar_follow_multiple.expected");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_multiple_input_files_with_suppressed_headers() {
|
||||
new_ucmd!().arg(FOOBAR_TXT).arg(FOOBAR_2_TXT).arg("-q").run().stdout_is_fixture("foobar_multiple_quiet.expected");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_multiple_input_quiet_flag_overrides_verbose_flag_for_suppressing_headers() {
|
||||
// TODO: actually the later one should win, i.e. -qv should lead to headers being printed, -vq to them being suppressed
|
||||
new_ucmd!().arg(FOOBAR_TXT).arg(FOOBAR_2_TXT).arg("-q").arg("-v").run().stdout_is_fixture("foobar_multiple_quiet.expected");
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue