Commit 913315bc authored by Steve Messick's avatar Steve Messick

Improve the error message when a target is specified but not found.

https://github.com/flutter/flutter/issues/2368
parent 8cc53120
...@@ -21,7 +21,7 @@ abstract class FlutterCommand extends Command { ...@@ -21,7 +21,7 @@ abstract class FlutterCommand extends Command {
FlutterCommandRunner get runner => super.runner; FlutterCommandRunner get runner => super.runner;
/// Whether this command needs to be run from the root of a project. /// Whether this command needs to be run from the root of a project.
bool get requiresProjectRoot => !_targetSpecified; bool get requiresProjectRoot => true;
/// Whether this command requires a (single) Flutter target device to be connected. /// Whether this command requires a (single) Flutter target device to be connected.
bool get requiresDevice => false; bool get requiresDevice => false;
...@@ -29,6 +29,10 @@ abstract class FlutterCommand extends Command { ...@@ -29,6 +29,10 @@ abstract class FlutterCommand extends Command {
/// Whether this command only applies to Android devices. /// Whether this command only applies to Android devices.
bool get androidOnly => false; bool get androidOnly => false;
/// Whether this command allows usage of the 'target' option.
bool get allowsTarget => _targetOptionSpecified;
bool _targetOptionSpecified = false;
List<BuildConfiguration> get buildConfigurations => runner.buildConfigurations; List<BuildConfiguration> get buildConfigurations => runner.buildConfigurations;
Future downloadToolchain() async { Future downloadToolchain() async {
...@@ -59,7 +63,8 @@ abstract class FlutterCommand extends Command { ...@@ -59,7 +63,8 @@ abstract class FlutterCommand extends Command {
} }
Future<int> _run() async { Future<int> _run() async {
if (requiresProjectRoot && !projectRootValidator()) bool _checkRoot = requiresProjectRoot && allowsTarget && !_targetSpecified;
if (_checkRoot && !projectRootValidator())
return 1; return 1;
// Ensure at least one toolchain is installed. // Ensure at least one toolchain is installed.
...@@ -152,5 +157,6 @@ abstract class FlutterCommand extends Command { ...@@ -152,5 +157,6 @@ abstract class FlutterCommand extends Command {
callback: (val) => _targetSpecified = true, callback: (val) => _targetSpecified = true,
defaultsTo: flx.defaultMainPath, defaultsTo: flx.defaultMainPath,
help: 'Target app path / main entry-point file.'); help: 'Target app path / main entry-point file.');
_targetOptionSpecified = true;
} }
} }
...@@ -13,7 +13,7 @@ main() => defineTests(); ...@@ -13,7 +13,7 @@ main() => defineTests();
defineTests() { defineTests() {
group('run', () { group('run', () {
testUsingContext('fail when target not found', () { testUsingContext('fails when target not found', () {
RunCommand command = new RunCommand(); RunCommand command = new RunCommand();
applyMocksToCommand(command); applyMocksToCommand(command);
return createTestCommandRunner(command).run(<String>['run', '-t', 'abc123']).then((int code) { return createTestCommandRunner(command).run(<String>['run', '-t', 'abc123']).then((int code) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment