added cleanContext (#93264)

* added cleanContext

* using async

* added one more test
This commit is contained in:
Alex
2021-11-08 17:34:03 -05:00
committed by GitHub
parent 550281e581
commit 9c1a87e627
2 changed files with 42 additions and 12 deletions

View File

@@ -49,12 +49,11 @@ class CleanCommand extends Command<void> {
'This will abort a work in progress release.';
@override
void run() {
Future<void> run() {
final ArgResults argumentResults = argResults!;
final File stateFile = checkouts.fileSystem.file(argumentResults[kStateOption]);
if (!stateFile.existsSync()) {
throw ConductorException(
'No persistent state file found at ${stateFile.path}!');
throw ConductorException('No persistent state file found at ${stateFile.path}!');
}
if (!(argumentResults[kYesFlag] as bool)) {
@@ -67,10 +66,28 @@ class CleanCommand extends Command<void> {
// Only proceed if the first character of stdin is 'y' or 'Y'
if (response.isEmpty || response[0].toLowerCase() != 'y') {
stdio.printStatus('Aborting clean operation.');
return;
}
}
stdio.printStatus('Deleting persistent state file ${stateFile.path}...');
stateFile.deleteSync();
final RunContext context = RunContext(
stateFile: stateFile,
);
return context.run();
}
}
/// Context for cleaning up persistent state file.
///
/// This is a frontend-agnostic implementation.
class RunContext {
RunContext({
required this.stateFile,
});
final File stateFile;
Future<void> run() {
return stateFile.delete();
}
}