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<int?> runCommand(ArgResults topLevelResults) async {
if (topLevelResults.flag('version')) {
// ignore: avoid_print
print('dpk ${Pubspec.version.representation}');
return 0;
}
if (topLevelResults.flag('help') == false && config != null) {
final requiredVersion = config!.dpkConfig.version;
final currentVersion = Version.parse(Pubspec.version.canonical);
if (!requiredVersion.allows(currentVersion)) {
// ignore: avoid_print
print(
'Error: dpk version ${Pubspec.version.canonical} does not satisfy '
'required version constraint "$requiredVersion" in dpk.yaml',
);
return 1;
}
}
final commandName = topLevelResults.command?.name;
if (commandName != null) {
setTerminalTitle('dpk $commandName');
} else {
setTerminalTitle('dpk');
}
try {
return await super.runCommand(topLevelResults);
} finally {
restoreTerminalTitle();
}
}