runCommand method
Runs the command specified by topLevelResults.
globalConfiguration is set before this method is called.
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<void> runCommand(final ArgResults topLevelResults) async {
try {
try {
_onRunContextResolved?.call(_runContext(topLevelResults));
} catch (e, stackTrace) {
logger.debug('Failed to resolve the run context: $e\n$stackTrace');
}
if (globalConfiguration.version) {
await _versionCommand.run();
return;
}
final latestVersion = await _fetchLatestCliVersion();
if (latestVersion != null && version < latestVersion) {
if (_isRequiredUpdate(latestVersion) &&
_attemptedUpdateVersion != latestVersion) {
final didRerun = await _updateAndRerunCommand(
latestVersion: latestVersion,
topLevelResults: topLevelResults,
);
if (didRerun) {
return;
}
} else {
_alertUpdateNotInstalled(latestVersion);
}
}
await super.runCommand(topLevelResults);
} finally {
_serviceProvider.shutdown();
}
}