run method

  1. @override
FutureOr? run()
override

Runs this command.

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

Implementation

@override
FutureOr? run() async {
  final cache = Cache();

  if (clear) {
    // Clear all cache
    final cacheDir = cache.getCacheDir();
    if (cacheDir.existsSync()) {
      logger.info('Clearing all cache at ${cacheDir.path}...');
      cacheDir.deleteSync(recursive: true);
      logger.success('✓ Cache cleared successfully');
    } else {
      logger.info('Cache directory does not exist');
    }
    return;
  }

  if (clearRepo) {
    // Clear cache for current repo only
    final repoPath = root.path;
    final repoCacheDir = cache.getRepositoryCacheDir(repoPath);
    if (repoCacheDir.existsSync()) {
      logger.info('Clearing cache for repository at ${repoCacheDir.path}...');
      repoCacheDir.deleteSync(recursive: true);
      logger.success('✓ Repository cache cleared successfully');
    } else {
      logger.info('No cache found for this repository');
    }
    return;
  }

  if (list) {
    // List cached refs for current repo
    final repoPath = root.path;
    final cachedRefs = cache.listCachedRefs(repoPath);

    if (cachedRefs.isEmpty) {
      logger.info('No cached API documentation found for this repository');
    } else {
      logger.info('Cached refs for this repository:');
      for (final ref in cachedRefs) {
        logger.info('  - $ref');
      }
      logger.success('✓ Found ${cachedRefs.length} cached ref(s)');
    }
    return;
  }

  // If no flags provided, show help
  logger.info(usage);
}