Skip to content

Commit 516b60b

Browse files
authored
Give error on too many arguments to flutter config (#121494)
Give error on too many arguments to `flutter config`
1 parent a297cb3 commit 516b60b

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,16 @@ class ConfigCommand extends FlutterCommand {
101101

102102
@override
103103
Future<FlutterCommandResult> runCommand() async {
104+
final List<String> rest = argResults?.rest ?? <String>[];
105+
if (rest.isNotEmpty) {
106+
throwToolExit(exitCode: 2,
107+
'error: flutter config: Too many arguments.\n'
108+
'\n'
109+
'If a value has a space in it, enclose in quotes on the command line\n'
110+
'to make a single argument. For example:\n'
111+
' flutter config --android-studio-dir "/opt/Android Studio"');
112+
}
113+
104114
if (boolArgDeprecated('machine')) {
105115
await handleMachine();
106116
return FlutterCommandResult.success();

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,19 @@ void main() {
4444
}
4545

4646
group('config', () {
47+
testUsingContext('throws error on excess arguments', () {
48+
final ConfigCommand configCommand = ConfigCommand();
49+
final CommandRunner<void> commandRunner = createTestCommandRunner(configCommand);
50+
51+
expect(() => commandRunner.run(<String>[
52+
'config',
53+
'--android-studio-dir=/opt/My', 'Android', 'Studio',
54+
]), throwsToolExit());
55+
verifyNoAnalytics();
56+
}, overrides: <Type, Generator>{
57+
Usage: () => testUsage,
58+
});
59+
4760
testUsingContext('machine flag', () async {
4861
final ConfigCommand command = ConfigCommand();
4962
await command.handleMachine();

0 commit comments

Comments
 (0)