JustBash.Commands.Command behaviour (JustBash v0.4.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.

The returned result map must carry :stdout, :stderr, and :exit_code, but may contain extra keys. The executor preserves them past result validation, dropping only internal control-flow signals before the result reaches the shell. This is load-bearing: JustBash.CLI smuggles its resolved subcommand path through under :__subcommand__ so command telemetry can attribute it (the executor pops it into span metadata). Do not tighten the result match to reject unknown keys.

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()) :: JustBash.FS.resolved()

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.