mirror of
https://github.com/flutter/flutter
synced 2024-10-13 11:42:54 +00:00
Suppress upgrade message with --machine (#49408)
This commit is contained in:
parent
1cc38683cd
commit
acdaffc493
|
@ -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);
|
||||
|
|
|
@ -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());
|
||||
|
|
Loading…
Reference in a new issue