Current section

Files

Jump to
cactus src cactus.erl
Raw

src/cactus.erl

-module(cactus).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-export([main/0]).
-spec get_cmd() -> binary().
get_cmd() ->
_pipe = shellout_ffi:start_arguments(),
_pipe@1 = gleam@list:filter(
_pipe,
fun(A) -> not gleam@string:ends_with(A, <<".js"/utf8>>) end
),
_pipe@2 = gleam@list:filter(
_pipe@1,
fun(A@1) -> not gleam@string:ends_with(A@1, <<".mjs"/utf8>>) end
),
_pipe@3 = gleam@list:filter(
_pipe@2,
fun(A@2) -> not gleam@string:ends_with(A@2, <<".cjs"/utf8>>) end
),
_pipe@4 = gleam@list:last(_pipe@3),
gleam@result:unwrap(_pipe@4, <<""/utf8>>).
-spec main() -> {ok, nil} | {error, cactus@errors:cactus_err()}.
main() ->
gleam@result:map(
cactus@errors:as_fs_err(simplifile:current_directory(), <<"."/utf8>>),
fun(Pwd) ->
Gleam_toml = filepath:join(Pwd, <<"gleam.toml"/utf8>>),
Hooks_dir = begin
_pipe = Pwd,
_pipe@1 = filepath:join(_pipe, <<".git"/utf8>>),
filepath:join(_pipe@1, <<"hooks"/utf8>>)
end,
Cmd = get_cmd(),
Res = case Cmd of
<<""/utf8>> ->
cactus@write:init(Hooks_dir, Gleam_toml);
<<"init"/utf8>> ->
cactus@write:init(Hooks_dir, Gleam_toml);
Arg ->
case 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>>],
Arg
) of
true ->
cactus@run:run(Gleam_toml, Arg);
false ->
{error, {cli_err, Arg}}
end
end,
case Res of
{ok, _} ->
nil;
{error, Reason} ->
gleam@io:println_error(
<<<<<<"'"/utf8, Cmd/binary>>/binary,
"' hook failed. Reason: "/utf8>>/binary,
(cactus@errors:str(Reason))/binary>>
),
shellout_ffi:os_exit(1)
end
end
).