run method
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.
This overrides the CommandRunner.run method in order to resolve the
global configuration before invoking runCommand.
If this method is overridden, the overriding method must ensure that
the global configuration is set, see globalConfiguration.
Implementation
@override
Future<T?> run(final Iterable<String> args) {
return Future.sync(() {
final argResults = parse(args);
globalConfiguration = resolveConfiguration(argResults);
try {
if (globalConfiguration.errors.isNotEmpty) {
final buffer = StringBuffer();
final errors = globalConfiguration.errors.map(formatConfigError);
buffer.writeAll(errors, '\n');
usageException(buffer.toString());
}
} on UsageException catch (e) {
messageOutput?.logUsageException(e);
_onAnalyticsEvent?.call(BetterCommandRunnerAnalyticsEvents.invalid);
rethrow;
}
return runCommand(argResults);
});
}