runCommand method
Runs the command specified by topLevelResults.
This is notionally a protected method. It may be overridden or called from subclasses, but it shouldn't be called externally.
It's useful to override this to handle global flags and/or wrap the entire
command in a block. For example, you might handle the --verbose flag
here to enable verbose logging before running the command.
This returns the return value of Command.run.
Implementation
@override
Future<T?> runCommand(ArgResults topLevelResults) async {
if (_globals.contains('version') && topLevelResults.flag('version')) {
logger._emit(logger._out, '$executableName version $version\n');
return null;
}
// Its run() cannot return null for a non-nullable T, so it runs here.
final results = topLevelResults.command;
final command = results == null ? null : commands[results.name];
if (command is _CompletionCommand<T> &&
!topLevelResults.flag('help') &&
!results!.flag('help')) {
await command._run(results);
return null;
}
return super.runCommand(topLevelResults);
}