Packages

đŸ›’ A small library of helper functions, that works as a companion of gleam_stdlib

Current section

Files

Jump to
gxyz src gxyz@cli.erl
Raw

src/gxyz@cli.erl

-module(gxyz@cli).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-export([strip_js_from_argv/1, hard_fail/1, hard_fail_with_msg/2, hard_fail_with_opts/3]).
-file("/home/bwireman/src/gxyz/src/gxyz/cli.gleam", 8).
-spec strip_js_from_argv(list(binary())) -> list(binary()).
strip_js_from_argv(Args) ->
_pipe = Args,
_pipe@1 = gxyz@list:reject(
_pipe,
fun(_capture) ->
gleam_stdlib:string_ends_with(_capture, <<".js"/utf8>>)
end
),
_pipe@2 = gxyz@list:reject(
_pipe@1,
fun(_capture@1) ->
gleam_stdlib:string_ends_with(_capture@1, <<".mjs"/utf8>>)
end
),
_pipe@3 = gxyz@list:reject(
_pipe@2,
fun(_capture@2) ->
gleam_stdlib:string_ends_with(_capture@2, <<".cjs"/utf8>>)
end
),
_pipe@4 = gxyz@list:reject(
_pipe@3,
fun(_capture@3) ->
gleam_stdlib:string_ends_with(_capture@3, <<".ts"/utf8>>)
end
),
_pipe@5 = gxyz@list:reject(
_pipe@4,
fun(_capture@4) ->
gleam_stdlib:string_ends_with(_capture@4, <<".mts"/utf8>>)
end
),
gxyz@list:reject(
_pipe@5,
fun(_capture@5) ->
gleam_stdlib:string_ends_with(_capture@5, <<".cts"/utf8>>)
end
).
-file("/home/bwireman/src/gxyz/src/gxyz/cli.gleam", 18).
-spec do_hard_fail(
{ok, FNO} | {error, any()},
gleam@option:option(binary()),
gleam@option:option(integer())
) -> FNO.
do_hard_fail(Res, Msg, Status_code) ->
case Res of
{ok, A} ->
A;
{error, _} ->
gleam@option:map(Msg, fun gleam_stdlib:print_error/1),
_pipe = Status_code,
_pipe@1 = gleam@option:unwrap(_pipe, 1),
erlang:halt(_pipe@1),
erlang:error(#{gleam_error => panic,
message => <<"Unreachable, please create an issue in https://github.com/bwireman/gxyz if you see this"/utf8>>,
module => <<"gxyz/cli"/utf8>>,
function => <<"do_hard_fail"/utf8>>,
line => 31})
end.
-file("/home/bwireman/src/gxyz/src/gxyz/cli.gleam", 37).
-spec hard_fail({ok, FNU} | {error, any()}) -> FNU.
hard_fail(Res) ->
do_hard_fail(Res, none, none).
-file("/home/bwireman/src/gxyz/src/gxyz/cli.gleam", 42).
-spec hard_fail_with_msg({ok, FNY} | {error, any()}, binary()) -> FNY.
hard_fail_with_msg(Res, Msg) ->
do_hard_fail(Res, {some, Msg}, none).
-file("/home/bwireman/src/gxyz/src/gxyz/cli.gleam", 47).
-spec hard_fail_with_opts({ok, FOC} | {error, any()}, binary(), integer()) -> FOC.
hard_fail_with_opts(Res, Msg, Status_code) ->
do_hard_fail(Res, {some, Msg}, {some, Status_code}).