cli

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2026 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Overview

Package cli wires wfctl's command tree. It owns everything the pure packages below it deliberately refuse to know: the kubeconfig, the clock, the terminal, and which snapshot provider a given invocation should use.

Nothing here decides what a picture means (that is internal/wfctl/snapshot) or how it reads (that is internal/wfctl/render). Keeping the split sharp is what lets the renderers be golden-tested and the providers be swapped for a file with a single flag.

Index

Constants

This section is empty.

Variables

View Source
var Version = "dev"

Version is stamped into every snapshot's ClusterIdent so a captured picture says which wfctl produced it. Release builds set it with `-ldflags "-X .../internal/wfctl/cli.Version=v1.2.3"`.

Functions

func Fail

func Fail(w io.Writer, err error) int

Fail reports a command error and returns the process exit status.

It is the whole of main's error handling, which is why it lives here where it can be tested rather than in the binary where it cannot.

func NewRootCommand

func NewRootCommand(argv0 string) *cobra.Command

NewRootCommand builds the wfctl command tree.

argv0 is the invoked path: installed as `kubectl-wavefront`, the binary is a kubectl plugin and must describe itself as `kubectl wavefront` in every usage line, because that is what the user has to type.

Types

type ExitError

type ExitError struct {
	Code int
	Err  error
}

ExitError carries a non-default exit status out of a command.

A nil Err exits silently: `status` exits 2 on a blocked fleet *after* printing its report, and a second "Error:" line under a table that already says BLOCKED would be noise, not information.

func (*ExitError) Error

func (e *ExitError) Error() string

func (*ExitError) Unwrap

func (e *ExitError) Unwrap() error

type Options

type Options struct {
	ConfigFlags *genericclioptions.ConfigFlags

	// Wavefront names the Wavefront to operate on; empty auto-selects the
	// only one.
	Wavefront string
	// Output is one of the output* constants.
	Output string
	// NoColor suppresses colour even on a terminal.
	NoColor bool
	// Yes skips the confirmation prompt of the write commands. It is declared
	// here because it is a persistent flag of the tree, not of any one command.
	Yes bool
	// DryRun prints a write command's plan and stops. Unlike Yes it is a local
	// flag of each write command, because a read command has no plan to print.
	DryRun bool
	// Derive re-derives the picture live instead of reading published status.
	Derive bool
	// Poll adds a ref-advertisement sweep to a derivation.
	Poll bool
	// PollTimeout bounds one ref listing.
	PollTimeout time.Duration
	// PerHostConcurrency bounds concurrent listings per git host; 0 takes the
	// Wavefront's own spec.poll.perHostConcurrency.
	PerHostConcurrency int
	// From replays a captured snapshot instead of reading a cluster.
	From string

	// Now is the clock every rendered age is anchored to; nil means the wall
	// clock. render.Options.Now is always set from it, so no renderer ever
	// falls back to a clock of its own.
	Now func() time.Time
	// NewReader builds the cluster reader; nil means the real one, built from
	// ConfigFlags. Tests substitute a fake so the command tree can be driven
	// without an apiserver.
	NewReader func() (client.Reader, error)
	// NewClient builds the read-write client the write commands operate
	// through; nil means the real one, built from ConfigFlags. It is separate
	// from NewReader so that the read commands stay unable to write even by
	// accident.
	NewClient func() (client.Client, error)
	// Lister lists a source's advertised refs for `pin --poll` and
	// `force-admit`; nil means the production go-git lister.
	Lister gitpoll.Lister
	// StdinTTY reports whether stdin is an interactive terminal, i.e. whether
	// there is anybody to answer a confirmation prompt; nil means "ask
	// os.Stdin".
	StdinTTY func() bool
	// Identity names who is running the command, for the audit note; nil means
	// the kubeconfig-derived one.
	Identity func() string
	// ColorTTY reports whether the output is an interactive terminal; nil
	// means "ask os.Stdout".
	ColorTTY func() bool
	// ClusterIdent stamps a captured snapshot with the cluster it came from;
	// nil means the kubeconfig-derived one. It is a seam because the default
	// reads the ambient kubeconfig, which a test must not depend on even when
	// NewReader has replaced the client.
	ClusterIdent func() snapshot.ClusterIdent
}

Options is the state every command shares: the persistent flags, plus the two seams (clock and client construction) that let the command tree be exercised without a cluster.

func NewOptions

func NewOptions() *Options

NewOptions is the tree's default state: the real kubeconfig flags and every seam left at its production value.

Jump to

Keyboard shortcuts

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