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 {
  int exitCode;
  try {
    final argResults = parse(args);

    exitCode = await runCommand(argResults);
  } catch (error) {
    logger.err('$error');
    exitCode = 1;
  } finally {
    final anyResult = (AnyArgParser()
          ..addFlag(
            'version-check',
            defaultsTo: true,
          ))
        .parse(args);

    if (anyResult['version-check'] as bool) {
      logger.detail('Checking for updates');
      await checkForUpdate();
    } else {
      logger.detail('Skipping version check');
    }
  }

  return exitCode;
}