-module(cactus@write). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). -export([init/1]). -spec create_script(binary()) -> {ok, nil} | {error, simplifile:file_error()}. create_script(Command) -> gleam@io:println( <<<<"Initializing hook: '"/utf8, Command/binary>>/binary, "'"/utf8>> ), gleam@result:'try'( simplifile:current_directory(), fun(Pwd) -> Hooks_path = begin _pipe = Pwd, _pipe@1 = filepath:join(_pipe, <<".git"/utf8>>), filepath:join(_pipe@1, <<"hooks"/utf8>>) end, Path = filepath:join(Hooks_path, Command), _ = simplifile_erl:create_directory(Hooks_path), _ = simplifile:create_file(Path), gleam@result:'try'( simplifile:write( Path, <<"gleam run -m cactus --target erlang -- "/utf8, Command/binary>> ), fun(_) -> All = gleam@set:from_list([read, write, execute]), simplifile:set_permissions( Path, {file_permissions, All, All, All} ) end ) end ). -spec init(binary()) -> {ok, nil} | {error, nil}. init(Path) -> gleam@result:'try'( cactus@util:parse_manifest(Path), fun(Manifest) -> gleam@result:map( begin _pipe = tom:get_table(Manifest, [<<"cactus"/utf8>>]), gleam@result:nil_error(_pipe) end, fun(Action_body) -> _pipe@1 = Action_body, _pipe@2 = gleam@dict:keys(_pipe@1), _pipe@3 = gleam@list:filter( _pipe@2, fun(_capture) -> gleam@list:contains( [<<"applypatch-msg"/utf8>>, <<"commit-msg"/utf8>>, <<"fsmonitor-watchman"/utf8>>, <<"post-update"/utf8>>, <<"pre-applypatch"/utf8>>, <<"pre-commit"/utf8>>, <<"pre-merge-commit"/utf8>>, <<"prepare-commit-msg"/utf8>>, <<"pre-push"/utf8>>, <<"pre-rebase"/utf8>>, <<"pre-receive"/utf8>>, <<"push-to-checkout"/utf8>>, <<"update"/utf8>>], _capture ) end ), gleam@list:map(_pipe@3, fun create_script/1), nil end ) end ).