-module(builder@format). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]). -define(FILEPATH, "src/builder/format.gleam"). -export([format_gleam_code/1]). -if(?OTP_RELEASE >= 27). -define(MODULEDOC(Str), -moduledoc(Str)). -define(DOC(Str), -doc(Str)). -else. -define(MODULEDOC(Str), -compile([])). -define(DOC(Str), -compile([])). -endif. -file("src/builder/format.gleam", 7). ?DOC( " Format Gleam source code using the standard gleam formatter\n" "\n" " Runs the code through `gleam format --stdin` and returns the formatted result.\n" ). -spec format_gleam_code(binary()) -> {ok, binary()} | {error, nil}. format_gleam_code(Code) -> _pipe = shellout:command( <<"sh"/utf8>>, [<<"-euc"/utf8>>, <<<<" echo '"/utf8, Code/binary>>/binary, "' \\ | gleam format --stdin "/utf8>>], <<"."/utf8>>, [let_be_stderr] ), gleam@result:map_error(_pipe, fun(_) -> nil end).