Documentation
¶
Overview ¶
Package cli is argv, dispatch and exit codes. Logic belongs in the modules, not here.
The parser is hand-rolled and positional: flags may appear ANYWHERE, including after the command word, `--ui` peeks ahead (a switch for build-image, a value for init), and unrecognised positional words accumulate into `cmd` and `sub`. Go's `flag` stops at the first non-flag argument and cobra would own the usage text — both would change observable behaviour that the CLI goldens pin.
Index ¶
Constants ¶
const ( ExitOK = 0 ExitFailed = 1 ExitLeaked = 2 ExitUsage = 3 )
Exit codes. The distinct code for leaks lets CI treat "torn down but leaked" differently from "teardown errored", which are different problems with different owners.
Variables ¶
var Commands = append(append([]string{}, SpecCommands...), "init", "serve", "build-image", "cloud-init", "dockerfile", "upgrade", "ui", "swarm", "healthcheck")
Commands in usage order.
var SpecCommands = []string{"up", "down", "verify", "status", "validate"}
SpecCommands read a spec; Commands is every command that exists. An unknown command must fail as unknown, never by hunting for a spec file — that bug shipped once.
Functions ¶
func IsSpecCommand ¶
IsSpecCommand reports whether name reads a spec.
Types ¶
type Exit ¶
type Exit struct {
Code int
// Msg is printed to stderr prefixed with `pstack: ` when non-empty.
Msg string
}
Exit is how a command ends: a code and an optional stderr line (`pstack: <msg>`).
func Healthcheck ¶
Healthcheck is the container's HEALTHCHECK: one GET against this process's own /api/health, exit 0 or 1. `init` blocks on this verdict, so it must be boring.
func Serve ¶
func Serve(o ServeOptions) *Exit
Serve is `pstack serve`. Blocks until SIGINT/SIGTERM, then stops the server.
func UnknownCommand ¶
UnknownCommand is the refusal for a command this build does not have.
type IO ¶
type IO struct {
Stdin io.Reader
Stdout io.Writer
Stderr io.Writer
Env func(string) (string, bool)
// Environ is the whole environment as a map (what hooks inherit); nil means os.Environ().
Environ map[string]string
// UIHTML and ShareHTML are the embedded pages `serve` hosts.
UIHTML string
}
IO is the process's streams and environment, so a test can drive Run without a process.
type Parsed ¶
type Parsed struct {
Cmd string
Sub string
File string
DryRun bool
Level exec.Level
Overrides map[string]string
OverrideKeys []string
NoVerify bool
Force bool
Domain string
AcmeEmail string
DNSProvider string
Challenge string // http01 | dns01
Orchestrator string // swarm | compose
Distro string
Format string
Tag string
UI string // basic | advanced
UIImage bool
UIDist string
SSHKey string
Password string
ConfigRepo string
Out string
Yes bool
To string
Resume bool
// Typed records which value flags were spelled on the command line, for the two commands that
// must only act on an EXPLICIT --ui / --orchestrator (upgrade, ui).
Typed map[string]bool
// Help and Version short-circuit dispatch.
Help bool
Version bool
}
Parsed is argv, resolved against the environment defaults.