Merge pull request #2872 from jfinkels/split-verbose

split: add --verbose option
This commit is contained in:
Sylvestre Ledru 2022-01-16 23:19:30 +01:00 committed by GitHub
commit 516bdfcfd5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 2 deletions

View file

@ -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<String>,
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(())

View file

@ -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'
",
);
}