Current section
Files
Jump to
Current section
Files
src/libero@cli@helpers.erl
-module(libero@cli@helpers).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/libero/cli/helpers.gleam").
-export([write_formatted/2, map_err/2]).
-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.
?MODULEDOC(" Shared helpers for CLI scaffold commands (new, add).\n").
-file("src/libero/cli/helpers.gleam", 8).
?DOC(" Write a file, running `gleam format` on .gleam files first.\n").
-spec write_formatted(binary(), binary()) -> {ok, nil} |
{error, simplifile:file_error()}.
write_formatted(Path, Content) ->
Formatted = case gleam_stdlib:string_ends_with(Path, <<".gleam"/utf8>>) of
true ->
libero@format:format_gleam(Content);
false ->
Content
end,
simplifile:write(Path, Formatted).
-file("src/libero/cli/helpers.gleam", 22).
?DOC(
" Map a simplifile.FileError to a user-facing String error, threading\n"
" the success value through a continuation.\n"
" nolint: stringly_typed_error -- CLI module, String errors are user-facing messages\n"
).
-spec map_err(
{ok, UKG} | {error, simplifile:file_error()},
fun((UKG) -> {ok, nil} | {error, binary()})
) -> {ok, nil} | {error, binary()}.
map_err(Result, Next) ->
case Result of
{ok, Value} ->
Next(Value);
{error, Err} ->
{error, simplifile:describe_error(Err)}
end.