Current section

Files

Jump to
dotenv_gleam src dotenv_gleam.erl
Raw

src/dotenv_gleam.erl

-module(dotenv_gleam).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-export([config_with/1, config/0]).
-file("/Users/grubba/Desktop/personal/gleam_dotenv/src/dotenv_gleam.gleam", 35).
-spec config_with(binary()) -> nil.
config_with(File) ->
_assert_subject = simplifile:read(File),
{ok, Env_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 => <<"dotenv_gleam"/utf8>>,
function => <<"config_with"/utf8>>,
line => 36})
end,
_pipe = gleam@string:split(Env_file, <<"\n"/utf8>>),
_pipe@1 = gleam@list:filter(_pipe, fun(Line) -> Line /= <<""/utf8>> end),
gleam@list:each(
_pipe@1,
fun(Line@1) ->
Splited_line = gleam@string:split(Line@1, <<"="/utf8>>),
Key = begin
_pipe@2 = gleam@list:first(Splited_line),
_pipe@3 = gleam@result:unwrap(_pipe@2, <<""/utf8>>),
gleam@string:trim(_pipe@3)
end,
Value = begin
_pipe@4 = gleam@list:drop(Splited_line, 1),
_pipe@5 = gleam@string:join(_pipe@4, <<"="/utf8>>),
gleam@string:trim(_pipe@5)
end,
envoy_ffi:set(Key, Value)
end
).
-file("/Users/grubba/Desktop/personal/gleam_dotenv/src/dotenv_gleam.gleam", 19).
-spec config() -> nil.
config() ->
config_with(<<".env"/utf8>>).