Current section
Files
Jump to
Current section
Files
src/olive@config.erl
-module(olive@config).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-export([get_name/0, parse_from_cli/0]).
-export_type([config/0]).
-type config() :: {config,
integer(),
integer(),
binary(),
olive@logging:log_level_filter()}.
-file("src/olive/config.gleam", 12).
-spec get_name() -> binary().
get_name() ->
_assert_subject = simplifile:read(<<"gleam.toml"/utf8>>),
{ok, Config_file} = case _assert_subject of
{ok, _} -> _assert_subject;
_assert_fail ->
erlang:error(#{gleam_error => let_assert,
message => <<"Pattern match failed, no pattern matched the value."/utf8>>,
value => _assert_fail,
module => <<"olive/config"/utf8>>,
function => <<"get_name"/utf8>>,
line => 13})
end,
_assert_subject@1 = tom:parse(Config_file),
{ok, Toml} = case _assert_subject@1 of
{ok, _} -> _assert_subject@1;
_assert_fail@1 ->
erlang:error(#{gleam_error => let_assert,
message => <<"Pattern match failed, no pattern matched the value."/utf8>>,
value => _assert_fail@1,
module => <<"olive/config"/utf8>>,
function => <<"get_name"/utf8>>,
line => 14})
end,
_assert_subject@2 = tom:get_string(Toml, [<<"name"/utf8>>]),
{ok, Name} = case _assert_subject@2 of
{ok, _} -> _assert_subject@2;
_assert_fail@2 ->
erlang:error(#{gleam_error => let_assert,
message => <<"Pattern match failed, no pattern matched the value."/utf8>>,
value => _assert_fail@2,
module => <<"olive/config"/utf8>>,
function => <<"get_name"/utf8>>,
line => 15})
end,
Name.
-file("src/olive/config.gleam", 57).
-spec main_port_opt() -> clip@opt:opt(integer()).
main_port_opt() ->
_pipe = clip@opt:new(<<"main_port"/utf8>>),
_pipe@1 = clip@opt:int(_pipe),
_pipe@2 = clip@opt:default(_pipe@1, 3000),
clip@opt:help(_pipe@2, <<"The port your main server listens to."/utf8>>).
-file("src/olive/config.gleam", 64).
-spec proxy_port_opt() -> clip@opt:opt(integer()).
proxy_port_opt() ->
_pipe = clip@opt:new(<<"proxy_port"/utf8>>),
_pipe@1 = clip@opt:int(_pipe),
_pipe@2 = clip@opt:default(_pipe@1, 1234),
clip@opt:help(
_pipe@2,
<<"The port the proxy listens to, handled by olive."/utf8>>
).
-file("src/olive/config.gleam", 71).
-spec bind_opt() -> clip@opt:opt(binary()).
bind_opt() ->
_pipe = clip@opt:new(<<"bind"/utf8>>),
_pipe@1 = clip@opt:default(_pipe, <<"localhost"/utf8>>),
clip@opt:help(_pipe@1, <<"The proxy binding address."/utf8>>).
-file("src/olive/config.gleam", 77).
-spec log_opt() -> clip@opt:opt(olive@logging:log_level_filter()).
log_opt() ->
_pipe = clip@opt:new(<<"log"/utf8>>),
_pipe@1 = clip@opt:map(_pipe, fun(V) -> case string:lowercase(V) of
<<"error"/utf8>> ->
errors_only;
<<"errors"/utf8>> ->
errors_only;
<<"errorsonly"/utf8>> ->
errors_only;
<<"erroronly"/utf8>> ->
errors_only;
<<"none"/utf8>> ->
no_logs;
<<"nologs"/utf8>> ->
no_logs;
_ ->
all_logs
end end),
_pipe@2 = clip@opt:default(_pipe@1, all_logs),
clip@opt:help(
_pipe@2,
<<"Either All, Error or None to filter logs from olive."/utf8>>
).
-file("src/olive/config.gleam", 29).
-spec parse_from_cli() -> gleam@option:option(config()).
parse_from_cli() ->
case begin
_pipe = clip:command(
begin
clip:parameter(
fun(Main_port) ->
clip:parameter(
fun(Proxy_port) ->
clip:parameter(
fun(Bind) ->
clip:parameter(
fun(Log) ->
{config,
Main_port,
Proxy_port,
Bind,
Log}
end
)
end
)
end
)
end
)
end
),
_pipe@1 = clip:opt(_pipe, main_port_opt()),
_pipe@2 = clip:opt(_pipe@1, proxy_port_opt()),
_pipe@3 = clip:opt(_pipe@2, bind_opt()),
_pipe@4 = clip:opt(_pipe@3, log_opt()),
_pipe@5 = clip:help(
_pipe@4,
clip@help:simple(
<<"olive"/utf8>>,
<<"Runs a dev proxy for easy live reloading and automatic code changes"/utf8>>
)
),
clip:run(_pipe@5, erlang:element(4, argv:load()))
end of
{ok, Config} ->
{some, Config};
{error, E} ->
gleam_stdlib:println(E),
none
end.