cli

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: MIT Imports: 11 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 holds the command plumbing shared by every patchy binary: the conventional cobra root command and the signal-aware execution wrapper.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Execute

func Execute(root *cobra.Command, log *slog.Logger) int

Execute runs root under a context cancelled by SIGINT/SIGTERM and returns the process exit code; main is the only place allowed to call os.Exit.

func NewControllerRoot

func NewControllerRoot(name, short string, opts *Options) *cobra.Command

NewControllerRoot builds a controller's root command with the shared options bound and flag/env resolution wired into PersistentPreRunE.

func NewRoot

func NewRoot(name, short string) *cobra.Command

NewRoot returns the conventional root command shared by every patchy binary: silenced usage/errors (errors are failures, not usage mistakes; main logs the error once) and cobra's built-in --version reporting the build metadata stamped into internal/version.

Types

type Options

type Options struct {
	// Log is the process logger; main constructs it, telemetry may replace
	// it with a fanout after Init.
	Log *slog.Logger
	// LogLevel is set from --log-level before any command runs.
	LogLevel *slog.LevelVar

	// ListenAddr is the webhook/health HTTP listen address.
	ListenAddr string
	// LogLevelName is the configured level: debug, info, warn, or error.
	LogLevelName string
	// contains filtered or unexported fields
}

Options carries the configuration shared by every controller binary. Precedence: explicit flag > PATCHY_* environment > default.

func NewOptions

func NewOptions() *Options

NewOptions builds Options with the conventional stderr logger and shared verbosity level every binary starts from.

func (*Options) Bind

func (o *Options) Bind(cmd *cobra.Command)

Bind registers the shared persistent flags on cmd and wires the viper environment binding. Call once from each binary's root command setup. Controller-specific flags are declared on the command itself; Load binds them and the String, Duration, Float and Int accessors read them.

func (*Options) Bool added in v0.14.0

func (o *Options) Bool(key string) bool

Bool reads an extra controller-specific boolean value.

func (*Options) Duration

func (o *Options) Duration(key string) time.Duration

Duration reads an extra controller-specific duration value.

func (*Options) Float

func (o *Options) Float(key string) float64

Float reads an extra controller-specific float value.

func (*Options) Int

func (o *Options) Int(key string) int

Int reads an extra controller-specific integer value.

func (*Options) Load

func (o *Options) Load(cmd *cobra.Command) error

Load resolves flag/env precedence into the Options fields. Run it in PersistentPreRunE, after cobra parsed the flags.

func (*Options) String

func (o *Options) String(key string) string

String reads an extra controller-specific value bound via cmd flags, applying the same flag/env precedence.

Jump to

Keyboard shortcuts

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