Skip to content

Commit

Permalink
Give error on too many arguments to flutter config (#121494)
Browse files Browse the repository at this point in the history
Give error on too many arguments to `flutter config`
  • Loading branch information
gnprice authored Feb 27, 2023
1 parent a297cb3 commit 516b60b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
10 changes: 10 additions & 0 deletions packages/flutter_tools/lib/src/commands/config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,16 @@ class ConfigCommand extends FlutterCommand {

@override
Future<FlutterCommandResult> runCommand() async {
final List<String> rest = argResults?.rest ?? <String>[];
if (rest.isNotEmpty) {
throwToolExit(exitCode: 2,
'error: flutter config: Too many arguments.\n'
'\n'
'If a value has a space in it, enclose in quotes on the command line\n'
'to make a single argument. For example:\n'
' flutter config --android-studio-dir "/opt/Android Studio"');
}

if (boolArgDeprecated('machine')) {
await handleMachine();
return FlutterCommandResult.success();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,19 @@ void main() {
}

group('config', () {
testUsingContext('throws error on excess arguments', () {
final ConfigCommand configCommand = ConfigCommand();
final CommandRunner<void> commandRunner = createTestCommandRunner(configCommand);

expect(() => commandRunner.run(<String>[
'config',
'--android-studio-dir=/opt/My', 'Android', 'Studio',
]), throwsToolExit());
verifyNoAnalytics();
}, overrides: <Type, Generator>{
Usage: () => testUsage,
});

testUsingContext('machine flag', () async {
final ConfigCommand command = ConfigCommand();
await command.handleMachine();
Expand Down

0 comments on commit 516b60b

Please sign in to comment.