-module(cactus@write). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). -export([create_script/2, init/2]). -spec create_script(binary(), binary()) -> {ok, binary()} | {error, cactus@errors:cactus_err()}. create_script(Hooks_dir, Command) -> gleam@io:println( <<<<"Initializing hook: '"/utf8, Command/binary>>/binary, "'"/utf8>> ), Path = filepath:join(Hooks_dir, Command), _ = simplifile_erl:create_directory(Hooks_dir), _ = simplifile:create_file(Path), gleam@result:'try'( cactus@errors:as_fs_err( simplifile:write( Path, <<"gleam run -m cactus --target erlang -- "/utf8, Command/binary>> ), Path ), fun(_) -> All = gleam@set:from_list([read, write, execute]), _pipe = simplifile:set_permissions( Path, {file_permissions, All, All, All} ), _pipe@1 = gleam@result:replace(_pipe, Command), cactus@errors:as_fs_err(_pipe@1, Path) end ). -spec init(binary(), binary()) -> {ok, list(binary())} | {error, cactus@errors:cactus_err()}. init(Hooks_dir, Path) -> _pipe@4 = (gleam@result:'try'( cactus@util:parse_gleam_toml(Path), fun(Manifest) -> gleam@result:map( cactus@errors:as_invalid_field_err( tom:get_table(Manifest, [<<"cactus"/utf8>>]) ), fun(Action_body) -> _pipe = Action_body, _pipe@1 = gleam@dict:keys(_pipe), _pipe@2 = gleam@list:filter( _pipe@1, 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 ), _pipe@3 = gleam@list:map( _pipe@2, fun(_capture@1) -> create_script(Hooks_dir, _capture@1) end ), gleam@result:all(_pipe@3) end ) end )), gleam@result:flatten(_pipe@4).