JustBash.Commands.Command behaviour (JustBash v0.3.0)

View Source

Behaviour for bash commands.

Each command module implements this behaviour, providing a consistent interface for command execution.

Summary

Callbacks

Execute the command with the given arguments and stdin.

Returns the command name(s) this module handles.

Functions

Create a failed result with stderr output.

Create a successful result with stdout output.

Resolve a path relative to the current working directory.

Create a result with custom stdout, stderr, and exit code.

Types

bash()

@type bash() :: JustBash.t()

execution_result()

@type execution_result() :: {result(), bash()}

result()

@type result() :: map()

Callbacks

execute(bash, args, stdin)

@callback execute(bash(), args :: [String.t()], stdin :: String.t()) :: execution_result()

Execute the command with the given arguments and stdin.

names()

@callback names() :: [String.t()]

Returns the command name(s) this module handles.

Functions

error(stderr, exit_code \\ 1)

@spec error(String.t(), non_neg_integer()) :: result()

Create a failed result with stderr output.

ok(stdout \\ "")

@spec ok(String.t()) :: result()

Create a successful result with stdout output.

resolve_path(bash, path)

@spec resolve_path(bash(), String.t()) :: String.t()

Resolve a path relative to the current working directory.

result(stdout, stderr, exit_code)

@spec result(String.t(), String.t(), non_neg_integer()) :: result()

Create a result with custom stdout, stderr, and exit code.