[flutter_tools] Don't try to run pub before the version command (#51436)

This commit is contained in:
Zachary Anderson 2020-02-25 17:19:47 -05:00 committed by GitHub
parent 22c807773a
commit bc4bd7bd55
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 2 deletions

View file

@ -17,11 +17,17 @@ import '../version.dart';
class VersionCommand extends FlutterCommand {
VersionCommand() : super() {
usesPubOption(hide: true);
argParser.addFlag('force',
abbr: 'f',
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
@ -138,7 +144,7 @@ class VersionCommand extends FlutterCommand {
globals.printStatus(flutterVersion.toString());
final String projectRoot = findProjectRoot();
if (projectRoot != null && shouldRunPub) {
if (projectRoot != null && boolArg('pub')) {
globals.printStatus('');
await pub.get(
context: PubContext.pubUpgrade,

View file

@ -170,6 +170,17 @@ void main() {
ProcessManager: () => MockProcessManager(failGitTag: true),
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,
});
});
}