Suppress upgrade message with --machine (#49408)

This commit is contained in:
Jenn Magder 2020-01-24 10:50:54 -08:00 committed by GitHub
parent 1cc38683cd
commit acdaffc493
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 3 deletions

View file

@ -309,7 +309,8 @@ class FlutterCommandRunner extends CommandRunner<void> {
globals.printError('Please ensure you have permissions in the artifact cache directory.');
throwToolExit('Failed to write the version file');
}
if (topLevelResults.command?.name != 'upgrade' && topLevelResults['version-check'] as bool) {
final bool machineFlag = topLevelResults['machine'] as bool;
if (topLevelResults.command?.name != 'upgrade' && topLevelResults['version-check'] as bool && !machineFlag) {
await FlutterVersion.instance.checkFlutterVersionFreshness();
}
@ -323,7 +324,7 @@ class FlutterCommandRunner extends CommandRunner<void> {
if (topLevelResults['version'] as bool) {
flutterUsage.sendCommand('version');
String status;
if (topLevelResults['machine'] as bool) {
if (machineFlag) {
status = const JsonEncoder.withIndent(' ').convert(FlutterVersion.instance.toJson());
} else {
status = FlutterVersion.instance.toString();
@ -332,7 +333,7 @@ class FlutterCommandRunner extends CommandRunner<void> {
return;
}
if (topLevelResults['machine'] as bool) {
if (machineFlag) {
throwToolExit('The --machine flag is only valid with the --version flag.', exitCode: 2);
}
await super.runCommand(topLevelResults);

View file

@ -72,6 +72,22 @@ void main() {
Platform: () => platform,
}, initializeFlutterRoot: false);
testUsingContext('does not check that Flutter installation is up-to-date with --machine flag', () async {
final MockFlutterVersion version = FlutterVersion.instance as MockFlutterVersion;
bool versionChecked = false;
when(version.checkFlutterVersionFreshness()).thenAnswer((_) async {
versionChecked = true;
});
await runner.run(<String>['dummy', '--machine', '--version']);
expect(versionChecked, isFalse);
}, overrides: <Type, Generator>{
FileSystem: () => fs,
ProcessManager: () => FakeProcessManager.any(),
Platform: () => platform,
}, initializeFlutterRoot: false);
testUsingContext('throw tool exit if the version file cannot be written', () async {
final MockFlutterVersion version = FlutterVersion.instance as MockFlutterVersion;
when(version.ensureVersionFile()).thenThrow(const FileSystemException());