mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
[flutter_tools] Don't try to run pub before the version command (#51436)
This commit is contained in:
parent
22c807773a
commit
bc4bd7bd55
@ -17,11 +17,17 @@ import '../version.dart';
|
|||||||
|
|
||||||
class VersionCommand extends FlutterCommand {
|
class VersionCommand extends FlutterCommand {
|
||||||
VersionCommand() : super() {
|
VersionCommand() : super() {
|
||||||
usesPubOption(hide: true);
|
|
||||||
argParser.addFlag('force',
|
argParser.addFlag('force',
|
||||||
abbr: 'f',
|
abbr: 'f',
|
||||||
help: 'Force switch to older Flutter versions that do not include a version command',
|
help: 'Force switch to older Flutter versions that do not include a version command',
|
||||||
);
|
);
|
||||||
|
// Don't use usesPubOption here. That will cause the version command to
|
||||||
|
// require a pubspec.yaml file, which it doesn't need.
|
||||||
|
argParser.addFlag('pub',
|
||||||
|
defaultsTo: true,
|
||||||
|
hide: true,
|
||||||
|
help: 'Whether to run "flutter pub get" after switching versions.',
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -138,7 +144,7 @@ class VersionCommand extends FlutterCommand {
|
|||||||
globals.printStatus(flutterVersion.toString());
|
globals.printStatus(flutterVersion.toString());
|
||||||
|
|
||||||
final String projectRoot = findProjectRoot();
|
final String projectRoot = findProjectRoot();
|
||||||
if (projectRoot != null && shouldRunPub) {
|
if (projectRoot != null && boolArg('pub')) {
|
||||||
globals.printStatus('');
|
globals.printStatus('');
|
||||||
await pub.get(
|
await pub.get(
|
||||||
context: PubContext.pubUpgrade,
|
context: PubContext.pubUpgrade,
|
||||||
|
@ -170,6 +170,17 @@ void main() {
|
|||||||
ProcessManager: () => MockProcessManager(failGitTag: true),
|
ProcessManager: () => MockProcessManager(failGitTag: true),
|
||||||
Stdio: () => mockStdio,
|
Stdio: () => mockStdio,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
testUsingContext('Does not run pub when outside a project', () async {
|
||||||
|
final VersionCommand command = VersionCommand();
|
||||||
|
await createTestCommandRunner(command).run(<String>[
|
||||||
|
'version',
|
||||||
|
]);
|
||||||
|
expect(testLogger.statusText, equals('v10.0.0\r\nv20.0.0\n'));
|
||||||
|
}, overrides: <Type, Generator>{
|
||||||
|
ProcessManager: () => MockProcessManager(),
|
||||||
|
Stdio: () => mockStdio,
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user