CliSubprocessCore.ProviderProfile behaviour (CliSubprocessCore v0.2.0)

Copy Markdown View Source

Behaviour contract for built-in and external provider CLI profiles.

Summary

Types

Event decode result returned by parser callbacks.

Normalized provider identifier.

Normalized invocation returned by a provider profile.

Parser state owned by an individual provider profile.

Functions

Validates that a module satisfies the provider profile contract.

Returns the callbacks required by the provider profile contract.

Validates a normalized invocation returned by a provider profile.

Types

callback_spec()

@type callback_spec() ::
  {:id, 0}
  | {:capabilities, 0}
  | {:build_invocation, 1}
  | {:init_parser_state, 1}
  | {:decode_stdout, 2}
  | {:decode_stderr, 2}
  | {:handle_exit, 2}
  | {:transport_options, 1}

decode_result()

@type decode_result() :: {[CliSubprocessCore.Event.t()], parser_state()}

Event decode result returned by parser callbacks.

id()

@type id() :: atom()

Normalized provider identifier.

invocation()

@type invocation() :: CliSubprocessCore.Command.t()

Normalized invocation returned by a provider profile.

parser_state()

@type parser_state() :: term()

Parser state owned by an individual provider profile.

Callbacks

build_invocation(keyword)

@callback build_invocation(keyword()) :: {:ok, invocation()} | {:error, term()}

capabilities()

@callback capabilities() :: [atom()]

decode_stderr(binary, parser_state)

@callback decode_stderr(binary(), parser_state()) :: decode_result()

decode_stdout(binary, parser_state)

@callback decode_stdout(binary(), parser_state()) :: decode_result()

handle_exit(term, parser_state)

@callback handle_exit(term(), parser_state()) :: decode_result()

id()

@callback id() :: id()

init_parser_state(keyword)

@callback init_parser_state(keyword()) :: parser_state()

transport_options(keyword)

@callback transport_options(keyword()) :: keyword()

Functions

ensure_module(module)

@spec ensure_module(module()) ::
  :ok
  | {:error, {:module_not_loaded, module()}}
  | {:error, {:missing_callbacks, module(), [{atom(), non_neg_integer()}]}}
  | {:error, {:behaviour_not_declared, module()}}

Validates that a module satisfies the provider profile contract.

required_callbacks()

@spec required_callbacks() :: [callback_spec(), ...]

Returns the callbacks required by the provider profile contract.

validate_invocation(invocation)

@spec validate_invocation(invocation()) ::
  :ok
  | {:error, {:invalid_command, term()}}
  | {:error, {:invalid_args, term()}}
  | {:error, {:invalid_cwd, term()}}
  | {:error, {:invalid_env, term()}}
  | {:error, {:invalid_clear_env, term()}}

Validates a normalized invocation returned by a provider profile.