Current section

Files

Jump to
glap src glap@cliargs.erl
Raw

src/glap@cliargs.erl

-module(glap@cliargs).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-define(FILEPATH, "src/glap/cliargs.gleam").
-export([get_cliarg/2, get_content/1, get_content_opt/1, get_content_opt_or/2, is_argument_registered/2, get_subargument/2, then_get_subargument/2, cliarg_to_string/1, cliargs_to_string/1]).
-export_type([c_l_i_arg/0]).
-type c_l_i_arg() :: {unnamed_argument, binary(), binary()} |
{flag, binary(), binary(), gleam@option:option(binary())} |
{command, binary(), boolean(), list(c_l_i_arg())}.
-file("src/glap/cliargs.gleam", 18).
-spec stringoption_to_string(gleam@option:option(binary())) -> binary().
stringoption_to_string(O) ->
case O of
{some, S} ->
glap@utils:strformat(<<"Some(\"{}\")"/utf8>>, [S]);
none ->
<<"None"/utf8>>
end.
-file("src/glap/cliargs.gleam", 51).
-spec get_cliarg(list(c_l_i_arg()), binary()) -> gleam@option:option(c_l_i_arg()).
get_cliarg(Cliargs, Cliarg_name) ->
gleam@bool:guard(
Cliargs =:= [],
none,
fun() ->
{Cliarg@1, Cliargs_rest@1} = case Cliargs of
[Cliarg | Cliargs_rest] -> {Cliarg, Cliargs_rest};
_assert_fail ->
erlang:error(#{gleam_error => let_assert,
message => <<"Pattern match failed, no pattern matched the value."/utf8>>,
file => <<?FILEPATH/utf8>>,
module => <<"glap/cliargs"/utf8>>,
function => <<"get_cliarg"/utf8>>,
line => 54,
value => _assert_fail,
start => 1576,
'end' => 1621,
pattern_start => 1587,
pattern_end => 1611})
end,
case Cliarg@1 of
{flag, Short, Long, _} when (Cliarg_name =:= Short) orelse (Cliarg_name =:= Long) ->
{some, Cliarg@1};
{unnamed_argument, Name, _} when Cliarg_name =:= Name ->
{some, Cliarg@1};
{command, Name@1, _, _} when Cliarg_name =:= Name@1 ->
{some, Cliarg@1};
_ ->
get_cliarg(Cliargs_rest@1, Cliarg_name)
end
end
).
-file("src/glap/cliargs.gleam", 64).
-spec get_content(c_l_i_arg()) -> gleam@option:option(binary()).
get_content(Cliarg) ->
case Cliarg of
{flag, _, _, Content_o} ->
Content_o;
{unnamed_argument, _, Content} ->
{some, Content};
_ ->
none
end.
-file("src/glap/cliargs.gleam", 72).
-spec get_content_opt(gleam@option:option(c_l_i_arg())) -> gleam@option:option(binary()).
get_content_opt(Cliarg) ->
case Cliarg of
{some, {flag, _, _, Content_o}} ->
Content_o;
{some, {unnamed_argument, _, Content}} ->
{some, Content};
_ ->
none
end.
-file("src/glap/cliargs.gleam", 80).
-spec get_content_opt_or(gleam@option:option(c_l_i_arg()), binary()) -> binary().
get_content_opt_or(Cliarg, Default) ->
_pipe = get_content_opt(Cliarg),
gleam@option:unwrap(_pipe, Default).
-file("src/glap/cliargs.gleam", 85).
-spec is_argument_registered(list(c_l_i_arg()), binary()) -> boolean().
is_argument_registered(Cliargs, Cliarg_name) ->
_pipe = get_cliarg(Cliargs, Cliarg_name),
gleam@option:is_some(_pipe).
-file("src/glap/cliargs.gleam", 91).
-spec get_subargument(c_l_i_arg(), binary()) -> gleam@option:option(c_l_i_arg()).
get_subargument(Command, Subargument_name) ->
case Command of
{command, _, _, Subcommands} ->
_pipe = gleam@list:filter(Subcommands, fun(Cliarg) -> case Cliarg of
{flag, Short, Long, _} when (Subargument_name =:= Short) orelse (Subargument_name =:= Long) ->
true;
{command, Name, _, _} when Subargument_name =:= Name ->
true;
{unnamed_argument, Name@1, _} when Subargument_name =:= Name@1 ->
true;
_ ->
false
end end),
_pipe@1 = gleam@list:first(_pipe),
gleam@option:from_result(_pipe@1);
_ ->
none
end.
-file("src/glap/cliargs.gleam", 110).
-spec then_get_subargument(gleam@option:option(c_l_i_arg()), binary()) -> gleam@option:option(c_l_i_arg()).
then_get_subargument(Cliarg_o, Subargument_name) ->
case Cliarg_o of
{some, Cliarg} ->
get_subargument(Cliarg, Subargument_name);
none ->
none
end.
-file("src/glap/cliargs.gleam", 38).
-spec cliargs_to_string_aux(list(c_l_i_arg()), integer()) -> binary().
cliargs_to_string_aux(Cliargs, Indent_level) ->
_pipe = Cliargs,
_pipe@1 = gleam@list:map(
_pipe,
fun(Cliarg) -> cliarg_to_string_aux(Cliarg, Indent_level + 1) end
),
_pipe@2 = gleam@list:map(
_pipe@1,
fun(S) ->
<<<<"\n"/utf8,
(gleam@string:repeat(<<" "/utf8>>, Indent_level))/binary>>/binary,
S/binary>>
end
),
gleam@string:join(_pipe@2, <<""/utf8>>).
-file("src/glap/cliargs.gleam", 25).
-spec cliarg_to_string_aux(c_l_i_arg(), integer()) -> binary().
cliarg_to_string_aux(Cliarg, Indent_level) ->
case Cliarg of
{unnamed_argument, Name, Content} ->
glap@utils:strformat(
<<"UnnamedArgument(\"{}\", \"{}\")"/utf8>>,
[Name, Content]
);
{flag, Short, Long, Content@1} ->
glap@utils:strformat(
<<"Flag(\"{}\", \"{}\", {})"/utf8>>,
[Short, Long, stringoption_to_string(Content@1)]
);
{command, Name@1, Registered, Subarguments} ->
glap@utils:strformat(
<<"Command(\"{}\", {}){}"/utf8>>,
[Name@1,
gleam@bool:to_string(Registered),
cliargs_to_string_aux(Subarguments, Indent_level + 1)]
)
end.
-file("src/glap/cliargs.gleam", 33).
-spec cliarg_to_string(c_l_i_arg()) -> binary().
cliarg_to_string(Cliarg) ->
cliarg_to_string_aux(Cliarg, 0).
-file("src/glap/cliargs.gleam", 46).
-spec cliargs_to_string(list(c_l_i_arg())) -> binary().
cliargs_to_string(Cliargs) ->
cliargs_to_string_aux(Cliargs, 0).