run method Null safety

  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 {
    if (_analytics.firstRun) {
      final response = _logger.prompt(
        lightGray.wrap(
          '''
+---------------------------------------------------+
|    Welcome to the Automatic Version Upgrader!     |
+---------------------------------------------------+
| We would like to collect anonymous                |
| usage statistics in order to improve the tool.    |
| Would you like to opt-into help us improve? [y/n] |
+---------------------------------------------------+\n''',
        ),
      );
      final normalizedResponse = response.toLowerCase().trim();
      _analytics.enabled =
          normalizedResponse == 'y' || normalizedResponse == 'yes';
    }
    final _argResults = parse(args);
    if (_argResults['verbose'] == true) {
      _logger.level = Level.verbose;
    }
    return await runCommand(_argResults) ?? ExitCode.success.code;
  } on FormatException catch (e, stackTrace) {
    _logger
      ..err(e.message)
      ..err('$stackTrace')
      ..info('')
      ..info(usage);
    return ExitCode.usage.code;
  } on UsageException catch (e) {
    _logger
      ..err(e.message)
      ..info('')
      ..info(e.usage);
    return ExitCode.usage.code;
  }
}