Skip to main content

src/oaisp@internal@exec.erl

-module(oaisp@internal@exec).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/oaisp/internal/exec.gleam").
-export([run/1]).
-export_type([output/0]).

-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(false).

-type output() :: {output, integer(), binary()}.

-file("src/oaisp/internal/exec.gleam", 17).
?DOC(false).
-spec run(binary()) -> output().
run(Command) ->
    {Exit_code, Bytes} = oaisp_ffi:run(Command),
    Stdout = case gleam@bit_array:to_string(Bytes) of
        {ok, Text} ->
            Text;

        {error, nil} ->
            <<""/utf8>>
    end,
    {output, Exit_code, Stdout}.