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 {
  logger.info('Running flo_cli doctor...');
  logger.info('Current flo_cli version: $packageVersion\n');

  final progress = logger.progress('Checking for updates...');
  final updateService = locator<UpdateService>();
  final latestVersion = await updateService.getLatestVersion();

  if (latestVersion != null) {
    if (updateService.isNewerVersion(packageVersion, latestVersion)) {
      progress.complete(
          'Update available: $latestVersion (current: $packageVersion)');
      logger.info(
          'Run `dart pub global activate flo_cli` or `flo_cli update` to update.\n');
    } else {
      progress.complete('You are on the latest version of flo_cli.');
    }
  } else {
    progress.fail('Failed to check for updates.');
  }

  final fs = locator<FileSystemService>();
  final currentDir = fs.exists('.');

  if (currentDir) {
    logger.success('[✓] File system service is working.');
  } else {
    logger.error('[✗] File system service failed to read current directory.');
  }

  logger.info('\nDoctor found no major issues!');
  return 0;
}