diff --git a/packages/flutter_tools/lib/src/runner/flutter_command.dart b/packages/flutter_tools/lib/src/runner/flutter_command.dart index d43f1210fa..c916ca662b 100644 --- a/packages/flutter_tools/lib/src/runner/flutter_command.dart +++ b/packages/flutter_tools/lib/src/runner/flutter_command.dart @@ -21,7 +21,7 @@ abstract class FlutterCommand extends Command { FlutterCommandRunner get runner => super.runner; /// 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. bool get requiresDevice => false; @@ -29,6 +29,10 @@ abstract class FlutterCommand extends Command { /// Whether this command only applies to Android devices. bool get androidOnly => false; + /// Whether this command allows usage of the 'target' option. + bool get allowsTarget => _targetOptionSpecified; + bool _targetOptionSpecified = false; + List get buildConfigurations => runner.buildConfigurations; Future downloadToolchain() async { @@ -59,7 +63,8 @@ abstract class FlutterCommand extends Command { } Future _run() async { - if (requiresProjectRoot && !projectRootValidator()) + bool _checkRoot = requiresProjectRoot && allowsTarget && !_targetSpecified; + if (_checkRoot && !projectRootValidator()) return 1; // Ensure at least one toolchain is installed. @@ -152,5 +157,6 @@ abstract class FlutterCommand extends Command { callback: (val) => _targetSpecified = true, defaultsTo: flx.defaultMainPath, help: 'Target app path / main entry-point file.'); + _targetOptionSpecified = true; } } diff --git a/packages/flutter_tools/test/run_test.dart b/packages/flutter_tools/test/run_test.dart index 100aa985c6..8c07516a5a 100644 --- a/packages/flutter_tools/test/run_test.dart +++ b/packages/flutter_tools/test/run_test.dart @@ -13,7 +13,7 @@ main() => defineTests(); defineTests() { group('run', () { - testUsingContext('fail when target not found', () { + testUsingContext('fails when target not found', () { RunCommand command = new RunCommand(); applyMocksToCommand(command); return createTestCommandRunner(command).run(['run', '-t', 'abc123']).then((int code) {