run function

Future<int> run (List<String> args, List<BuilderApplication> builders)

A common entry point to parse command line arguments and build or serve with builders.

Returns the exit code that should be set when the calling process exits. 0 implies success.

Implementation

Future<int> run(List<String> args, List<BuilderApplication> builders) async {
  var runner = BuildCommandRunner(builders)..addCommand(CleanCommand());
  try {
    var result = await runner.run(args);
    return result ?? 0;
  } on UsageException catch (e) {
    print(ansi.red.wrap(e.message));
    print('');
    print(e.usage);
    return ExitCode.usage.code;
  } on ArgumentError catch (e) {
    print(ansi.red.wrap(e.toString()));
    return ExitCode.usage.code;
  } on CannotBuildException {
    // A message should have already been logged.
    return ExitCode.config.code;
  } on BuildScriptChangedException {
    _deleteAssetGraph();
    if (_runningFromSnapshot) _deleteSelf();
    return ExitCode.tempFail.code;
  } on BuildConfigChangedException {
    return ExitCode.tempFail.code;
  }
}