cli

package
v0.0.0-...-9d38c2f Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Package cli is the command tree: Cobra commands, global flags, and how an error becomes an exit code (design §3, §6).

Commands write to cmd.OutOrStdout() and cmd.ErrOrStderr(), never to os.Stdout and os.Stderr directly. Run sets those writers, so the binary gets the real streams and a test gets a buffer, with no other difference.

Index

Constants

View Source
const (
	ExitOK          = 0 // done, possibly from cache
	ExitFailed      = 1 // anything not covered below
	ExitUsage       = 2 // wrong usage: unknown command or flag, bad value
	ExitUnreachable = 3 // Quantic unreachable, and nothing cached
	ExitNotSignedIn = 4 // no token, or Quantic rejected it (401)
	ExitRateLimited = 5 // still rate limited after retrying
)

Exit codes (design §6). A script or the widget branches on these, so they are part of the CLI's contract: a meaning never changes once released.

Variables

This section is empty.

Functions

func ExitCode

func ExitCode(err error) int

ExitCode is the exit status an error from a command maps to: 0 for nil, the code of the first ExitError in its chain, otherwise ExitFailed.

func Run

func Run(args []string, stdin io.Reader, stdout, stderr io.Writer, build Build) int

Run executes the command line in args and returns the process exit code. It never calls os.Exit, so tests can call it as often as they like.

func RunWith

func RunWith(args []string, stdin io.Reader, stdout, stderr io.Writer, build Build, keyring auth.Keyring) int

RunWith is Run with another keyring. The binary always uses the system's; tests use one of their own, so they never touch the keyring of the machine they run on.

Types

type Build

type Build struct {
	Version string
	Commit  string
	Date    string // the commit's date, not the build's: see main.go
}

Build is the stamp main receives from the linker. Any field can be empty: a `go build` or `go install` sets none of them.

type ExitError

type ExitError struct {
	Code int
	Err  error
}

ExitError is an error that knows which exit code it means. Commands return one when the plain "1" isn't enough; any other error exits 1.

func (*ExitError) Error

func (e *ExitError) Error() string

func (*ExitError) Unwrap

func (e *ExitError) Unwrap() error

Unwrap lets errors.Is and errors.As see the error underneath, so wrapping an error in an exit code doesn't hide what it was.

type Options

type Options struct {
	JSON      bool
	Portfolio string
	NoCache   bool
	Timeout   time.Duration
	// contains filtered or unexported fields
}

Options holds the global flags (design §3). Every command sees the same one, through the pointer its constructor received.

Jump to

Keyboard shortcuts

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