Skip to content

Commit ca0596e

Browse files
authored
Fix pub get --unknown-flag (#119622)
1 parent fd76ef0 commit ca0596e

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

packages/flutter_tools/lib/src/commands/packages.dart

+6-1
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ class PackagesGetCommand extends FlutterCommand {
213213
argParser.addOption('git-ref');
214214
argParser.addOption('git-path');
215215
argParser.addFlag('dev');
216+
argParser.addFlag('verbose', abbr: 'v');
216217
return argParser;
217218
}
218219

@@ -238,7 +239,11 @@ class PackagesGetCommand extends FlutterCommand {
238239
FlutterProject? rootProject;
239240

240241
if (!isHelp) {
241-
if (directoryOption == null && rest.length == 1 &&
242+
if (directoryOption == null &&
243+
rest.length == 1 &&
244+
// Anything that looks like an argument should not be interpreted as
245+
// a directory.
246+
!rest.single.startsWith('-') &&
242247
((rest.single.contains('/') || rest.single.contains(r'\')) ||
243248
name == 'get')) {
244249
// For historical reasons, if there is one argument to the command and it contains

packages/flutter_tools/test/commands.shard/hermetic/pub_get_test.dart

+30
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,32 @@ void main() {
9494
FileSystem: () => fileSystem,
9595
});
9696

97+
testUsingContext("pub get doesn't treat unknown flag as directory", () async {
98+
fileSystem.currentDirectory.childDirectory('target').createSync();
99+
fileSystem.currentDirectory.childFile('pubspec.yaml').createSync();
100+
final PackagesGetCommand command = PackagesGetCommand('get', '', PubContext.pubGet);
101+
final CommandRunner<void> commandRunner = createTestCommandRunner(command);
102+
pub.expectedArguments = <String>['get', '--unknown-flag', '--example', '--directory', '.'];
103+
await commandRunner.run(<String>['get', '--unknown-flag']);
104+
}, overrides: <Type, Generator>{
105+
Pub: () => pub,
106+
ProcessManager: () => FakeProcessManager.any(),
107+
FileSystem: () => fileSystem,
108+
});
109+
110+
testUsingContext("pub get doesn't treat -v as directory", () async {
111+
fileSystem.currentDirectory.childDirectory('target').createSync();
112+
fileSystem.currentDirectory.childFile('pubspec.yaml').createSync();
113+
final PackagesGetCommand command = PackagesGetCommand('get', '', PubContext.pubGet);
114+
final CommandRunner<void> commandRunner = createTestCommandRunner(command);
115+
pub.expectedArguments = <String>['get', '-v', '--example', '--directory', '.'];
116+
await commandRunner.run(<String>['get', '-v']);
117+
}, overrides: <Type, Generator>{
118+
Pub: () => pub,
119+
ProcessManager: () => FakeProcessManager.any(),
120+
FileSystem: () => fileSystem,
121+
});
122+
97123
testUsingContext("pub get skips example directory if it doesn't contain a pubspec.yaml", () async {
98124
fileSystem.currentDirectory.childFile('pubspec.yaml').createSync();
99125
fileSystem.currentDirectory.childDirectory('example').createSync(recursive: true);
@@ -181,6 +207,7 @@ class FakePub extends Fake implements Pub {
181207
FakePub(this.fileSystem);
182208

183209
final FileSystem fileSystem;
210+
List<String>? expectedArguments;
184211

185212
@override
186213
Future<void> interactively(
@@ -192,6 +219,9 @@ class FakePub extends Fake implements Pub {
192219
bool generateSyntheticPackage = false,
193220
PubOutputMode outputMode = PubOutputMode.all,
194221
}) async {
222+
if (expectedArguments != null) {
223+
expect(arguments, expectedArguments);
224+
}
195225
if (project != null) {
196226
fileSystem.directory(project.directory)
197227
.childDirectory('.dart_tool')

0 commit comments

Comments
 (0)