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',
|
abbr: 'o',
|
||||||
defaultsTo: _kDefaultOutputPath,
|
defaultsTo: _kDefaultOutputPath,
|
||||||
help: 'Output APK file.');
|
help: 'Output APK file.');
|
||||||
argParser.addOption('target',
|
|
||||||
abbr: 't',
|
|
||||||
defaultsTo: flx.defaultMainPath,
|
|
||||||
help: 'Target app path / main entry-point file.');
|
|
||||||
argParser.addOption('flx',
|
argParser.addOption('flx',
|
||||||
abbr: 'f',
|
abbr: 'f',
|
||||||
defaultsTo: '',
|
defaultsTo: '',
|
||||||
@ -172,6 +168,7 @@ class ApkCommand extends FlutterCommand {
|
|||||||
argParser.addOption('keystore-key-password',
|
argParser.addOption('keystore-key-password',
|
||||||
defaultsTo: '',
|
defaultsTo: '',
|
||||||
help: 'Password for the entry within the keystore.');
|
help: 'Password for the entry within the keystore.');
|
||||||
|
addTargetOption();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -19,17 +19,13 @@ class BuildCommand extends FlutterCommand {
|
|||||||
// remove it once we've updated those build scripts.
|
// remove it once we've updated those build scripts.
|
||||||
argParser.addOption('asset-base', help: 'Ignored. Will be removed.', hide: true);
|
argParser.addOption('asset-base', help: 'Ignored. Will be removed.', hide: true);
|
||||||
argParser.addOption('compiler');
|
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.
|
// TODO(devoncarew): Remove this once the xcode project is switched over.
|
||||||
argParser.addOption('main', hide: true);
|
argParser.addOption('main', hide: true);
|
||||||
argParser.addOption('manifest', defaultsTo: defaultManifestPath);
|
argParser.addOption('manifest', defaultsTo: defaultManifestPath);
|
||||||
argParser.addOption('private-key', defaultsTo: defaultPrivateKeyPath);
|
argParser.addOption('private-key', defaultsTo: defaultPrivateKeyPath);
|
||||||
argParser.addOption('output-file', abbr: 'o', defaultsTo: defaultFlxOutputPath);
|
argParser.addOption('output-file', abbr: 'o', defaultsTo: defaultFlxOutputPath);
|
||||||
argParser.addOption('snapshot', defaultsTo: defaultSnapshotPath);
|
argParser.addOption('snapshot', defaultsTo: defaultSnapshotPath);
|
||||||
|
addTargetOption();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<int> runInProject() async {
|
Future<int> runInProject() async {
|
||||||
|
@ -7,7 +7,6 @@ import 'dart:io';
|
|||||||
|
|
||||||
import 'package:path/path.dart' as path;
|
import 'package:path/path.dart' as path;
|
||||||
|
|
||||||
import '../flx.dart';
|
|
||||||
import '../globals.dart';
|
import '../globals.dart';
|
||||||
import '../runner/flutter_command.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).';
|
final String description = 'Build and deploy the Dart code in a Flutter app (Android only).';
|
||||||
|
|
||||||
RefreshCommand() {
|
RefreshCommand() {
|
||||||
argParser.addOption('target',
|
addTargetOption();
|
||||||
abbr: 't',
|
|
||||||
defaultsTo: defaultMainPath,
|
|
||||||
help: 'Target app path / main entry-point file.'
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool get androidOnly => true;
|
bool get androidOnly => true;
|
||||||
|
@ -13,7 +13,6 @@ import '../base/utils.dart';
|
|||||||
import '../build_configuration.dart';
|
import '../build_configuration.dart';
|
||||||
import '../dart/pub.dart';
|
import '../dart/pub.dart';
|
||||||
import '../device.dart';
|
import '../device.dart';
|
||||||
import '../flx.dart';
|
|
||||||
import '../globals.dart';
|
import '../globals.dart';
|
||||||
import '../runner/flutter_command.dart';
|
import '../runner/flutter_command.dart';
|
||||||
import '../toolchain.dart';
|
import '../toolchain.dart';
|
||||||
@ -43,12 +42,9 @@ abstract class RunCommandBase extends FlutterCommand {
|
|||||||
negatable: true,
|
negatable: true,
|
||||||
defaultsTo: false,
|
defaultsTo: false,
|
||||||
help: 'Start tracing during startup.');
|
help: 'Start tracing during startup.');
|
||||||
argParser.addOption('target',
|
|
||||||
abbr: 't',
|
|
||||||
defaultsTo: defaultMainPath,
|
|
||||||
help: 'Target app path / main entry-point file.');
|
|
||||||
argParser.addOption('route',
|
argParser.addOption('route',
|
||||||
help: 'Which route to load when starting the app.');
|
help: 'Which route to load when starting the app.');
|
||||||
|
addTargetOption();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool get checked => argResults['checked'];
|
bool get checked => argResults['checked'];
|
||||||
|
@ -12,6 +12,7 @@ import '../build_configuration.dart';
|
|||||||
import '../device.dart';
|
import '../device.dart';
|
||||||
import '../globals.dart';
|
import '../globals.dart';
|
||||||
import '../toolchain.dart';
|
import '../toolchain.dart';
|
||||||
|
import '../flx.dart' as flx;
|
||||||
import 'flutter_command_runner.dart';
|
import 'flutter_command_runner.dart';
|
||||||
|
|
||||||
typedef bool Validator();
|
typedef bool Validator();
|
||||||
@ -28,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 {
|
||||||
@ -58,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.
|
||||||
@ -142,4 +148,15 @@ abstract class FlutterCommand extends Command {
|
|||||||
|
|
||||||
return devices;
|
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