rootutil

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package rootutil holds the root-command scaffolding shared by every CLI built on this library: the standard global flags (--verbose, --no-color, --backend, --ref), the PersistentPreRunE wiring that records the backend/credential-ref selection for the next keychain.Open call, and the migration-notice flush that must wrap execution. Each CLI's root package supplies its own Use/Short/Long and command set and calls these helpers, so the plumbing lives in exactly one place.

Index

Constants

View Source
const CredentialRefFlagName = "ref"

CredentialRefFlagName is the global per-invocation credential-ref selector. It shares its name with set-credential's own write-target --ref (a local flag that shadows this persistent one for that command only).

Variables

This section is empty.

Functions

func AddGlobalFlags

func AddGlobalFlags(cmd *cobra.Command, verbose, noColor *bool)

AddGlobalFlags registers the standard persistent flags on cmd, binding verbose and noColor to the given pointers. The --ref help shows the env var by its <SERVICE>_ pattern rather than the resolved name because flags are registered at package-init time, before config.Register runs.

func ApplyGlobalFlags

func ApplyGlobalFlags(cmd *cobra.Command, verbose, noColor bool) error

ApplyGlobalFlags runs the shared PersistentPreRunE logic: verbosity, color, and backend/ref wiring. Each root calls it from its own PersistentPreRunE.

func RunWithMigrationNotice

func RunWithMigrationNotice(ctx context.Context, rootCmd *cobra.Command) error

RunWithMigrationNotice executes rootCmd with the deferred §1.8 migration-notice flush. The defer fires on success AND error, before any os.Exit, so a one-time migration signal is never lost. A --json command consumes the record via output.JSON, making this a no-op for it; everything else gets the human stderr line.

func WireBackendSelection

func WireBackendSelection(cmd *cobra.Command) error

WireBackendSelection validates the user-supplied --backend flag and records it for the next keychain.Open* call. Cobra-layer only — it does NOT load config; openWith binds the flag pair against cfg.Keyring.Backend at the single credstore.Open call site. Exported because cobra does NOT chain PersistentPreRunE, so a subcommand that defines its own must call it explicitly. Reads via cmd.Flag() so persistent-flag inheritance works from any subcommand path.

func WireCredentialRefSelection

func WireCredentialRefSelection(cmd *cobra.Command) error

WireCredentialRefSelection records the user-supplied --ref flag for the next keychain.Open* call and validates its <service>/<profile> shape up front so a bad value fails with a clear "--ref" error before any keyring work. The resolved precedence (--ref flag > <SERVICE>_CREDENTIAL_REF env > config credential_ref) is applied at keychain.open; this hook only records the flag.

Types

This section is empty.

Jump to

Keyboard shortcuts

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