View Source edifa_exec (edifa v1.0.0)

Summary

Types

-type call_return() ::
          {call, [call_spec() | command_handler()], LastResult :: term(), NewState :: term()}.
-type call_spec() ::
          #{cmd := atom(),
            args => [string() | binary()],
            env =>
                [string() |
                 binary() |
                 clear |
                 {Name :: string() | binary(), Val :: string() | binary() | false}],
            on_start => start_handler(),
            on_data => data_handler(),
            on_exit => exit_handler(),
            handler => command_handler(),
            input => undefined | command_input_data(),
            result =>
                undefined |
                {match, iodata() | unicode:charlist()} |
                {match, iodata() | unicode:charlist(), re:options()} |
                {match, iodata() | unicode:charlist(), re:options(), fun((list()) -> term())} |
                {collect, stdout | stderr | both},
            result_default => undefined,
            keep_result => undefined | atom(),
            error =>
                undefined |
                {match, iodata() | unicode:charlist()} |
                {match, iodata() | unicode:charlist(), re:options()} |
                {match, iodata() | unicode:charlist(), re:options(), fun((list()) -> term())} |
                {collect, stdout | stderr | both},
            error_default => undefined,
            error_as_result => undefined | boolean()}.
-type command_exit() ::
          {exit,
           {status, Status :: integer()} | {signal, Signal :: integer()} | {down, Reason :: term()}}.
-type command_handler() :: full_command_handler() | simple_command_handler().
-type command_input() :: {stdin, InputLine :: binary() | eof}.
-type command_input_data() :: eof | [iodata() | [eof]] | iodata().
-type command_message() ::
          {start, LastResult :: term()} | command_output() | command_exit() | {message, Msg :: term()}.
-type command_output() :: {stdout, OuputLine :: binary()} | {stderr, ErrorLine :: binary()}.
-type continue_return() ::
          {continue, NewState :: term()} |
          {continue, Inputs :: command_input_data(), NewState :: term()}.
-type data_handler() ::
          fun((State :: term(), command_output()) ->
                  continue_return() | ok_return() | call_return() | error_return()).
-type deep_call_list() :: [call_spec() | command_handler() | deep_call_list()].
-type error_return() :: {error, Reason :: term()} | {error, Reason :: term(), NewState :: term()}.
-type exit_handler() ::
          fun((State :: term(), command_exit()) -> ok_return() | call_return() | error_return()).
Link to this type

full_command_handler/0

View Source
-type full_command_handler() ::
          fun((State :: term(), call_spec(), command_message()) ->
                  continue_return() | ok_return() | call_return() | error_return()).
-type log_event() ::
          {exec, Args :: [binary()]} |
          command_input() |
          command_output() |
          command_exit() |
          {result, term()} |
          {error, term()}.
-type log_handler() :: stateless_log_handler() | statefull_log_handler().
-type ok_return() :: {ok, NewState :: term()} | {ok, Result :: term(), NewState :: term()}.
Link to this type

simple_command_handler/0

View Source
-type simple_command_handler() ::
          fun((State :: term(), LastResult :: term()) -> ok_return() | call_return() | error_return()).
-type start_handler() ::
          fun((State :: term(), LastResult :: term()) ->
                  continue_return() | ok_return() | call_return() | error_return()).
-type state() ::
          #state{terminating :: boolean(),
                 parent :: pid(),
                 exec_pid :: pid(),
                 mod :: module(),
                 sub :: term(),
                 cmd_paths :: #{atom() => {binary(), binary()}},
                 stdout_buffer :: binary(),
                 stderr_buffer :: binary()}.
Link to this type

statefull_log_handler/0

View Source
-type statefull_log_handler() :: fun((log_event(), State1 :: term()) -> State2 :: term()).
Link to this type

stateless_log_handler/0

View Source
-type stateless_log_handler() :: fun((log_event()) -> ok).

Functions

Link to this function

call(Pid, Name, Args, Opts)

View Source
-spec command(term(), call_spec() | deep_call_list()) -> ok_return() | call_return().
Link to this function

command(State, Cmd, Args)

View Source
-spec command(term(), atom(), [string() | binary()]) -> ok_return() | call_return().
Link to this function

find_executables(Rest, Map)

View Source
-spec log(term()) -> ok.