improve flutter create error message (#6525)
diff --git a/packages/flutter_tools/lib/src/commands/create.dart b/packages/flutter_tools/lib/src/commands/create.dart
index d53d573..e8d5525 100644
--- a/packages/flutter_tools/lib/src/commands/create.dart
+++ b/packages/flutter_tools/lib/src/commands/create.dart
@@ -47,13 +47,19 @@
@override
Future<int> 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 f9b472b..dc7ad25 100644
--- a/packages/flutter_tools/test/create_test.dart
+++ b/packages/flutter_tools/test/create_test.dart
@@ -7,6 +7,7 @@
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 @@
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(<String>['create', temp.path, '--pub']);
+ expect(code, 2);
+ expect(logger.errorText, contains('Try moving --pub'));
+ }, overrides: <Type, dynamic>{
+ Logger: logger,
+ });
+
// Verify that we fail with an error code when the file exists.
testUsingContext('fails when file exists', () async {
Cache.flutterRoot = '../..';