-module(clip). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). -export([return/1, apply/2, command/1, fail/1, opt/2, arg/2, arg_many/2, arg_many1/2, flag/2, subcommands_with_default/2, subcommands/1, add_help/3, run/2]). -export_type([command/1]). -opaque command(IRC) :: {command, clip@internal@arg_info:arg_info(), fun((list(binary())) -> {ok, {IRC, list(binary())}} | {error, binary()})}. -file("/Users/drew/code/clip/src/clip.gleam", 28). -spec return(IRD) -> command(IRD). return(Val) -> {command, clip@internal@arg_info:empty(), fun(Args) -> {ok, {Val, Args}} end}. -file("/Users/drew/code/clip/src/clip.gleam", 34). -spec apply(command(fun((IRF) -> IRG)), command(IRF)) -> command(IRG). apply(Mf, Ma) -> {command, clip@internal@arg_info:merge( erlang:element(2, Mf), erlang:element(2, Ma) ), fun(Args) -> gleam@result:'try'( (erlang:element(3, Mf))(Args), fun(_use0) -> {F, Args1} = _use0, gleam@result:'try'( (erlang:element(3, Ma))(Args1), fun(_use0@1) -> {A, Args2} = _use0@1, {ok, {F(A), Args2}} end ) end ) end}. -file("/Users/drew/code/clip/src/clip.gleam", 53). -spec command(fun((IRK) -> IRL)) -> command(fun((IRK) -> IRL)). command(F) -> return(F). -file("/Users/drew/code/clip/src/clip.gleam", 58). -spec fail(binary()) -> command(any()). fail(Message) -> {command, clip@internal@arg_info:empty(), fun(_) -> {error, Message} end}. -file("/Users/drew/code/clip/src/clip.gleam", 72). -spec opt(command(fun((IRP) -> IRQ)), clip@opt:opt(IRP)) -> command(IRQ). opt(Command, Opt) -> apply( Command, {command, clip@opt:to_arg_info(Opt), fun(_capture) -> clip@opt:run(Opt, _capture) end} ). -file("/Users/drew/code/clip/src/clip.gleam", 90). -spec arg(command(fun((IRU) -> IRV)), clip@arg:arg(IRU)) -> command(IRV). arg(Command, Arg) -> apply( Command, {command, clip@arg:to_arg_info(Arg), fun(_capture) -> clip@arg:run(Arg, _capture) end} ). -file("/Users/drew/code/clip/src/clip.gleam", 111). -spec arg_many(command(fun((list(IRZ)) -> ISB)), clip@arg:arg(IRZ)) -> command(ISB). arg_many(Command, Arg) -> apply( Command, {command, clip@arg:to_arg_info_many(Arg), fun(_capture) -> clip@arg:run_many(Arg, _capture) end} ). -file("/Users/drew/code/clip/src/clip.gleam", 134). -spec arg_many1(command(fun((list(ISF)) -> ISH)), clip@arg:arg(ISF)) -> command(ISH). arg_many1(Command, Arg) -> apply( Command, {command, clip@arg:to_arg_info_many1(Arg), fun(_capture) -> clip@arg:run_many1(Arg, _capture) end} ). -file("/Users/drew/code/clip/src/clip.gleam", 151). -spec flag(command(fun((boolean()) -> ISL)), clip@flag:flag()) -> command(ISL). flag(Command, Flag) -> apply( Command, {command, clip@flag:to_arg_info(Flag), fun(_capture) -> clip@flag:run(Flag, _capture) end} ). -file("/Users/drew/code/clip/src/clip.gleam", 155). -spec run_subcommands( list({binary(), command(ISO)}), command(ISO), list(binary()) ) -> {ok, {ISO, list(binary())}} | {error, binary()}. run_subcommands(Subcommands, Default, Args) -> case {Subcommands, Args} of {[{Name, Command} | _], [Head | Rest]} when Name =:= Head -> (erlang:element(3, Command))(Rest); {[_ | Rest@1], _} -> run_subcommands(Rest@1, Default, Args); {[], _} -> (erlang:element(3, Default))(Args) end. -file("/Users/drew/code/clip/src/clip.gleam", 170). -spec subcommands_with_default(list({binary(), command(IST)}), command(IST)) -> command(IST). subcommands_with_default(Subcommands, Default) -> Sub_names = gleam@list:map(Subcommands, fun(P) -> erlang:element(1, P) end), Sub_arg_info = erlang:setelement(5, erlang:element(2, Default), Sub_names), apply( return(fun(A) -> A end), {command, Sub_arg_info, fun(_capture) -> run_subcommands(Subcommands, Default, _capture) end} ). -file("/Users/drew/code/clip/src/clip.gleam", 184). -spec subcommands(list({binary(), command(ISY)})) -> command(ISY). subcommands(Subcommands) -> subcommands_with_default( Subcommands, fail(<<"No subcommand provided"/utf8>>) ). -file("/Users/drew/code/clip/src/clip.gleam", 191). -spec add_help(command(ITC), binary(), binary()) -> command(ITC). add_help(Command, Name, Description) -> Help_info = erlang:setelement( 4, clip@internal@arg_info:empty(), [{flag_info, <<"help"/utf8>>, {some, <<"h"/utf8>>}, {some, <<"Print this help"/utf8>>}}] ), erlang:setelement(3, Command, fun(Args) -> case Args of [<<"-h"/utf8>> | _] -> {error, clip@internal@arg_info:help_text( clip@internal@arg_info:merge( erlang:element(2, Command), Help_info ), Name, Description )}; [<<"--help"/utf8>> | _] -> {error, clip@internal@arg_info:help_text( clip@internal@arg_info:merge( erlang:element(2, Command), Help_info ), Name, Description )}; Other -> (erlang:element(3, Command))(Other) end end). -file("/Users/drew/code/clip/src/clip.gleam", 221). -spec run(command(ITF), list(binary())) -> {ok, ITF} | {error, binary()}. run(Command, Args) -> case (erlang:element(3, Command))(Args) of {ok, {A, _}} -> {ok, A}; {error, E} -> {error, E} end.