run method

  1. @override
Future<int> run()
override

Runs this command.

The return value is wrapped in a Future if necessary and returned by CommandRunner.runCommand.

Implementation

@override
Future<int> run() async {
  final packageName = lightGreen.wrap('barreler')!;

  final progress = logger.progress('Checking for updates');

  final (needsUpdate, latestVersion) = await this.needsUpdate();

  if (!needsUpdate) {
    progress.complete('$packageName is up to date');

    return 0;
  }

  progress.update('Updating $packageName to ${yellow.wrap(latestVersion)}');

  final updatedSuccessfully = await update();

  if (!updatedSuccessfully) {
    progress.complete('Failed to update $packageName');

    return 1;
  }

  progress.complete(
    'Successfully updated $packageName to ${yellow.wrap(latestVersion)}',
  );

  return 0;
}