verify that we're running from the root of a project

remove an unused import

review comments

rename st --> stack
This commit is contained in:
Devon Carew 2015-10-28 20:57:51 -07:00
parent 678af9c045
commit 494d1e0140
14 changed files with 55 additions and 17 deletions

View file

@ -20,6 +20,7 @@ import 'src/commands/run_mojo.dart';
import 'src/commands/start.dart';
import 'src/commands/stop.dart';
import 'src/commands/trace.dart';
import 'src/process.dart';
/// Main entry point for commands.
///
@ -58,6 +59,16 @@ Future main(List<String> args) async {
exit(result);
} on UsageException catch (e) {
stderr.writeln(e);
exit(4);
// Args error exit code.
exit(64);
} catch (e, stack) {
if (e is ProcessExit) {
// We've caught an exit code.
exit(e.exitCode);
}
stderr.writeln(e);
Logger.root.log(Level.SEVERE, '\nException:', null, stack);
exit(1);
}
}

View file

@ -127,7 +127,7 @@ class BuildCommand extends FlutterCommand {
}
@override
Future<int> run() async {
Future<int> runInProject() async {
String compilerPath = argResults['compiler'];
if (compilerPath == null)

View file

@ -3,6 +3,7 @@
// found in the LICENSE file.
import 'dart:async';
import 'dart:io';
import 'package:args/command_runner.dart';
@ -14,6 +15,9 @@ import 'flutter_command_runner.dart';
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 => true;
Future downloadApplicationPackages() async {
if (applicationPackages == null)
applicationPackages = await ApplicationPackageStore.forConfigs(runner.buildConfigurations);
@ -40,6 +44,20 @@ abstract class FlutterCommand extends Command {
devices = other.devices;
}
Future<int> run() async {
if (requiresProjectRoot) {
if (!FileSystemEntity.isFileSync('pubspec.yaml')) {
stderr.writeln('No pubspec.yaml file found. '
'This command should be run from the root of a project.');
return 1;
}
}
return runInProject();
}
Future<int> runInProject();
ApplicationPackageStore applicationPackages;
Toolchain toolchain;
DeviceStore devices;

View file

@ -12,6 +12,7 @@ import 'package:path/path.dart' as path;
import '../artifacts.dart';
import '../build_configuration.dart';
import '../process.dart';
final Logger _logging = new Logger('sky_tools.flutter_command_runner');
@ -116,8 +117,8 @@ class FlutterCommandRunner extends CommandRunner {
else
message += '\nDid you run this command from the same directory as your pubspec.yaml file?';
}
_logging.severe(message);
exit(2);
stderr.writeln(message);
throw new ProcessExit(2);
}
String enginePath = globalResults['engine-src-path'];
@ -129,9 +130,11 @@ class FlutterCommandRunner extends CommandRunner {
String realFlutterPath = flutterDir.resolveSymbolicLinksSync();
enginePath = path.dirname(path.dirname(path.dirname(path.dirname(realFlutterPath))));
if (enginePath == '/' || enginePath.isEmpty || !FileSystemEntity.isDirectorySync(path.join(enginePath, 'out'))) {
_logging.severe('Unable to detect local build in $enginePath.\nDo you have a dependency override for the flutter package?');
exit(2);
bool dirExists = FileSystemEntity.isDirectorySync(path.join(enginePath, 'out'));
if (enginePath == '/' || enginePath.isEmpty || !dirExists) {
stderr.writeln('Unable to detect local build in $enginePath.\n'
'Do you have a dependency override for the flutter package?');
throw new ProcessExit(2);
}
}

View file

@ -160,8 +160,7 @@ class FlutterDemo extends StatelessComponent {
),
floatingActionButton: new FloatingActionButton(
child: new Icon(
type: 'content/add',
size: 24
type: 'content/add'
)
)
);

View file

@ -18,7 +18,7 @@ class InstallCommand extends FlutterCommand {
}
@override
Future<int> run() async {
Future<int> runInProject() async {
await downloadApplicationPackagesAndConnectToDevices();
return install(boot: argResults['boot']) ? 0 : 2;
}

View file

@ -23,7 +23,7 @@ class ListCommand extends FlutterCommand {
}
@override
Future<int> run() async {
Future<int> runInProject() async {
connectToDevices();
bool details = argResults['details'];

View file

@ -38,7 +38,7 @@ class ListenCommand extends FlutterCommand {
static const String _remoteFlutterBundle = 'Documents/app.flx';
@override
Future<int> run() async {
Future<int> runInProject() async {
await downloadApplicationPackagesAndConnectToDevices();
await downloadToolchain();

View file

@ -22,7 +22,7 @@ class LogsCommand extends FlutterCommand {
}
@override
Future<int> run() async {
Future<int> runInProject() async {
connectToDevices();
bool clear = argResults['clear'];

View file

@ -36,7 +36,7 @@ class StartCommand extends FlutterCommand {
}
@override
Future<int> run() async {
Future<int> runInProject() async {
await downloadApplicationPackagesAndConnectToDevices();
bool poke = argResults['poke'];

View file

@ -17,7 +17,7 @@ class StopCommand extends FlutterCommand {
final String description = 'Stop your Flutter app on all attached devices.';
@override
Future<int> run() async {
Future<int> runInProject() async {
await downloadApplicationPackagesAndConnectToDevices();
return await stop() ? 0 : 2;
}

View file

@ -28,7 +28,7 @@ class TraceCommand extends FlutterCommand {
}
@override
Future<int> run() async {
Future<int> runInProject() async {
await downloadApplicationPackagesAndConnectToDevices();
if (!devices.android.isConnected()) {

View file

@ -89,3 +89,10 @@ String _runWithLoggingSync(List<String> cmd, {bool checked: false}) {
_logging.fine(results.stdout.trim());
return results.stdout;
}
class ProcessExit implements Exception {
final int exitCode;
ProcessExit(this.exitCode);
String get message => 'ProcessExit: ${exitCode}';
String toString() => message;
}

View file

@ -19,7 +19,7 @@ dependencies:
shelf_route: ^0.13.4
shelf_static: ^0.2.3
shelf: ^0.6.2
test: ^0.12.5
test: 0.12.4+9
yaml: ^2.1.3
dev_dependencies: