Cherry.CLI.Command behaviour (cherry v0.3.0)

Copy Markdown View Source

Behaviour every Cherry command implements.

A command is pure input → result: it receives a Cherry.CLI.Context and returns {:ok, data} or {:error, %Cherry.CLI.Error{}}. Rendering (human text vs --json envelope) belongs to Cherry.CLI, so commands stay testable without capturing IO.

Summary

Callbacks

Renders the success data as the human-facing output line(s).

Executes the command.

Command-specific OptionParser switches, merged with the global ones.

Callbacks

human(map)

@callback human(map()) :: iodata()

Renders the success data as the human-facing output line(s).

run(t)

@callback run(Cherry.CLI.Context.t()) :: {:ok, map()} | {:error, Cherry.CLI.Error.t()}

Executes the command.

switches()

@callback switches() :: keyword()

Command-specific OptionParser switches, merged with the global ones.