From 7af300720420d3c9ccb1d8224462c5403813084e Mon Sep 17 00:00:00 2001 From: Jeffrey Finkelstein Date: Sat, 15 Jan 2022 23:04:46 -0500 Subject: [PATCH] split: add --verbose option --- src/uu/split/src/split.rs | 18 ++++++++++++++++-- tests/by-util/test_split.rs | 16 ++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src/uu/split/src/split.rs b/src/uu/split/src/split.rs index b0610189f..04ee3641c 100644 --- a/src/uu/split/src/split.rs +++ b/src/uu/split/src/split.rs @@ -230,7 +230,6 @@ impl Strategy { } } -#[allow(dead_code)] struct Settings { prefix: String, numeric_suffix: bool, @@ -240,7 +239,7 @@ struct Settings { /// When supplied, a shell command to output to instead of xaa, xab … filter: Option, strategy: Strategy, - verbose: bool, // TODO: warning: field is never read: `verbose` + verbose: bool, } trait Splitter { @@ -396,6 +395,21 @@ fn split(settings: Settings) -> UResult<()> { break; } + // TODO It is silly to have the "creating file" message here + // after the file has been already created. However, because + // of the way the main loop has been written, an extra file + // gets created and then deleted in the last iteration of the + // loop. So we need to make sure we are not in that case when + // printing this message. + // + // This is only here temporarily while we make some + // improvements to the architecture of the main loop in this + // function. In the future, it will move to a more appropriate + // place---at the point where the file is actually created. + if settings.verbose { + println!("creating file {}", filename.quote()); + } + fileno += 1; } Ok(()) diff --git a/tests/by-util/test_split.rs b/tests/by-util/test_split.rs index 2cace29ad..ebcc0926d 100644 --- a/tests/by-util/test_split.rs +++ b/tests/by-util/test_split.rs @@ -408,3 +408,19 @@ fn test_suffixes_exhausted() { .fails() .stderr_only("split: output file suffixes exhausted"); } + +#[test] +fn test_verbose() { + new_ucmd!() + .args(&["-b", "5", "--verbose", "asciilowercase.txt"]) + .succeeds() + .stdout_only( + "creating file 'xaa' +creating file 'xab' +creating file 'xac' +creating file 'xad' +creating file 'xae' +creating file 'xaf' +", + ); +}