Packages

CLI tool to package a Gleam app as a FreeBSD package, with a service script.

Current section

Files

Jump to
glm_freebsd src glm_freebsd.erl
Raw

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()}.
-file("src/glm_freebsd.gleam", 15).
-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)"/utf8>>
).
-file("src/glm_freebsd.gleam", 19).
-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", 23).
-spec templates() -> clip:command(app()).
templates() ->
_pipe = clip:command(
begin
clip:parameter(
fun(Input) ->
clip:parameter(fun(Output) -> {app, Input, Output} end)
end
)
end
),
_pipe@1 = clip:opt(_pipe, input_opt()),
clip:opt(_pipe@1, output_opt()).
-file("src/glm_freebsd.gleam", 35).
-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} ->
gleam_stdlib:println_error(E);
{ok, App} ->
Input_path = erlang:element(2, App),
Output_path = erlang:element(3, App),
Gleam_toml_path = <<Input_path/binary, "/gleam.toml"/utf8>>,
Cfg = glm_freebsd@config:load_toml(Gleam_toml_path, Output_path),
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 => 48,
value => _assert_fail,
start => 1146,
'end' => 1209,
pattern_start => 1157,
pattern_end => 1162})
end,
_ = glm_freebsd@freebsd_templates:gen_files_from_templates(
Cfg,
Output_path
),
_ = glm_freebsd@freebsd_build:run_build(
Cfg,
Input_path,
Output_path
),
nil
end.