improve flutter create error message (#6525)
This commit is contained in:
@@ -47,13 +47,19 @@ class CreateCommand extends FlutterCommand {
|
||||
@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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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(<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 = '../..';
|
||||
|
||||
Reference in New Issue
Block a user