Current section
Files
Jump to
Current section
Files
src/glm_freebsd.erl
-module(glm_freebsd).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/glm_freebsd.gleam").
-export([main/0]).
-export_type([app/0]).
-type app() :: {app, binary(), binary(), binary()}.
-file("src/glm_freebsd.gleam", 17).
-spec input_opt() -> clip@opt:opt(binary()).
input_opt() ->
_pipe = clip@opt:new(<<"input"/utf8>>),
clip@opt:help(
_pipe,
<<"path to target app (directory with gleam.toml, and environment file, if provided.)"/utf8>>
).
-file("src/glm_freebsd.gleam", 21).
-spec output_opt() -> clip@opt:opt(binary()).
output_opt() ->
_pipe = clip@opt:new(<<"output"/utf8>>),
clip@opt:help(
_pipe,
<<"path to place generated files (will create output dir)"/utf8>>
).
-file("src/glm_freebsd.gleam", 25).
-spec log_opt() -> clip@opt:opt(binary()).
log_opt() ->
_pipe = clip@opt:new(<<"log"/utf8>>),
_pipe@1 = clip@opt:default(_pipe, <<"info"/utf8>>),
clip@opt:help(_pipe@1, <<"log output verbosity, debug|warn|error"/utf8>>).
-file("src/glm_freebsd.gleam", 31).
-spec templates() -> clip:command(app()).
templates() ->
_pipe = clip:command(
begin
clip:parameter(
fun(Input) ->
clip:parameter(
fun(Output) ->
clip:parameter(
fun(Log) -> {app, Input, Output, Log} end
)
end
)
end
)
end
),
_pipe@1 = clip:opt(_pipe, input_opt()),
_pipe@2 = clip:opt(_pipe@1, output_opt()),
clip:opt(_pipe@2, log_opt()).
-file("src/glm_freebsd.gleam", 44).
-spec configure_logging(binary()) -> nil.
configure_logging(Level) ->
_ = logging_ffi:configure(),
Level@1 = begin
_pipe = Level,
string:lowercase(_pipe)
end,
Logging_level = case Level@1 of
<<"debug"/utf8>> ->
debug;
<<"info"/utf8>> ->
info;
<<"error"/utf8>> ->
error;
_ ->
debug
end,
_ = logging:set_level(Logging_level),
gleam_stdlib:println(<<"logging level set to: "/utf8, Level@1/binary>>),
logging:log(info, <<"application starting..."/utf8>>).
-file("src/glm_freebsd.gleam", 59).
-spec debug(binary()) -> nil.
debug(S) ->
logging:log(
debug,
<<"------------------------------------------------------------------"/utf8>>
),
logging:log(debug, S),
logging:log(
debug,
<<"------------------------------------------------------------------"/utf8>>
).
-file("src/glm_freebsd.gleam", 65).
-spec main() -> nil.
main() ->
Result = begin
_pipe = templates(),
_pipe@1 = clip:help(
_pipe,
clip@help:simple(
<<"templates"/utf8>>,
<<"generate templates for target app"/utf8>>
)
),
clip:run(_pipe@1, erlang:element(4, argv:load()))
end,
case Result of
{error, E} ->
logging:log(error, E);
{ok, App} ->
Input_path = erlang:element(2, App),
Output_path = erlang:element(3, App),
configure_logging(erlang:element(4, App)),
Gleam_toml_path = <<Input_path/binary, "/gleam.toml"/utf8>>,
debug(<<"load gleam.toml file"/utf8>>),
Cfg = glm_freebsd@config:load_toml(Gleam_toml_path, Output_path),
debug(<<"create directories"/utf8>>),
case simplifile:create_directory_all(Output_path) of
{ok, _} -> nil;
_assert_fail ->
erlang:error(#{gleam_error => let_assert,
message => <<"Pattern match failed, no pattern matched the value."/utf8>>,
file => <<?FILEPATH/utf8>>,
module => <<"glm_freebsd"/utf8>>,
function => <<"main"/utf8>>,
line => 81,
value => _assert_fail,
start => 2214,
'end' => 2277,
pattern_start => 2225,
pattern_end => 2230})
end,
debug(<<"gen files from templates"/utf8>>),
_ = glm_freebsd@freebsd_templates:gen_files_from_templates(
Cfg,
Output_path
),
debug(<<"package files into freebsd package"/utf8>>),
_ = glm_freebsd@freebsd_build:run_build(
Cfg,
Input_path,
Output_path
),
nil
end.