run method

  1. @override
Future<int> run(
  1. Iterable<String> args
)
override

Parses args and invokes Command.run on the chosen command.

This always returns a Future in case the command is asynchronous. The Future will throw a UsageException if args was invalid.

Implementation

@override
Future<int> run(Iterable<String> args) async {
  try {
    final topLevelResults = parse(args);
    if (topLevelResults['verbose'] == true) {
      _logger.level = Level.verbose;
    }
    return await runCommand(topLevelResults) ?? ExitCode.success.code;
  } on FormatException catch (e, stackTrace) {
    // On format errors, show the commands error message, root usage and
    // exit with an error code
    _logger
      ..err(e.message)
      ..err('$stackTrace')
      ..info('')
      ..info(usage);
    return ExitCode.usage.code;
  } on UsageException catch (e) {
    // On usage errors, show the commands usage message and
    // exit with an error code
    _logger
      ..err(e.message)
      ..info('')
      ..info(e.usage);
    return ExitCode.usage.code;
  }
}