From ffd1baa342e21f591dd4dd4dd4f4017ee2a4e7ba Mon Sep 17 00:00:00 2001 From: Matan Lurey Date: Mon, 21 Jul 2025 17:41:08 -0700 Subject: [PATCH] Refactor checks for `--machine` (#172504) Was already fixed in https://github.com/flutter/flutter/pull/150138, so removes duplicate flag. Already tested by existing test suite. --- .../src/runner/flutter_command_runner.dart | 23 ++++++------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/packages/flutter_tools/lib/src/runner/flutter_command_runner.dart b/packages/flutter_tools/lib/src/runner/flutter_command_runner.dart index ecd359a3d79..d5016d1450e 100644 --- a/packages/flutter_tools/lib/src/runner/flutter_command_runner.dart +++ b/packages/flutter_tools/lib/src/runner/flutter_command_runner.dart @@ -314,15 +314,11 @@ class FlutterCommandRunner extends CommandRunner { /// /// This method should be narrowly used in the following manner: /// ```dart - /// final bool topLevelMachineFlag = topLevelResults[FlutterGlobalOptions.kMachineFlag] as bool? ?? false; - /// if (await _shouldCheckForUpdates(topLevelResults, topLevelMachineFlag: topLevelMachineFlag)) { + /// if (await _shouldCheckForUpdates(topLevelResult)) { /// await globals.flutterVersion.checkFlutterVersionFreshness(); /// } /// ``` - Future _shouldCheckForUpdates( - ArgResults topLevelResults, { - required bool topLevelMachineFlag, - }) async { + Future _shouldCheckForUpdates(ArgResults topLevelResults) async { // Check if the user has explicitly requested a version check. final bool versionCheckFlag = topLevelResults[FlutterGlobalOptions.kVersionCheckFlag] as bool? ?? false; @@ -332,11 +328,6 @@ class FlutterCommandRunner extends CommandRunner { return true; } - // If the top level --machine flag is set, we don't want to check for updates. - if (topLevelMachineFlag) { - return false; - } - // Running the "upgrade" command is already checking, don't check twice. if (topLevelResults.command?.name == 'upgrade') { return false; @@ -454,9 +445,7 @@ class FlutterCommandRunner extends CommandRunner { await globals.cache.updateAll({DevelopmentArtifact.informative}); globals.flutterVersion.ensureVersionFile(); - final bool machineFlag = - topLevelResults[FlutterGlobalOptions.kMachineFlag] as bool? ?? false; - if (await _shouldCheckForUpdates(topLevelResults, topLevelMachineFlag: machineFlag)) { + if (await _shouldCheckForUpdates(topLevelResults)) { await globals.flutterVersion.checkFlutterVersionFreshness(); } @@ -466,6 +455,8 @@ class FlutterCommandRunner extends CommandRunner { globals.deviceManager?.specifiedDeviceId = specifiedDeviceId; } + final bool topLevelMachineFlag = + topLevelResults[FlutterGlobalOptions.kMachineFlag] as bool? ?? false; if ((topLevelResults[FlutterGlobalOptions.kVersionFlag] as bool?) ?? false) { globals.analytics.send( Event.flutterCommandResult( @@ -478,7 +469,7 @@ class FlutterCommandRunner extends CommandRunner { clock: globals.systemClock, ); final String status; - if (machineFlag) { + if (topLevelMachineFlag) { final Map jsonOut = version.toJson(); jsonOut['flutterRoot'] = Cache.flutterRoot!; status = const JsonEncoder.withIndent(' ').convert(jsonOut); @@ -488,7 +479,7 @@ class FlutterCommandRunner extends CommandRunner { globals.printStatus(status); return; } - if (machineFlag && topLevelResults.command?.name != 'analyze') { + if (topLevelMachineFlag && topLevelResults.command?.name != 'analyze') { throwToolExit( 'The "--machine" flag is only valid with the "--version" flag or the "analyze --suggestions" command.', exitCode: 2,