Merge pull request #2433 from stevemessick/targetmessage
Improve message when target not found
This commit is contained in:
commit
e70036f1ad
@ -152,10 +152,6 @@ class ApkCommand extends FlutterCommand {
|
||||
abbr: 'o',
|
||||
defaultsTo: _kDefaultOutputPath,
|
||||
help: 'Output APK file.');
|
||||
argParser.addOption('target',
|
||||
abbr: 't',
|
||||
defaultsTo: flx.defaultMainPath,
|
||||
help: 'Target app path / main entry-point file.');
|
||||
argParser.addOption('flx',
|
||||
abbr: 'f',
|
||||
defaultsTo: '',
|
||||
@ -172,6 +168,7 @@ class ApkCommand extends FlutterCommand {
|
||||
argParser.addOption('keystore-key-password',
|
||||
defaultsTo: '',
|
||||
help: 'Password for the entry within the keystore.');
|
||||
addTargetOption();
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -19,17 +19,13 @@ class BuildCommand extends FlutterCommand {
|
||||
// remove it once we've updated those build scripts.
|
||||
argParser.addOption('asset-base', help: 'Ignored. Will be removed.', hide: true);
|
||||
argParser.addOption('compiler');
|
||||
argParser.addOption('target',
|
||||
abbr: 't',
|
||||
defaultsTo: defaultMainPath,
|
||||
help: 'Target app path / main entry-point file.'
|
||||
);
|
||||
// TODO(devoncarew): Remove this once the xcode project is switched over.
|
||||
argParser.addOption('main', hide: true);
|
||||
argParser.addOption('manifest', defaultsTo: defaultManifestPath);
|
||||
argParser.addOption('private-key', defaultsTo: defaultPrivateKeyPath);
|
||||
argParser.addOption('output-file', abbr: 'o', defaultsTo: defaultFlxOutputPath);
|
||||
argParser.addOption('snapshot', defaultsTo: defaultSnapshotPath);
|
||||
addTargetOption();
|
||||
}
|
||||
|
||||
Future<int> runInProject() async {
|
||||
|
@ -7,7 +7,6 @@ import 'dart:io';
|
||||
|
||||
import 'package:path/path.dart' as path;
|
||||
|
||||
import '../flx.dart';
|
||||
import '../globals.dart';
|
||||
import '../runner/flutter_command.dart';
|
||||
|
||||
@ -16,11 +15,7 @@ class RefreshCommand extends FlutterCommand {
|
||||
final String description = 'Build and deploy the Dart code in a Flutter app (Android only).';
|
||||
|
||||
RefreshCommand() {
|
||||
argParser.addOption('target',
|
||||
abbr: 't',
|
||||
defaultsTo: defaultMainPath,
|
||||
help: 'Target app path / main entry-point file.'
|
||||
);
|
||||
addTargetOption();
|
||||
}
|
||||
|
||||
bool get androidOnly => true;
|
||||
|
@ -13,7 +13,6 @@ import '../base/utils.dart';
|
||||
import '../build_configuration.dart';
|
||||
import '../dart/pub.dart';
|
||||
import '../device.dart';
|
||||
import '../flx.dart';
|
||||
import '../globals.dart';
|
||||
import '../runner/flutter_command.dart';
|
||||
import '../toolchain.dart';
|
||||
@ -43,12 +42,9 @@ abstract class RunCommandBase extends FlutterCommand {
|
||||
negatable: true,
|
||||
defaultsTo: false,
|
||||
help: 'Start tracing during startup.');
|
||||
argParser.addOption('target',
|
||||
abbr: 't',
|
||||
defaultsTo: defaultMainPath,
|
||||
help: 'Target app path / main entry-point file.');
|
||||
argParser.addOption('route',
|
||||
help: 'Which route to load when starting the app.');
|
||||
addTargetOption();
|
||||
}
|
||||
|
||||
bool get checked => argResults['checked'];
|
||||
|
@ -12,6 +12,7 @@ import '../build_configuration.dart';
|
||||
import '../device.dart';
|
||||
import '../globals.dart';
|
||||
import '../toolchain.dart';
|
||||
import '../flx.dart' as flx;
|
||||
import 'flutter_command_runner.dart';
|
||||
|
||||
typedef bool Validator();
|
||||
@ -28,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<BuildConfiguration> get buildConfigurations => runner.buildConfigurations;
|
||||
|
||||
Future downloadToolchain() async {
|
||||
@ -58,7 +63,8 @@ abstract class FlutterCommand extends Command {
|
||||
}
|
||||
|
||||
Future<int> _run() async {
|
||||
if (requiresProjectRoot && !projectRootValidator())
|
||||
bool _checkRoot = requiresProjectRoot && allowsTarget && !_targetSpecified;
|
||||
if (_checkRoot && !projectRootValidator())
|
||||
return 1;
|
||||
|
||||
// Ensure at least one toolchain is installed.
|
||||
@ -142,4 +148,15 @@ abstract class FlutterCommand extends Command {
|
||||
|
||||
return devices;
|
||||
}
|
||||
|
||||
bool _targetSpecified = false;
|
||||
|
||||
void addTargetOption() {
|
||||
argParser.addOption('target',
|
||||
abbr: 't',
|
||||
callback: (val) => _targetSpecified = true,
|
||||
defaultsTo: flx.defaultMainPath,
|
||||
help: 'Target app path / main entry-point file.');
|
||||
_targetOptionSpecified = true;
|
||||
}
|
||||
}
|
||||
|
24
packages/flutter_tools/test/run_test.dart
Normal file
24
packages/flutter_tools/test/run_test.dart
Normal file
@ -0,0 +1,24 @@
|
||||
// Copyright 2016 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:flutter_tools/src/commands/run.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import 'src/common.dart';
|
||||
import 'src/context.dart';
|
||||
import 'src/mocks.dart';
|
||||
|
||||
main() => defineTests();
|
||||
|
||||
defineTests() {
|
||||
group('run', () {
|
||||
testUsingContext('fails when target not found', () {
|
||||
RunCommand command = new RunCommand();
|
||||
applyMocksToCommand(command);
|
||||
return createTestCommandRunner(command).run(<String>['run', '-t', 'abc123']).then((int code) {
|
||||
expect(code, equals(1));
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user