@@ -35,8 +35,8 @@ void main(List<String> args) {
3535 if (verbose > 1 ) {
3636 stdout.writeln ('Verbosity: $verbose ' );
3737 }
38- if (verbose > 0 ) {
39- if (dryRun || verbose > 1 ) stdout.writeln ('Dry-run: $dryRun ' );
38+ if (verbose > 1 || (dryRun && verbose > 0 ) ) {
39+ stdout.writeln ('Dry-run: $dryRun ' );
4040 }
4141
4242 if (experimentsFile == null ) {
@@ -148,19 +148,19 @@ class Updater {
148148 final Version currentVersion;
149149 final int verbose;
150150 final Map <String , Version ?> experiments;
151- final FileCache files;
151+ final FileEditor files;
152152 Updater (
153153 this .root,
154154 this .currentVersion,
155155 this .experiments, {
156156 this .verbose = 0 ,
157157 bool dryRun = false ,
158- }) : files = FileCache (verbose: verbose, dryRun: dryRun);
158+ }) : files = FileEditor (verbose: verbose - 1 , dryRun: dryRun);
159159
160160 void run () {
161161 _updatePubspec ();
162162 _updateTests ();
163- files.flushSaves ();
163+ files.flushChanges ();
164164 }
165165
166166 bool _updatePubspec () {
@@ -331,17 +331,29 @@ Map<String, Version?> _parseExperiments(File experimentsFile) {
331331}
332332
333333// --------------------------------------------------------------------
334- // File system abstraction which caches changes, so they can be written
335- // atomically at the end.
334+ // File system abstraction which caches changes to text files,
335+ // so they can be written atomically at the end.
336336
337- class FileCache {
337+ /// Cached edits of text files.
338+ ///
339+ /// Use [edit] to edit a text file and return the new content.
340+ /// Changes are cached and given to later edits of the same file.
341+ ///
342+ /// Changed files can be flushed to disk using [flushChanges] .
343+ ///
344+ /// If [verbose] is positive, operations may print information
345+ /// about what they do.
346+ ///
347+ /// If [dryRun] is `true` , [flushChanges] does nothing, other than print
348+ /// what it would have done.
349+ class FileEditor {
338350 final int verbose;
339351 final bool dryRun;
340352 // Contains string if it has been changed.
341353 // Contains `null` if currently being edited.
342354 final Map <File , String ?> _cache = {};
343355
344- FileCache ({this .verbose = 0 , this .dryRun = false });
356+ FileEditor ({this .verbose = 0 , this .dryRun = false });
345357
346358 /// Edit file with the given [path] .
347359 ///
@@ -354,7 +366,7 @@ class FileCache {
354366 ///
355367 /// Returns whether the file content changed.
356368 bool edit (File path, String ? Function (String content) editor) {
357- if (verbose > 1 ) {
369+ if (verbose > 0 ) {
358370 var fromString = ' from ${_cache .containsKey (path ) ? 'cache' : 'disk' }' ;
359371 stdout.writeln ('Loading ${path .path }$fromString .' );
360372 }
@@ -376,11 +388,11 @@ class FileCache {
376388 change = newContent != null && newContent != content;
377389 } finally {
378390 // No change if function threw, or if it returned `null` or `content`.
379- if (verbose > 1 ) {
391+ if (verbose > 0 ) {
380392 if (change) {
381393 var first = (existingContent == null ) ? '' : ', first change to file' ;
382394 stdout.writeln ('Saving changes to ${path .path }$first .' );
383- } else if (verbose > 2 ) {
395+ } else if (verbose > 1 ) {
384396 stdout.writeln ('No changes to ${path .path }' );
385397 }
386398 }
@@ -399,7 +411,7 @@ class FileCache {
399411 /// Saves all cached file changes to disk.
400412 ///
401413 /// Does nothing if dry-running.
402- void flushSaves () {
414+ void flushChanges () {
403415 var count = 0 ;
404416 var prefix = dryRun ? 'Dry-run: ' : '' ;
405417 for (var file in [..._cache.keys]) {
0 commit comments