run function

Future<int> run(
  1. List<String> args,
  2. 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, await PackageGraph.forThisPackage())
    ..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 // ignore: avoid_catching_errors
  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 (_runningFromKernel) _invalidateSelf();
    return ExitCode.tempFail.code;
  } on BuildConfigChangedException {
    return ExitCode.tempFail.code;
  }
}