listScripts method

void listScripts()

Print all available scripts

Implementation

void listScripts() {
  final pubspec = findPubspec();
  if (pubspec == null) {
    error('No pubspec.yaml found in current directory or parents');
    return;
  }

  final projectName = getProjectName(pubspec.path);
  final scripts = getScripts(pubspec.path);

  if (scripts.isEmpty) {
    warn('No scripts defined in pubspec.yaml');
    print('');
    print('Add scripts to your pubspec.yaml:');
    print('');
    print('scripts:');
    print('  build: flutter build');
    print('  test: flutter test');
    return;
  }

  print('');
  if (projectName != null) {
    print('Scripts for $projectName:');
  } else {
    print('Available scripts:');
  }
  print('\u2500' * 60);

  // Find max script name length for alignment
  final maxLen = scripts.keys.map((k) => k.length).reduce((a, b) => a > b ? a : b);

  for (final entry in scripts.entries) {
    final name = entry.key.padRight(maxLen + 2);
    final cmd = entry.value;
    // Truncate long commands
    final displayCmd = cmd.length > 50 ? '${cmd.substring(0, 47)}...' : cmd;
    print('  $name $displayCmd');
  }

  print('');
  print('Run with: oracular scripts exec <script_name>');
  print('Tip: Use abbreviations like "br" for "build_runner"');
}