Documentation
¶
Overview ¶
Package cli holds the `brigade` command table, the interspersed-flag parser of plan 7.3, the usage and help output, and the mapping from a command failure to a process exit status (4.6).
Nothing in this package touches os.Stdout, os.Stderr, os.Exit or os.Getenv. Streams arrive as io.Writer values and the environment arrives as a slice, which is both the stdout discipline of 7.3 and what makes every command testable without a subprocess.
Index ¶
- Constants
- Variables
- func Dispatch(args []string, s Streams, environ []string) int
- func NotImplemented(cmd Command, args []string, s Streams) int
- func Usage(cmd Command, args []string, s Streams, message string) int
- func WriteError(w io.Writer, err *Error) error
- func WriteResult(w io.Writer, result any) error
- type Code
- type Command
- type Context
- type Error
- type Streams
- type SyncAdapterFunc
Constants ¶
const ( CodeInternal = protocol.CodeInternal CodeUsage = protocol.CodeUsage CodeInvalidInput = protocol.CodeInvalidInput CodeUnauthenticated = protocol.CodeUnauthenticated CodeNotFound = protocol.CodeNotFound CodeConflict = protocol.CodeConflict CodeRateLimited = protocol.CodeRateLimited CodeProtocolMismatch = protocol.CodeProtocolMismatch CodeConfig = protocol.CodeConfig CodeLoopDetected = protocol.CodeLoopDetected )
The 4.6 error codes, in exit-code order.
const ExitOK = protocol.ExitOK
ExitOK is the exit status of a command that succeeded.
const PoisonFlag = "join-secret"
PoisonFlag is the flag name whose mere presence on argv is a usage error: a join secret must never be visible in a process listing, a shell history, or a Claude Code transcript (4.5.14, C-05, 5.11).
const Program = "brigade"
Program is the name the binary is documented and invoked under. It is a constant on purpose: argv[0] is the bootstrap's cache path on every legitimate call (6.4), so it is not a usable identity.
const ProtocolVersion = protocol.ProtocolVersion
ProtocolVersion is the value of the `protocol_version` member of every result envelope (plan 4.3). It is owned by internal/protocol; this alias keeps the CLI's callers and tests reading naturally.
Variables ¶
var LogLevels = []string{"debug", "info", "warn", "error"}
LogLevels are the accepted values of the global --log-level flag.
Functions ¶
func Dispatch ¶
Dispatch runs one `brigade` invocation and returns its exit status. args excludes the program name.
func NotImplemented ¶
NotImplemented reports a recognised multi-call entrypoint that internal/app intercepts but cannot run yet. It exists so that `brigade hook …` and `brigade watch …` fail with the plan task that builds them rather than as an unknown command.
func Usage ¶
Usage reports a `usage` refusal of a multi-call entrypoint that internal/app dispatches itself (the adapter name after `brigade adapter`), through the same reporter the table uses. message is fixed text and never carries an argument: argv can hold a secret (4.5.14).
func WriteError ¶
WriteError writes a failing 4.3 envelope for err.
Types ¶
type Code ¶
A Code is the machine-readable `error.code` of the plan's 4.6 taxonomy.
The taxonomy — the Code type, its constants, Exit and Retryable — is owned by internal/protocol (the P1-2 row of the plan): adapters and the harness need it without importing the CLI. This file is the thin alias the P1-1 note in its place promised, not a second copy: the type alias means a protocol.Code and a cli.Code are the same type, so the exit-code map cannot fork.
type Command ¶
type Command struct {
// Name is the first argv word that selects the command.
Name string
// Args is the argv summary shown after the name in help, without the
// global flags.
Args string
// Summary is the one-line description shown by `brigade help`.
Summary string
// Hidden keeps the command out of `brigade help` but not out of
// `brigade help --all` or `brigade help <name>` (6.4).
Hidden bool
// MultiCall marks the entrypoints internal/app intercepts before the
// human command table: `hook`, `watch` and `adapter`.
MultiCall bool
// Task names the plan task that implements the command. It is set only
// while the command is still a placeholder, and is what the
// not-implemented message points the caller at. No entry carries one
// since P5-9 filled `inbox`; the mechanism stays for the next one.
Task string
// Flags registers the command's own flags. The global flags are added
// separately, so a command must not register --json or --log-level.
Flags func(fs *flag.FlagSet)
// Raw hands Run everything after the command word verbatim instead of
// parsing it: the terminal pass-through commands (`team`, `profile`)
// forward adapter flags the harness has never heard of, so their
// grammar is their own (6.4). The global flags BEFORE the command
// word still apply, --json is honoured wherever it appears, and the
// poison scan runs first as for every command.
Raw bool
// Run executes the command. It is nil exactly when Task is set.
Run func(cx *Context, args []string) error
}
A Command is one entry of the `brigade` command table (6.4).
func LookupMultiCall ¶
LookupMultiCall returns the table entry for name when internal/app is the dispatcher for it rather than the human command table.
func (Command) Implemented ¶
Implemented reports whether the command does real work yet.
type Context ¶
type Context struct {
Streams
// Environ is the process environment in os.Environ() form. Commands
// read configuration from here, never from os.Getenv, so a test can
// hand a command an environment without mutating its own (3.2, 7.3).
Environ []string
// JSON is the global --json flag: the protocol envelope on stdout
// instead of human output.
JSON bool
// LogLevel is the global --log-level flag, validated against LogLevels.
LogLevel string
// Command is the resolved command name.
Command string
// Flags is the command's own parsed flag set.
Flags *flag.FlagSet
}
A Context carries everything a command may read: its streams, the environment it was given, and the global flags.
type Error ¶
type Error struct {
// Code selects the exit status and appears as `error.code`.
Code Code
// Message is short, human-readable and safe to show to a model: no raw
// server text, no SQL, no tokens (4.3).
Message string
// RetryAfterMS is emitted only when non-zero (rate_limited).
RetryAfterMS int
// Details is optional and adapter-specific (4.3).
Details map[string]string
// Command names the command for the one-line stderr form. Empty when
// the failure happened before a command was resolved.
Command string
}
An Error is a command failure carrying the 4.6 code that decides both the process exit status and the `error` object of the JSON envelope.
type SyncAdapterFunc ¶ added in v0.11.0
type SyncAdapterFunc func(args []string, stdin io.Reader, stdout, stderr io.Writer, environ []string) int
A SyncAdapterFunc runs one bundled sync adapter (docs/sync-adapters.md): args are the words after its name — the verb — and it speaks the sync-adapter protocol on the real process streams, returning the exit status.
func LookupSyncAdapter ¶ added in v0.11.0
func LookupSyncAdapter(name string) (SyncAdapterFunc, bool)
LookupSyncAdapter returns the bundled sync adapter named name.