Cherry.CLI.Command behaviour (cherry v0.6.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

The command's full doc text — the single source reused as the mix task's @moduledoc and rendered by cherry help <verb> and cherry <verb> --help. The first line doubles as the one-line summary on the base help screen.

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

Executes the command.

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

Callbacks

doc()

@callback doc() :: String.t()

The command's full doc text — the single source reused as the mix task's @moduledoc and rendered by cherry help <verb> and cherry <verb> --help. The first line doubles as the one-line summary on the base help screen.

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.