Current section
Files
Jump to
Current section
Files
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, get_command/1, 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", 19).
-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", 52).
-spec get_cliarg(list(c_l_i_arg()), binary()) -> {ok, c_l_i_arg()} |
{error, nil}.
get_cliarg(Cliargs, Cliarg_name) ->
gleam@bool:guard(
Cliargs =:= [],
{error, nil},
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 => 55,
value => _assert_fail,
start => 1607,
'end' => 1652,
pattern_start => 1618,
pattern_end => 1642})
end,
case Cliarg@1 of
{flag, Short, Long, _} when (Cliarg_name =:= Short) orelse (Cliarg_name =:= Long) ->
{ok, Cliarg@1};
{unnamed_argument, Name, _} when Cliarg_name =:= Name ->
{ok, Cliarg@1};
{command, Name@1, _, _} when Cliarg_name =:= Name@1 ->
{ok, Cliarg@1};
_ ->
get_cliarg(Cliargs_rest@1, Cliarg_name)
end
end
).
-file("src/glap/cliargs.gleam", 65).
-spec get_content(c_l_i_arg()) -> {ok, binary()} | {error, nil}.
get_content(Cliarg) ->
case Cliarg of
{flag, _, _, {some, Content}} ->
{ok, Content};
{unnamed_argument, _, Content@1} ->
{ok, Content@1};
_ ->
{error, nil}
end.
-file("src/glap/cliargs.gleam", 73).
-spec get_content_opt({ok, c_l_i_arg()} | {error, nil}) -> {ok, binary()} |
{error, nil}.
get_content_opt(Cliarg) ->
case Cliarg of
{ok, {flag, _, _, {some, Content}}} ->
{ok, Content};
{ok, {unnamed_argument, _, Content@1}} ->
{ok, Content@1};
_ ->
{error, nil}
end.
-file("src/glap/cliargs.gleam", 81).
-spec get_content_opt_or({ok, c_l_i_arg()} | {error, nil}, binary()) -> binary().
get_content_opt_or(Cliarg, Default) ->
case Cliarg of
{ok, {unnamed_argument, _, Content}} ->
Content;
{ok, {flag, _, _, {some, Content@1}}} ->
Content@1;
_ ->
Default
end.
-file("src/glap/cliargs.gleam", 89).
-spec is_argument_registered(list(c_l_i_arg()), binary()) -> boolean().
is_argument_registered(Cliargs, Cliarg_name) ->
_pipe = get_cliarg(Cliargs, Cliarg_name),
gleam@result:is_ok(_pipe).
-file("src/glap/cliargs.gleam", 95).
-spec get_subargument(c_l_i_arg(), binary()) -> {ok, c_l_i_arg()} | {error, nil}.
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),
gleam@list:first(_pipe);
_ ->
{error, nil}
end.
-file("src/glap/cliargs.gleam", 113).
-spec then_get_subargument({ok, c_l_i_arg()} | {error, nil}, binary()) -> {ok,
c_l_i_arg()} |
{error, nil}.
then_get_subargument(Cliarg_o, Subargument_name) ->
case Cliarg_o of
{ok, Cliarg} ->
get_subargument(Cliarg, Subargument_name);
{error, _} ->
{error, nil}
end.
-file("src/glap/cliargs.gleam", 120).
-spec get_command(list(c_l_i_arg())) -> {ok, c_l_i_arg()} | {error, nil}.
get_command(Cliargs) ->
gleam@bool:guard(
Cliargs =:= [],
{error, nil},
fun() ->
{Cliargs_h@1, Cliargs_rest@1} = case Cliargs of
[Cliargs_h | Cliargs_rest] -> {Cliargs_h, 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_command"/utf8>>,
line => 123,
value => _assert_fail,
start => 3501,
'end' => 3549,
pattern_start => 3512,
pattern_end => 3539})
end,
case Cliargs_h@1 of
{command, _, _, _} ->
{ok, Cliargs_h@1};
_ ->
get_command(Cliargs_rest@1)
end
end
).
-file("src/glap/cliargs.gleam", 39).
-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", 26).
-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", 34).
-spec cliarg_to_string(c_l_i_arg()) -> binary().
cliarg_to_string(Cliarg) ->
cliarg_to_string_aux(Cliarg, 0).
-file("src/glap/cliargs.gleam", 47).
-spec cliargs_to_string(list(c_l_i_arg())) -> binary().
cliargs_to_string(Cliargs) ->
cliargs_to_string_aux(Cliargs, 0).