getExistingSnapshots function

Future<Set<String>> getExistingSnapshots()

Implementation

Future<Set<String>> getExistingSnapshots() async {
  // Check for actual snapshot files created by git dependencies
  final home = Platform.environment['HOME'];
  if (home == null) return {};

  final snapshotDir = Directory('$home/.generated_commands/.dart_tool/pub/bin/generated_commands');
  if (!snapshotDir.existsSync()) return {};

  final snapshots = <String>{};
  await for (final entity in snapshotDir.list()) {
    if (entity is File && entity.path.endsWith('.snapshot')) {
      // Extract command name from filename like: s1_no_comment.dart-3.9.2.snapshot
      final filename = entity.path.split('/').last;
      final commandName = filename.split('.dart-').first;
      snapshots.add(commandName);
    }
  }
  return snapshots;
}