cli

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: MIT Imports: 55 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 builds the patchy command tree.

The grammar is Kubernetes-standard: patchy <verb> <noun> [name...]. Verbs are cobra commands, nouns are resolved through the resource registry, and adding a noun never adds a verb. This keeps the surface predictable as new nouns arrive alongside the pipeline ones.

Two rules hold everywhere in this package:

  • stdout is data, stderr is narration. Anything a script might parse goes to stdout and nothing else does, so `patchy get findings -o json | jq` works with logging turned all the way up.
  • presentation is decided once, from the output format and whether stdout is a terminal, never per call site. See internal/printer.

Index

Constants

View Source
const (
	// ExitOK reports success.
	ExitOK = 0
	// ExitError reports a runtime failure: unreachable cluster, bad response.
	ExitError = 1
	// ExitUsage reports a malformed invocation. Cobra's own errors land here.
	ExitUsage = 2
	// ExitNotFound reports that a named resource does not exist.
	ExitNotFound = 3
	// ExitDenied reports that RBAC refused the action, or that the finding's
	// current phase (or the backfill request's state) has no use for it. Both
	// mean nothing was done, which is what a script needs to know.
	ExitDenied = 4
)

Exit codes. A CLI that only ever returns 1 forces scripts to grep stderr, so the cases a caller might reasonably branch on get their own code.

Variables

This section is empty.

Functions

func Execute

func Execute() int

Execute builds and runs the CLI, returning the process exit code. main is the only place allowed to call os.Exit.

func NewRoot

func NewRoot(opts *Options) *cobra.Command

NewRoot builds the command tree against opts.

Types

type Options

type Options struct {
	Kubeconfig     string
	Context        string
	Namespace      string
	AllNamespaces  bool
	Output         string
	NoColor        bool
	RequestTimeout time.Duration
	Verbose        bool

	// Out and ErrOut are the streams commands write to. They live here rather
	// than as globals so tests can capture them.
	Out    io.Writer
	ErrOut io.Writer
	// contains filtered or unexported fields
}

Options carries the persistent flags and the lazily-resolved cluster connection. One instance is shared by the whole command tree.

func (*Options) Connect

func (o *Options) Connect() (*kubecfg.Env, error)

Connect resolves the cluster connection, once per process.

func (*Options) Printer

func (o *Options) Printer() (*printer.Printer, error)

Printer builds the printer for the resolved output format.

func (*Options) Timeout

Timeout derives a per-call context from the command's context.

func (*Options) WithAccess

func (o *Options) WithAccess(fn func(context.Context, *kubecfg.Env, string, string) (bool, error))

WithAccess pins the access-review answer. The fn receives (resource, verb).

func (*Options) WithArchive added in v0.14.0

func (o *Options) WithArchive(fn func(context.Context, archive.Config) (archive.Store, error))

WithArchive pins the archive store the CLI reads, bypassing the cloud SDK credential chains.

func (*Options) WithEnv

func (o *Options) WithEnv(env *kubecfg.Env)

WithEnv pins a pre-built environment, bypassing kubeconfig resolution.

func (*Options) WithIdentity

func (o *Options) WithIdentity(fn func() string)

WithIdentity pins the identity actions are recorded under.

Jump to

Keyboard shortcuts

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