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 { ...@@ -13,6 +13,8 @@ class PrecacheCommand extends FlutterCommand {
PrecacheCommand() { PrecacheCommand() {
argParser.addFlag('all-platforms', abbr: 'a', negatable: false, argParser.addFlag('all-platforms', abbr: 'a', negatable: false,
help: 'Precache artifacts for all platforms.'); 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, argParser.addFlag('android', negatable: true, defaultsTo: true,
help: 'Precache artifacts for Android development'); help: 'Precache artifacts for Android development');
argParser.addFlag('ios', negatable: true, defaultsTo: true, argParser.addFlag('ios', negatable: true, defaultsTo: true,
...@@ -55,10 +57,11 @@ class PrecacheCommand extends FlutterCommand { ...@@ -55,10 +57,11 @@ class PrecacheCommand extends FlutterCommand {
requiredArtifacts.add(artifact); requiredArtifacts.add(artifact);
} }
} }
if (cache.isUpToDate()) { final bool forceUpdate = argResults['force'];
printStatus('Already up-to-date.'); if (forceUpdate || !cache.isUpToDate()) {
} else {
await cache.updateAll(requiredArtifacts); await cache.updateAll(requiredArtifacts);
} else {
printStatus('Already up-to-date.');
} }
return null; return null;
} }
......
...@@ -63,6 +63,23 @@ void main() { ...@@ -63,6 +63,23 @@ void main() {
Cache: () => cache, Cache: () => cache,
FlutterVersion: () => flutterVersion, 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