cli

package
v0.29.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 24, 2026 License: MIT, MIT Imports: 29 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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

View Source
var Commands = append(append([]string{}, SpecCommands...), "init", "serve", "build-image", "cloud-init", "dockerfile", "upgrade", "ui", "swarm", "healthcheck")

Commands in usage order.

View Source
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 IsCommand

func IsCommand(name string) bool

IsCommand reports whether name is a known command.

func IsSpecCommand

func IsSpecCommand(name string) bool

IsSpecCommand reports whether name reads a spec.

func ParseArgs

func ParseArgs(argv []string, env func(string) (string, bool)) (*Parsed, *Exit)

ParseArgs walks argv. `env` is os.LookupEnv-shaped so a test can pin the defaults.

func Run

func Run(argv []string, io IO) int

Run is the CLI: argv in, exit code out. Every `process.exit` in the reference is a return here.

func Usage

func Usage(version string) string

Usage is the --help text, byte for byte.

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

func Healthcheck(env func(string) (string, bool)) *Exit

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

func UnknownCommand(cmd, version string) *Exit

UnknownCommand is the refusal for a command this build does not have.

func (*Exit) Error

func (e *Exit) Error() string

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
	ShareHTML 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.

type ServeOptions

type ServeOptions struct {
	UIHTML    string
	ShareHTML string
	Stdout    io.Writer
	Stderr    io.Writer
	// Env is the process environment (os.LookupEnv-shaped); nil means the real one.
	Env func(string) (string, bool)
}

ServeOptions are what the binary hands `serve`: the two embedded pages and the streams.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL