add function

Future<void> add({
  1. required String hookName,
  2. bool verbose = false,
})

Adds a git hook by copying from the sample file. If the hook already exists, it skips the addition.

Implementation

Future<void> add({required String hookName, bool verbose = false}) async {
  final hookFile = File('${Consts.herdsmanDirPath}/$hookName.sample');

  if (hookFile.existsSync()) {
    final newFile = File('${Consts.herdsmanDirPath}/$hookName');
    if (newFile.existsSync()) {
      stdout.writeln('⚠️ Git hook $hookName already exists. Skipping...');
      return;
    }
    final file = hookFile.copySync('${Consts.herdsmanDirPath}/$hookName');
    if (verbose) stdout.writeln('🔨 Creating git hook: $hookName');
    file.createSync();
    if (verbose) stdout.writeln('📄 Created git hook file: $hookName');
    hookFile.deleteSync();
    if (verbose) {
      stdout.writeln('🗑️ Deleting sample git hook: $hookName.sample');
    }
    stdout.writeln('✅ Add git hook: $hookName');
  } else {
    stdout.writeln('⚠️ Git hook $hookName already exists. Skipping...');
  }
}