list static method

Future<void> list({
  1. required HooksConfigModel hooksConfig,
  2. String? projectDir,
})

Prints a summary table of all hooks in hooksConfig and their installation status on disk.

Implementation

static Future<void> list({
  required HooksConfigModel hooksConfig,
  String? projectDir,
}) async {
  if (hooksConfig.isEmpty) {
    print('');
    print('πŸ“¦ No hooks configured.');
    print('');
    print('   To get started, add a hooks section to your config.yaml:');
    print('');
    print('   hooks:');
    print('     pre-commit:');
    print('       enabled: true');
    print('       steps:');
    print('         - name: "Analyze"');
    print('           command: "flutter analyze"');
    print('');
    print('   Run "frx hooks install" after adding your hooks.');
    print('');
    return;
  }

  final gitDir = await _findGitDir(projectDir ?? Directory.current.path);
  final hooksDir = gitDir != null
      ? Directory('${gitDir.path}${Platform.pathSeparator}hooks')
      : null;

  print('');
  print(
      '╔══════════════════════╦═════════╦═══════╦═══════════╦════════════════════════════╗');
  print(
      'β•‘ Hook                 β•‘ Enabled β•‘ Steps β•‘ Installed β•‘ Source                     β•‘');
  print(
      '╠══════════════════════╬═════════╬═══════╬═══════════╬════════════════════════════╣');

  for (final entry in hooksConfig.hooks.entries) {
    final name = entry.key.padRight(20);
    final hook = entry.value;
    final enabled = hook.enabled ? '   βœ…   ' : '   ❌   ';
    final steps = hook.steps.length.toString().padRight(5);

    // Check disk install status
    String installed = '    ❌    ';
    if (hooksDir != null) {
      final hookFile =
          File('${hooksDir.path}${Platform.pathSeparator}${entry.key}');
      if (hookFile.existsSync()) {
        final content = hookFile.readAsStringSync();
        installed =
            content.contains(_kFrxHookMarker) ? '    βœ…    ' : '  ⚠️ custom';
      }
    }

    final source = hook.hasPipeline
        ? 'β†’ pipeline: ${hook.runPipeline}'.padRight(26)
        : (hook.hasSteps
            ? '${hook.steps.length} inline step(s)'.padRight(26)
            : '(none)'.padRight(26));

    print('β•‘ $name β•‘$enabledβ•‘ $steps β•‘$installed β•‘ $source β•‘');
  }

  print(
      'β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•©β•β•β•β•β•β•β•β•β•β•©β•β•β•β•β•β•β•β•©β•β•β•β•β•β•β•β•β•β•β•β•©β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•');
  print('');
  print('πŸ’‘ Manage hooks:');
  print('   frx hooks install              Install all enabled hooks');
  print('   frx hooks uninstall            Remove all FRX-managed hooks');
  print('   frx hooks uninstall --hook pre-commit   Remove a specific hook');
  print('   frx hooks run pre-commit       Manually trigger a hook');
  print('');
}