-module(adglent@init). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). -export([main/0]). -file("/Users/john.bjork/git/adglent/src/adglent/init.gleam", 19). -spec main() -> {ok, binary()} | {error, binary()}. main() -> Year = priv@prompt:value(<<"Year"/utf8>>, <<"2023"/utf8>>, false), Session = priv@prompt:value(<<"Session Cookie"/utf8>>, <<""/utf8>>, false), Use_showtime = priv@prompt:confirm(<<"Use showtime"/utf8>>, false), Aoc_toml_file = <<"aoc.toml"/utf8>>, Overwrite = case simplifile:create_file(Aoc_toml_file) of {ok, _} -> true; {error, eexist} -> priv@prompt:confirm(<<"aoc.toml exits - overwrite"/utf8>>, false); _ -> erlang:error(#{gleam_error => panic, message => <<"Could not create aoc.toml"/utf8>>, module => <<"adglent/init"/utf8>>, function => <<"main"/utf8>>, line => 29}) end, _ = begin _pipe@3 = case Overwrite of true -> _pipe@1 = priv@template:render( <<" version = {{ version }} year = \"{{ year }}\" session = \"{{ session }}\" showtime = {{ showtime }} "/utf8>>, [{<<"version"/utf8>>, <<"2"/utf8>>}, {<<"year"/utf8>>, Year}, {<<"session"/utf8>>, Session}, {<<"showtime"/utf8>>, begin _pipe = gleam@bool:to_string(Use_showtime), gleam@string:lowercase(_pipe) end}] ), _pipe@2 = simplifile:write(Aoc_toml_file, _pipe@1), priv@errors:map_messages( _pipe@2, <<"aoc.toml - written"/utf8>>, <<"Error when writing aoc.toml"/utf8>> ); false -> {ok, <<"aoc.toml - skipped"/utf8>>} end, priv@errors:print_result(_pipe@3) end, Gleam_toml = begin _pipe@4 = simplifile:read(<<"gleam.toml"/utf8>>), _pipe@5 = priv@errors:map_error( _pipe@4, <<"Could not read gleam.toml"/utf8>> ), _pipe@6 = priv@errors:print_error(_pipe@5), priv@errors:assert_ok(_pipe@6) end, Name = begin _pipe@7 = priv@toml:get_string(Gleam_toml, [<<"name"/utf8>>]), _pipe@8 = priv@errors:map_error( _pipe@7, <<"Could not read \"name\" from gleam.toml"/utf8>> ), _pipe@9 = priv@errors:print_error(_pipe@8), priv@errors:assert_ok(_pipe@9) end, Have_showtime_dependency = begin _pipe@10 = priv@toml:get_string( Gleam_toml, [<<"dependencies"/utf8>>, <<"showtime"/utf8>>] ), gleam@result:is_ok(_pipe@10) end, Test_main_file = <<<<"test/"/utf8, Name/binary>>/binary, "_test.gleam"/utf8>>, _pipe@13 = case Use_showtime of true -> _pipe@11 = priv@template:render( <<" import showtime pub fn main() { showtime.main() } "/utf8>>, [] ), _pipe@12 = simplifile:write(Test_main_file, _pipe@11), priv@errors:map_messages( _pipe@12, <<"Wrote "/utf8, Test_main_file/binary>>, <<"Could not write to "/utf8, Test_main_file/binary>> ); false -> {ok, <<"Using existing (gleeunit) "/utf8, Test_main_file/binary>>} end, _pipe@14 = priv@errors:print_result(_pipe@13), priv@errors:assert_ok(_pipe@14), _pipe@21 = case {Use_showtime, Have_showtime_dependency} of {true, false} -> _pipe@15 = Gleam_toml, _pipe@16 = gleam@string:split(_pipe@15, <<"\n"/utf8>>), _pipe@17 = gleam@list:fold( _pipe@16, [], fun(Lines, Line) -> case Line of <<"[dependencies]"/utf8>> -> [<<"showtime = \"~> 0.2\""/utf8>>, Line | Lines]; _ -> [Line | Lines] end end ), _pipe@18 = lists:reverse(_pipe@17), _pipe@19 = gleam@string:join(_pipe@18, <<"\n"/utf8>>), _pipe@20 = simplifile:write(<<"gleam.toml"/utf8>>, _pipe@19), priv@errors:map_messages( _pipe@20, <<"Wrote "/utf8, "gleam.toml"/utf8>>, <<"Could not write to "/utf8, "gleam.toml"/utf8>> ); {true, true} -> {ok, <<"Skip add of showtime dependency (already present)"/utf8>>}; {false, _} -> {ok, <<"Skip add of showtime dependency (not configured)"/utf8>>} end, _pipe@22 = priv@errors:print_result(_pipe@21), priv@errors:assert_ok(_pipe@22), _pipe@26 = case simplifile_erl:is_file(<<".gitignore"/utf8>>) of {ok, true} -> gleam@result:'try'( begin _pipe@23 = simplifile:read(<<".gitignore"/utf8>>), gleam@result:map_error( _pipe@23, fun(Err) -> <<"Could not read .gitignore: "/utf8, (gleam@string:inspect(Err))/binary>> end ) end, fun(Gitignore) -> Aoc_toml_ignored = begin _pipe@24 = gleam@string:split(Gitignore, <<"\n"/utf8>>), gleam@list:find( _pipe@24, fun(Line@1) -> Line@1 =:= <<"aoc.toml"/utf8>> end ) end, case Aoc_toml_ignored of {error, _} -> _pipe@25 = simplifile:append( <<".gitignore"/utf8>>, <<"\naoc.toml"/utf8>> ), priv@errors:map_messages( _pipe@25, <<".gitignore written"/utf8>>, <<"Error when writing .gitignore"/utf8>> ); {ok, _} -> {ok, <<".gitignore - skipped (already configured)"/utf8>>} end end ); {ok, false} -> {error, <<"Could not find .gitignore"/utf8>>}; {error, _} -> {error, <<"Could not find .gitignore"/utf8>>} end, priv@errors:print_result(_pipe@26).