diff --git a/packages/flutter_tools/lib/src/commands/create.dart b/packages/flutter_tools/lib/src/commands/create.dart index d53d57395b..e8d5525afc 100644 --- a/packages/flutter_tools/lib/src/commands/create.dart +++ b/packages/flutter_tools/lib/src/commands/create.dart @@ -47,13 +47,19 @@ class CreateCommand extends FlutterCommand { @override Future runCommand() async { if (argResults.rest.isEmpty) { - printStatus('No option specified for the output directory.'); - printStatus(usage); + printError('No option specified for the output directory.'); + printError(usage); return 2; } if (argResults.rest.length > 1) { - printStatus('Multiple output directories specified.'); + printError('Multiple output directories specified.'); + for (String arg in argResults.rest) { + if (arg.startsWith('-')) { + printError('Try moving $arg to be immediately following $name'); + break; + } + } return 2; } diff --git a/packages/flutter_tools/test/create_test.dart b/packages/flutter_tools/test/create_test.dart index f9b472bba9..dc7ad250ab 100644 --- a/packages/flutter_tools/test/create_test.dart +++ b/packages/flutter_tools/test/create_test.dart @@ -7,6 +7,7 @@ import 'dart:convert'; import 'dart:io'; import 'package:args/command_runner.dart'; +import 'package:flutter_tools/src/base/logger.dart'; import 'package:flutter_tools/src/cache.dart'; import 'package:flutter_tools/src/commands/create.dart'; import 'package:flutter_tools/src/dart/sdk.dart'; @@ -82,6 +83,21 @@ void main() { expect(code, 0); }); + // Verify that we help the user correct an option ordering issue + BufferLogger logger = new BufferLogger(); + testUsingContext('produces sensible error message', () async { + Cache.flutterRoot = '../..'; + + CreateCommand command = new CreateCommand(); + CommandRunner runner = createTestCommandRunner(command); + + int code = await runner.run(['create', temp.path, '--pub']); + expect(code, 2); + expect(logger.errorText, contains('Try moving --pub')); + }, overrides: { + Logger: logger, + }); + // Verify that we fail with an error code when the file exists. testUsingContext('fails when file exists', () async { Cache.flutterRoot = '../..';