run method
Implementation
Future<int> run() async {
if (args['help'] case true) {
logger.write(_usage);
return 0;
}
if (await setHooksPath() case final int code) {
return code;
}
final root = this.root;
if (root == null) {
logger.err('Could not find root directory');
return 1;
}
final (definedHooks, exitCode) = this.definedHooks(root);
if (exitCode case final int code) {
return code;
}
logger.detail('Registering hooks (${definedHooks.length})');
final hooksDartToolDir = dartToolGitHooksDir(root);
final executablesDir = this.executablesDir(root);
final progress = logger.progress('Registering hooks');
final executablesToCompile = prepareExecutables(
definedHooks,
hooksDartToolDir: hooksDartToolDir,
executablesDir: executablesDir,
);
final executables = await compile(executablesToCompile, progress.fail);
if (executables == null) {
return 1;
}
final hooksPath = gitHooksDir;
if (hooksPath == null) {
logger.err('Could not find .git/hooks directory');
return 1;
}
if (copyExecutables(executables, gitHooksDir: hooksPath) case final int code
when code != 0) {
return code;
}
progress.complete('Registered hooks');
return 0;
}