1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 11:37:44 +00:00

split: add --verbose option

This commit is contained in:
Jeffrey Finkelstein 2022-01-15 23:04:46 -05:00
parent fd5310411e
commit 7af3007204
2 changed files with 32 additions and 2 deletions

View file

@ -230,7 +230,6 @@ impl Strategy {
} }
} }
#[allow(dead_code)]
struct Settings { struct Settings {
prefix: String, prefix: String,
numeric_suffix: bool, numeric_suffix: bool,
@ -240,7 +239,7 @@ struct Settings {
/// When supplied, a shell command to output to instead of xaa, xab … /// When supplied, a shell command to output to instead of xaa, xab …
filter: Option<String>, filter: Option<String>,
strategy: Strategy, strategy: Strategy,
verbose: bool, // TODO: warning: field is never read: `verbose` verbose: bool,
} }
trait Splitter { trait Splitter {
@ -396,6 +395,21 @@ fn split(settings: Settings) -> UResult<()> {
break; 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; fileno += 1;
} }
Ok(()) Ok(())

View file

@ -408,3 +408,19 @@ fn test_suffixes_exhausted() {
.fails() .fails()
.stderr_only("split: output file suffixes exhausted"); .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'
",
);
}