Unverified Commit acdaffc4 authored by Jenn Magder's avatar Jenn Magder Committed by GitHub

Suppress upgrade message with --machine (#49408)

parent 1cc38683
...@@ -309,7 +309,8 @@ class FlutterCommandRunner extends CommandRunner<void> { ...@@ -309,7 +309,8 @@ class FlutterCommandRunner extends CommandRunner<void> {
globals.printError('Please ensure you have permissions in the artifact cache directory.'); globals.printError('Please ensure you have permissions in the artifact cache directory.');
throwToolExit('Failed to write the version file'); 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(); await FlutterVersion.instance.checkFlutterVersionFreshness();
} }
...@@ -323,7 +324,7 @@ class FlutterCommandRunner extends CommandRunner<void> { ...@@ -323,7 +324,7 @@ class FlutterCommandRunner extends CommandRunner<void> {
if (topLevelResults['version'] as bool) { if (topLevelResults['version'] as bool) {
flutterUsage.sendCommand('version'); flutterUsage.sendCommand('version');
String status; String status;
if (topLevelResults['machine'] as bool) { if (machineFlag) {
status = const JsonEncoder.withIndent(' ').convert(FlutterVersion.instance.toJson()); status = const JsonEncoder.withIndent(' ').convert(FlutterVersion.instance.toJson());
} else { } else {
status = FlutterVersion.instance.toString(); status = FlutterVersion.instance.toString();
...@@ -332,7 +333,7 @@ class FlutterCommandRunner extends CommandRunner<void> { ...@@ -332,7 +333,7 @@ class FlutterCommandRunner extends CommandRunner<void> {
return; return;
} }
if (topLevelResults['machine'] as bool) { if (machineFlag) {
throwToolExit('The --machine flag is only valid with the --version flag.', exitCode: 2); throwToolExit('The --machine flag is only valid with the --version flag.', exitCode: 2);
} }
await super.runCommand(topLevelResults); await super.runCommand(topLevelResults);
......
...@@ -72,6 +72,22 @@ void main() { ...@@ -72,6 +72,22 @@ void main() {
Platform: () => platform, Platform: () => platform,
}, initializeFlutterRoot: false); }, 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 { testUsingContext('throw tool exit if the version file cannot be written', () async {
final MockFlutterVersion version = FlutterVersion.instance as MockFlutterVersion; final MockFlutterVersion version = FlutterVersion.instance as MockFlutterVersion;
when(version.ensureVersionFile()).thenThrow(const FileSystemException()); when(version.ensureVersionFile()).thenThrow(const FileSystemException());
......
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