flutter/packages/flutter_tools/lib/executable.dart
Devon Carew 494d1e0140 verify that we're running from the root of a project
remove an unused import

review comments

rename st --> stack
2015-10-29 11:30:44 -07:00

75 lines
2.2 KiB
Dart

// 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.
import 'dart:async';
import 'dart:io';
import 'package:args/command_runner.dart';
import 'package:logging/logging.dart';
import 'src/commands/build.dart';
import 'src/commands/cache.dart';
import 'src/commands/flutter_command_runner.dart';
import 'src/commands/init.dart';
import 'src/commands/install.dart';
import 'src/commands/list.dart';
import 'src/commands/listen.dart';
import 'src/commands/logs.dart';
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.
///
/// This function is intended to be used from the [flutter] command line tool.
Future main(List<String> args) async {
// This level can be adjusted by users through the `--verbose` option.
Logger.root.level = Level.SEVERE;
Logger.root.onRecord.listen((LogRecord record) {
if (record.level >= Level.WARNING) {
stderr.writeln(record.message);
} else {
print(record.message);
}
if (record.error != null)
stderr.writeln(record.error);
if (record.stackTrace != null)
stderr.writeln(record.stackTrace);
});
FlutterCommandRunner runner = new FlutterCommandRunner()
..addCommand(new BuildCommand())
..addCommand(new CacheCommand())
..addCommand(new InitCommand())
..addCommand(new InstallCommand())
..addCommand(new ListCommand())
..addCommand(new ListenCommand())
..addCommand(new LogsCommand())
..addCommand(new RunMojoCommand())
..addCommand(new StartCommand())
..addCommand(new StopCommand())
..addCommand(new TraceCommand());
try {
dynamic result = await runner.run(args);
if (result is int)
exit(result);
} on UsageException catch (e) {
stderr.writeln(e);
// 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);
}
}