Current section

Files

Jump to
clip src clip@flag.erl
Raw

src/clip@flag.erl

-module(clip@flag).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-export([to_arg_info/1, help/2, new/1, short/2, run/2]).
-export_type([flag/0]).
-opaque flag() :: {flag,
binary(),
gleam@option:option(binary()),
gleam@option:option(binary())}.
-file("/Users/drew/code/clip/src/clip/flag.gleam", 15).
-spec to_arg_info(flag()) -> clip@internal@arg_info:arg_info().
to_arg_info(Flag) ->
erlang:setelement(
4,
clip@internal@arg_info:empty(),
[{flag_info,
erlang:element(2, Flag),
erlang:element(4, Flag),
erlang:element(3, Flag)}]
).
-file("/Users/drew/code/clip/src/clip/flag.gleam", 23).
-spec help(flag(), binary()) -> flag().
help(Flag, Help) ->
erlang:setelement(3, Flag, {some, Help}).
-file("/Users/drew/code/clip/src/clip/flag.gleam", 29).
-spec new(binary()) -> flag().
new(Name) ->
{flag, Name, none, none}.
-file("/Users/drew/code/clip/src/clip/flag.gleam", 43).
-spec short(flag(), binary()) -> flag().
short(Flag, Short) ->
erlang:setelement(4, Flag, {some, Short}).
-file("/Users/drew/code/clip/src/clip/flag.gleam", 49).
-spec run(flag(), list(binary())) -> {ok, {boolean(), list(binary())}} |
{error, binary()}.
run(Flag, Args) ->
Long_name = <<"--"/utf8, (erlang:element(2, Flag))/binary>>,
Short_name = gleam@option:map(
erlang:element(4, Flag),
fun(S) -> <<"-"/utf8, S/binary>> end
),
case Args of
[] ->
{ok, {false, []}};
[Head | Rest] when (Long_name =:= Head) orelse (Short_name =:= {some,
Head}) ->
{ok, {true, Rest}};
[Head@1 | Rest@1] ->
_pipe = run(Flag, Rest@1),
gleam@result:map(
_pipe,
fun(V) ->
{erlang:element(1, V), [Head@1 | erlang:element(2, V)]}
end
)
end.