Current section

Files

Jump to
squirrel src squirrel@internal@project.erl
Raw

src/squirrel@internal@project.erl

-module(squirrel@internal@project).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-export([name/0, src/0]).
-file("/home/runner/work/squirrel/squirrel/src/squirrel/internal/project.gleam", 20).
-spec try_nil(
{ok, XBN} | {error, any()},
fun((XBN) -> {ok, XBR} | {error, nil})
) -> {ok, XBR} | {error, nil}.
try_nil(Result, Do) ->
gleam@result:'try'(gleam@result:replace_error(Result, nil), Do).
-file("/home/runner/work/squirrel/squirrel/src/squirrel/internal/project.gleam", 42).
-spec find_root(binary()) -> binary().
find_root(Path) ->
Toml = filepath:join(Path, <<"gleam.toml"/utf8>>),
case simplifile_erl:is_file(Toml) of
{ok, false} ->
find_root(filepath:join(<<".."/utf8>>, Path));
{error, _} ->
find_root(filepath:join(<<".."/utf8>>, Path));
{ok, true} ->
Path
end.
-file("/home/runner/work/squirrel/squirrel/src/squirrel/internal/project.gleam", 38).
-spec root() -> binary().
root() ->
find_root(<<"."/utf8>>).
-file("/home/runner/work/squirrel/squirrel/src/squirrel/internal/project.gleam", 11).
-spec name() -> {ok, binary()} | {error, nil}.
name() ->
Configuration_path = filepath:join(root(), <<"gleam.toml"/utf8>>),
try_nil(
simplifile:read(Configuration_path),
fun(Configuration) ->
try_nil(
tom:parse(Configuration),
fun(Toml) ->
try_nil(
tom:get_string(Toml, [<<"name"/utf8>>]),
fun(Name) -> {ok, Name} end
)
end
)
end
).
-file("/home/runner/work/squirrel/squirrel/src/squirrel/internal/project.gleam", 31).
-spec src() -> binary().
src() ->
filepath:join(root(), <<"src"/utf8>>).