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", "pull", "push", "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
// AdminUser / AdminPassword / APIToken are cloud-init's credential flags. Deliberately WITHOUT
// environment defaults, unlike --password (PSTACK_DASHBOARD_PASSWORD) beside them: an operator's
// shell has PSTACK_TOKEN set precisely because it is talking to a host that already exists, and a
// default would silently clone that host's bearer token into a new host's user-data. The pair
// follows the token because they are the same decision — the credentials of one specific host.
AdminUser string
AdminPassword string
APIToken string
ConfigRepo string
// Config / ConfigURL are cloud-init's two ways to carry a `pull config` export onto a new host:
// the sealed file itself, or a URL the host fetches at boot. Mutually exclusive, and both need
// PSTACK_CONFIG_KEY — see cloudInit().
//
// The PASSPHRASE is deliberately not here and has no flag anywhere: argv is world-readable
// through `ps`, so it comes from PSTACK_CONFIG_KEY or a no-echo prompt. Keeping it out of this
// struct also keeps it out of the `t.Errorf("got %+v", p)` that every parser test does.
Config string
ConfigURL string
Out string
// In is `-i` — the file `push config` reads. The counterpart of Out.
In 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.