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 {
serviceProvider.initialize(
globalConfiguration: globalConfiguration,
logger: logger,
);
if (globalConfiguration.version) {
await _versionCommand.run();
}
final Version? latestVersion;
try {
latestVersion = await CLIVersionChecker.fetchLatestCLIVersion(
logger: logger,
localStoragePath: globalConfiguration.scloudDir.path,
);
} catch (e, stackTrace) {
logger.debug('Failed to fetch latest CLI version: $e');
throw ErrorExitException(
'Failed to fetch latest CLI version', e, stackTrace);
}
if (latestVersion != null && version < latestVersion) {
final isRequiredUpdate = CLIVersionChecker.isBreakingUpdate(
currentVersion: version,
latestVersion: latestVersion,
);
_printUpdateCLIPrompt(
latestVersion: latestVersion,
logger: logger,
isRequiredUpdate: isRequiredUpdate,
);
if (isRequiredUpdate) {
throw ErrorExitException('You need to update the CLI to continue.');
}
}
try {
await super.runCommand(topLevelResults);
} finally {
serviceProvider.shutdown();
}
}