improve flutter create error message (#6525)

This commit is contained in:
Dan Rubel
2016-10-26 19:11:55 +01:00
committed by GitHub
parent 80627a5ccd
commit 949e27ae8f
2 changed files with 25 additions and 3 deletions

View File

@@ -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;
}

View File

@@ -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 = '../..';