-module(clip). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). -export([return/1, parameter/1, apply/2, command/1, fail/1, opt/2, arg/2, arg_many/2, arg_many1/2, flag/2, help/2, subcommands_with_default/2, subcommands/1, run/2]). -export_type([command/1]). -opaque command(ISL) :: {command, clip@arg_info:arg_info(), gleam@option:option(clip@help:help()), fun((list(binary())) -> {ok, {ISL, list(binary())}} | {error, binary()})}. -file("/Users/drew/code/clip/src/clip.gleam", 29). -spec return(ISM) -> command(ISM). return(Val) -> {command, clip@arg_info:empty(), none, fun(Args) -> {ok, {Val, Args}} end}. -file("/Users/drew/code/clip/src/clip.gleam", 56). -spec parameter(fun((ISO) -> ISP)) -> fun((ISO) -> ISP). parameter(F) -> F. -file("/Users/drew/code/clip/src/clip.gleam", 62). -spec apply(command(fun((ISQ) -> ISR)), command(ISQ)) -> command(ISR). apply(Mf, Ma) -> {command, clip@arg_info:merge(erlang:element(2, Mf), erlang:element(2, Ma)), gleam@option:'or'(erlang:element(3, Mf), erlang:element(3, Ma)), fun(Args) -> gleam@result:'try'( (erlang:element(4, Mf))(Args), fun(_use0) -> {F, Args1} = _use0, gleam@result:'try'( (erlang:element(4, Ma))(Args1), fun(_use0@1) -> {A, Args2} = _use0@1, {ok, {F(A), Args2}} end ) end ) end}. -file("/Users/drew/code/clip/src/clip.gleam", 90). -spec command(fun((ISV) -> ISW)) -> command(fun((ISV) -> ISW)). command(F) -> return(F). -file("/Users/drew/code/clip/src/clip.gleam", 95). -spec fail(binary()) -> command(any()). fail(Message) -> {command, clip@arg_info:empty(), none, fun(_) -> {error, Message} end}. -file("/Users/drew/code/clip/src/clip.gleam", 109). -spec opt(command(fun((ITA) -> ITB)), clip@opt:opt(ITA)) -> command(ITB). opt(Command, Opt) -> apply( Command, {command, clip@opt:to_arg_info(Opt), none, fun(_capture) -> clip@opt:run(Opt, _capture) end} ). -file("/Users/drew/code/clip/src/clip.gleam", 130). -spec arg(command(fun((ITF) -> ITG)), clip@arg:arg(ITF)) -> command(ITG). arg(Command, Arg) -> apply( Command, {command, clip@arg:to_arg_info(Arg), none, fun(_capture) -> clip@arg:run(Arg, _capture) end} ). -file("/Users/drew/code/clip/src/clip.gleam", 154). -spec arg_many(command(fun((list(ITK)) -> ITM)), clip@arg:arg(ITK)) -> command(ITM). arg_many(Command, Arg) -> apply( Command, {command, clip@arg:to_arg_info_many(Arg), none, fun(_capture) -> clip@arg:run_many(Arg, _capture) end} ). -file("/Users/drew/code/clip/src/clip.gleam", 177). -spec arg_many1(command(fun((list(ITQ)) -> ITS)), clip@arg:arg(ITQ)) -> command(ITS). arg_many1(Command, Arg) -> apply( Command, {command, clip@arg:to_arg_info_many1(Arg), none, fun(_capture) -> clip@arg:run_many1(Arg, _capture) end} ). -file("/Users/drew/code/clip/src/clip.gleam", 197). -spec flag(command(fun((boolean()) -> ITW)), clip@flag:flag()) -> command(ITW). flag(Command, Flag) -> apply( Command, {command, clip@flag:to_arg_info(Flag), none, fun(_capture) -> clip@flag:run(Flag, _capture) end} ). -file("/Users/drew/code/clip/src/clip.gleam", 245). -spec help(command(IUN), clip@help:help()) -> command(IUN). help(Command, Help) -> erlang:setelement(3, Command, {some, Help}). -file("/Users/drew/code/clip/src/clip.gleam", 249). -spec wrap_help(command(IUQ), clip@help:help()) -> fun((list(binary())) -> {ok, {IUQ, list(binary())}} | {error, binary()}). wrap_help(Command, Help) -> Help_info = erlang:setelement( 4, clip@arg_info:empty(), [{flag_info, <<"help"/utf8>>, {some, <<"h"/utf8>>}, {some, <<"Print this help"/utf8>>}}] ), fun(Args) -> case Args of [<<"-h"/utf8>> | _] -> {error, clip@help:run( Help, clip@arg_info:merge( erlang:element(2, Command), Help_info ) )}; [<<"--help"/utf8>> | _] -> {error, clip@help:run( Help, clip@arg_info:merge( erlang:element(2, Command), Help_info ) )}; Other -> (erlang:element(4, Command))(Other) end end. -file("/Users/drew/code/clip/src/clip.gleam", 267). -spec run_aux(command(IUT), list(binary())) -> {ok, {IUT, list(binary())}} | {error, binary()}. run_aux(Command, Args) -> F = case erlang:element(3, Command) of none -> erlang:element(4, Command); {some, Help} -> wrap_help(Command, Help) end, F(Args). -file("/Users/drew/code/clip/src/clip.gleam", 204). -spec run_subcommands( list({binary(), command(ITZ)}), command(ITZ), list(binary()) ) -> {ok, {ITZ, list(binary())}} | {error, binary()}. run_subcommands(Subcommands, Default, Args) -> case {Subcommands, Args} of {[{Name, Command} | _], [Head | Rest]} when Name =:= Head -> run_aux(Command, Rest); {[_ | Rest@1], _} -> run_subcommands(Rest@1, Default, Args); {[], _} -> run_aux(Default, Args) end. -file("/Users/drew/code/clip/src/clip.gleam", 220). -spec subcommands_with_default(list({binary(), command(IUE)}), command(IUE)) -> command(IUE). 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, none, fun(_capture) -> run_subcommands(Subcommands, Default, _capture) end} ). -file("/Users/drew/code/clip/src/clip.gleam", 238). -spec subcommands(list({binary(), command(IUJ)})) -> command(IUJ). subcommands(Subcommands) -> subcommands_with_default( Subcommands, fail(<<"No subcommand provided"/utf8>>) ). -file("/Users/drew/code/clip/src/clip.gleam", 278). -spec run(command(IUX), list(binary())) -> {ok, IUX} | {error, binary()}. run(Command, Args) -> case run_aux(Command, Args) of {ok, {A, _}} -> {ok, A}; {error, E} -> {error, E} end.