mirror of
https://github.com/flutter/flutter
synced 2024-10-13 19:52:53 +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 {
|
||||
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,
|
||||
|
|
|
@ -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,
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue