executeHook function
Implementation
Future<void> executeHook(String name, Hook hook) async {
const fs = LocalFileSystem();
final debug = hook is VerboseHook;
final level = switch (debug) {
true => Level.verbose,
false => Level.info,
};
final logger = Logger()..level = level;
final gitService = GitService(
logger: logger,
fs: fs,
);
try {
final executor = HookExecutor(
hook,
stdout: stdout,
hookName: name,
logger: logger,
gitService: gitService,
debug: debug,
);
final canRun = await executor.runChecks();
if (!canRun) {
exitCode = 1;
} else {
exitCode = await executor.run();
}
} catch (e, stack) {
logger
..err('Error running hook')
..detail('Error: $e')
..detail('Stack:\n$stack');
exitCode = 1;
}
exit(exitCode);
}