-module(internal@config).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/internal/config.gleam").
-export([get/2]).
-export_type([configuration/0, configuration_error/0]).
-type configuration() :: {configuration, binary(), binary(), binary()}.
-type configuration_error() :: {file_error, simplifile:file_error()} |
{toml_error, tom:parse_error()}.
-file("src/internal/config.gleam", 47).
-spec get_string(gleam@dict:dict(binary(), tom:toml()), binary(), binary()) -> binary().
get_string(Toml, Key, Default) ->
_pipe = tom:get_string(Toml, [Key]),
gleam@result:unwrap(_pipe, Default).
-file("src/internal/config.gleam", 40).
-spec find_root(binary()) -> binary().
find_root(Path) ->
case simplifile_erl:is_file(filepath:join(Path, <<"gleam.toml"/utf8>>)) of
{ok, true} ->
Path;
{ok, false} ->
find_root(filepath:join(Path, <<"../"/utf8>>));
{error, _} ->
find_root(filepath:join(Path, <<"../"/utf8>>))
end.
-file("src/internal/config.gleam", 16).
-spec get(binary(), binary()) -> {ok, configuration()} |
{error, configuration_error()}.
get(Default_iconset, Default_module) ->
Root = find_root(<<"./"/utf8>>),
_pipe = filepath:join(Root, <<"gleam.toml"/utf8>>),
_pipe@2 = (fun(File) -> _pipe@1 = simplifile:read(File),
gleam@result:map_error(
_pipe@1,
fun(Field@0) -> {file_error, Field@0} end
) end)(_pipe),
_pipe@4 = gleam@result:'try'(
_pipe@2,
fun(Content) -> _pipe@3 = tom:parse(Content),
gleam@result:map_error(
_pipe@3,
fun(Field@0) -> {toml_error, Field@0} end
) end
),
_pipe@6 = gleam@result:map(
_pipe@4,
fun(Toml) ->
_pipe@5 = tom:get_table(
Toml,
[<<"tools"/utf8>>, <<"iconify_lustre"/utf8>>]
),
gleam@result:unwrap(_pipe@5, maps:new())
end
),
gleam@result:map(
_pipe@6,
fun(Table) ->
{configuration,
Root,
get_string(Table, <<"iconset"/utf8>>, Default_iconset),
get_string(Table, <<"module"/utf8>>, Default_module)}
end
).