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 ¶
- func Execute(root *cobra.Command, log *slog.Logger) int
- func NewControllerRoot(name, short string, opts *Options) *cobra.Command
- func NewRoot(name, short string) *cobra.Command
- type Options
- func (o *Options) Bind(cmd *cobra.Command)
- func (o *Options) Duration(key string) time.Duration
- func (o *Options) Float(key string) float64
- func (o *Options) GitHub() (ghclient.Resolver, error)
- func (o *Options) Int(key string) int
- func (o *Options) Load(cmd *cobra.Command) error
- func (o *Options) String(key string) string
- func (o *Options) WebhookSecret() ([]byte, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Execute ¶
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 ¶
NewControllerRoot builds a controller's root command with the shared options bound and flag/env resolution wired into PersistentPreRunE.
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
// WebhookSecretFile names a file holding the GitHub webhook shared
// secret (mounted from a Kubernetes Secret).
WebhookSecretFile string
// GitHubAppID and GitHubAppKeyFile configure GitHub App authentication —
// the production mode.
GitHubAppID int64
GitHubAppKeyFile string
// GitHubToken is the dev-mode personal-access-token fallback; set, it
// wins over App auth.
GitHubToken string
// GitHubBaseURL overrides the API endpoint (GHES, tests).
GitHubBaseURL string
// ReconcileInterval paces the controller's reconcile loop.
ReconcileInterval time.Duration
// 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 ¶
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 bind on top with BindExtra.
func (*Options) GitHub ¶
GitHub builds the API resolver from the configured auth mode: a personal access token when --github-token is set (dev), otherwise the GitHub App credentials (production).
func (*Options) Load ¶
Load resolves flag/env precedence into the Options fields. Run it in PersistentPreRunE, after cobra parsed the flags.
func (*Options) String ¶
String reads an extra controller-specific value bound via cmd flags, applying the same flag/env precedence.
func (*Options) WebhookSecret ¶
WebhookSecret loads the webhook secret from WebhookSecretFile, trimmed of the trailing newline editors and Secret mounts add.