2015-10-10 06:41:40 +00:00
|
|
|
// Copyright 2015 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.
|
|
|
|
|
2015-10-13 20:36:39 +00:00
|
|
|
import 'dart:async';
|
|
|
|
import 'dart:io';
|
|
|
|
|
|
|
|
import 'package:args/command_runner.dart';
|
2015-11-02 08:20:22 +00:00
|
|
|
import 'package:stack_trace/stack_trace.dart';
|
2015-10-10 06:41:40 +00:00
|
|
|
|
2016-02-07 03:19:50 +00:00
|
|
|
import 'src/base/context.dart';
|
|
|
|
import 'src/base/logger.dart';
|
2015-11-29 05:07:16 +00:00
|
|
|
import 'src/base/process.dart';
|
2015-11-11 18:29:05 +00:00
|
|
|
import 'src/commands/analyze.dart';
|
2015-11-17 01:24:54 +00:00
|
|
|
import 'src/commands/apk.dart';
|
2015-10-10 06:41:40 +00:00
|
|
|
import 'src/commands/build.dart';
|
|
|
|
import 'src/commands/cache.dart';
|
2016-01-27 22:37:29 +00:00
|
|
|
import 'src/commands/create.dart';
|
2015-11-02 21:05:05 +00:00
|
|
|
import 'src/commands/daemon.dart';
|
2016-02-14 07:50:20 +00:00
|
|
|
import 'src/commands/devices.dart';
|
2015-10-10 06:41:40 +00:00
|
|
|
import 'src/commands/install.dart';
|
2015-12-17 22:22:29 +00:00
|
|
|
import 'src/commands/ios.dart';
|
2015-10-10 06:41:40 +00:00
|
|
|
import 'src/commands/listen.dart';
|
|
|
|
import 'src/commands/logs.dart';
|
2016-02-09 18:40:21 +00:00
|
|
|
import 'src/commands/refresh.dart';
|
2016-02-14 07:50:20 +00:00
|
|
|
import 'src/commands/run.dart';
|
2015-10-10 06:41:40 +00:00
|
|
|
import 'src/commands/run_mojo.dart';
|
|
|
|
import 'src/commands/stop.dart';
|
2015-11-05 07:43:15 +00:00
|
|
|
import 'src/commands/test.dart';
|
2015-10-10 06:41:40 +00:00
|
|
|
import 'src/commands/trace.dart';
|
2015-11-12 18:13:40 +00:00
|
|
|
import 'src/commands/upgrade.dart';
|
2016-02-07 03:19:50 +00:00
|
|
|
import 'src/device.dart';
|
2015-11-29 05:07:16 +00:00
|
|
|
import 'src/runner/flutter_command_runner.dart';
|
2015-10-10 06:41:40 +00:00
|
|
|
|
|
|
|
/// Main entry point for commands.
|
|
|
|
///
|
|
|
|
/// This function is intended to be used from the [flutter] command line tool.
|
2015-10-13 20:36:39 +00:00
|
|
|
Future main(List<String> args) async {
|
2016-01-29 22:32:12 +00:00
|
|
|
bool help = args.contains('-h') || args.contains('--help');
|
|
|
|
bool verbose = args.contains('-v') || args.contains('--verbose');
|
2016-02-14 07:50:20 +00:00
|
|
|
bool verboseHelp = help && verbose;
|
2016-01-29 22:32:12 +00:00
|
|
|
|
2016-02-14 07:50:20 +00:00
|
|
|
FlutterCommandRunner runner = new FlutterCommandRunner(verboseHelp: verboseHelp)
|
2015-11-11 18:29:05 +00:00
|
|
|
..addCommand(new AnalyzeCommand())
|
2015-11-17 01:24:54 +00:00
|
|
|
..addCommand(new ApkCommand())
|
2015-10-10 06:41:40 +00:00
|
|
|
..addCommand(new BuildCommand())
|
|
|
|
..addCommand(new CacheCommand())
|
2016-01-27 22:37:29 +00:00
|
|
|
..addCommand(new CreateCommand())
|
2016-02-14 07:50:20 +00:00
|
|
|
..addCommand(new DaemonCommand(hideCommand: !verboseHelp))
|
|
|
|
..addCommand(new DevicesCommand())
|
2015-10-10 06:41:40 +00:00
|
|
|
..addCommand(new InstallCommand())
|
2015-12-17 22:22:29 +00:00
|
|
|
..addCommand(new IOSCommand())
|
2015-10-10 06:41:40 +00:00
|
|
|
..addCommand(new ListenCommand())
|
|
|
|
..addCommand(new LogsCommand())
|
2016-02-09 18:40:21 +00:00
|
|
|
..addCommand(new RefreshCommand())
|
2016-02-14 07:50:20 +00:00
|
|
|
..addCommand(new RunCommand())
|
2015-10-10 06:41:40 +00:00
|
|
|
..addCommand(new RunMojoCommand())
|
|
|
|
..addCommand(new StopCommand())
|
2015-11-05 07:43:15 +00:00
|
|
|
..addCommand(new TestCommand())
|
2015-11-12 18:13:40 +00:00
|
|
|
..addCommand(new TraceCommand())
|
|
|
|
..addCommand(new UpgradeCommand());
|
2015-10-13 20:36:39 +00:00
|
|
|
|
2015-11-02 08:20:22 +00:00
|
|
|
return Chain.capture(() async {
|
2016-02-07 03:19:50 +00:00
|
|
|
// Initialize globals.
|
|
|
|
context[Logger] = new StdoutLogger();
|
|
|
|
context[DeviceManager] = new DeviceManager();
|
|
|
|
|
2015-10-17 18:50:23 +00:00
|
|
|
dynamic result = await runner.run(args);
|
2016-02-07 03:19:50 +00:00
|
|
|
|
2015-10-17 18:50:23 +00:00
|
|
|
if (result is int)
|
|
|
|
exit(result);
|
2015-11-02 08:20:22 +00:00
|
|
|
}, onError: (error, Chain chain) {
|
|
|
|
if (error is UsageException) {
|
|
|
|
stderr.writeln(error);
|
|
|
|
// Argument error exit code.
|
|
|
|
exit(64);
|
|
|
|
} else if (error is ProcessExit) {
|
2015-10-29 03:57:51 +00:00
|
|
|
// We've caught an exit code.
|
2015-11-02 08:20:22 +00:00
|
|
|
exit(error.exitCode);
|
|
|
|
} else {
|
2016-01-28 21:29:17 +00:00
|
|
|
stderr.writeln(error);
|
|
|
|
stderr.writeln(chain.terse);
|
2015-11-02 08:20:22 +00:00
|
|
|
exit(1);
|
2015-10-29 03:57:51 +00:00
|
|
|
}
|
2015-11-02 08:20:22 +00:00
|
|
|
});
|
2015-10-10 06:41:40 +00:00
|
|
|
}
|