Unverified Commit f5672b93 authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

add --force flag to precache (#31278)

parent b275e111
......@@ -13,6 +13,8 @@ class PrecacheCommand extends FlutterCommand {
PrecacheCommand() {
argParser.addFlag('all-platforms', abbr: 'a', negatable: false,
help: 'Precache artifacts for all platforms.');
argParser.addFlag('force', abbr: 'f', negatable: false,
help: 'Force downloading of artifacts.');
argParser.addFlag('android', negatable: true, defaultsTo: true,
help: 'Precache artifacts for Android development');
argParser.addFlag('ios', negatable: true, defaultsTo: true,
......@@ -55,10 +57,11 @@ class PrecacheCommand extends FlutterCommand {
requiredArtifacts.add(artifact);
}
}
if (cache.isUpToDate()) {
printStatus('Already up-to-date.');
} else {
final bool forceUpdate = argResults['force'];
if (forceUpdate || !cache.isUpToDate()) {
await cache.updateAll(requiredArtifacts);
} else {
printStatus('Already up-to-date.');
}
return null;
}
......
......@@ -63,6 +63,23 @@ void main() {
Cache: () => cache,
FlutterVersion: () => flutterVersion,
});
testUsingContext('Downloads artifacts when --force is provided', () async {
when(cache.isUpToDate()).thenReturn(true);
// Release lock between test cases.
Cache.releaseLockEarly();
final PrecacheCommand command = PrecacheCommand();
applyMocksToCommand(command);
await createTestCommandRunner(command).run(const <String>['precache', '--force']);
expect(artifacts, unorderedEquals(<DevelopmentArtifact>{
DevelopmentArtifact.universal,
DevelopmentArtifact.iOS,
DevelopmentArtifact.android,
}));
}, overrides: <Type, Generator>{
Cache: () => cache,
FlutterVersion: () => flutterVersion,
});
});
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment