flutter/packages/flutter_tools/lib/executable.dart
Hixie a0227cab15 flutter analyze command
Other changes in this patch:
- Make the 'flutter' tool say "Updating flutter tool..." when it calls
  pub get, to avoid confusion about what the pub get output is about.
- Make the bash flutter tool call pub get when the revision has
  changed. (This was already happening on Windows.)
- Fix a raft of bugs found by the analyzer.
- Fix some style nits in various bits of code that happened to be near
  things the analyzer noticed.
- Remove the logic in "flutter test" that would run "pub get", since
  upon further reflexion it was determined it didn't work anyway.
  We'll probably have to add better diagnostics here and say to run the
  updater script.
- Remove the native velocity tracker script, since it was testing code
  that has since been removed.

Notes on ignored warnings:
- We ignore warnings in any packages that are not in the Flutter repo or
  in the author's current directory.
- We ignore various irrelevant Strong Mode warnings. We still enable
  strong mode because even though it's not really relevant to our needs,
  it does (more or less accidentally) catch a few things that are
  helpful to us.
- We allow CONSTANTS_LIKE_THIS, since we get some of those from other
  platforms that we are copying for sanity and consistency.
- We allow one-member abstract classes since we have a number of them
  where it's perfectly reasonable.
- We unfortunately still ignore warnings in mojom.dart autogenerated
  files. We should really fix those but that's a separate patch.
- We verify the actual source file when we see the 'Name non-constant
  identifiers using lowerCamelCase.' lint, to allow one-letter variables
  that use capital letters (e.g. for physics expressions) and to allow
  multiple-underscore variable names.
- We ignore all errors on lines that contain the following magic
  incantation and a "#" character:
    // analyzer doesn't like constructor tear-offs
- For all remaining errors, if the line contains a comment of the form
    // analyzer says "..."
  ...then we ignore any errors that have that "..." string in them.
2015-11-12 12:23:29 -08:00

85 lines
2.7 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 'package:stack_trace/stack_trace.dart';
import 'src/commands/analyze.dart';
import 'src/commands/build.dart';
import 'src/commands/cache.dart';
import 'src/commands/daemon.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/test.dart';
import 'src/commands/trace.dart';
import 'src/commands/upgrade.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.WARNING;
Logger.root.onRecord.listen((LogRecord record) {
String level = record.level.name.toLowerCase();
if (record.level >= Level.WARNING) {
stderr.writeln('$level: ${record.message}');
} else {
print('$level: ${record.message}');
}
if (record.error != null)
stderr.writeln(record.error);
if (record.stackTrace != null)
stderr.writeln(record.stackTrace);
});
FlutterCommandRunner runner = new FlutterCommandRunner()
..addCommand(new AnalyzeCommand())
..addCommand(new BuildCommand())
..addCommand(new CacheCommand())
..addCommand(new DaemonCommand())
..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 TestCommand())
..addCommand(new TraceCommand())
..addCommand(new UpgradeCommand());
return Chain.capture(() async {
dynamic result = await runner.run(args);
if (result is int)
exit(result);
}, onError: (error, Chain chain) {
if (error is UsageException) {
stderr.writeln(error);
// Argument error exit code.
exit(64);
} else if (error is ProcessExit) {
// We've caught an exit code.
exit(error.exitCode);
} else {
stderr.writeln(error);
Logger.root.log(Level.SEVERE, '\nException:', null, chain.terse.toTrace());
exit(1);
}
});
}