Help us shape the future of Go! Take the 2026 Go Developer Survey

cli

package
v1.10.0 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2026 License: MIT Imports: 30 Imported by: 0

Documentation

Overview

Package cli provides shared runners and command builders for stage commands.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatTagApplySummary

func FormatTagApplySummary(tag stagingusecase.ApplyTagResult) string

FormatTagApplySummary formats a tag apply result as a summary string.

func NewAddCommand

func NewAddCommand(cfg CommandConfig) *cli.Command

NewAddCommand creates an add command with the given config.

func NewApplyCommand

func NewApplyCommand(cfg CommandConfig) *cli.Command

NewApplyCommand creates an apply command with the given config.

func NewDeleteCommand

func NewDeleteCommand(cfg CommandConfig) *cli.Command

NewDeleteCommand creates a delete command with the given config.

func NewDiffCommand

func NewDiffCommand(cfg CommandConfig) *cli.Command

NewDiffCommand creates a diff command with the given config.

func NewEditCommand

func NewEditCommand(cfg CommandConfig) *cli.Command

NewEditCommand creates an edit command with the given config.

func NewExportCommand added in v1.7.0

func NewExportCommand(cfg CommandConfig) *cli.Command

NewExportCommand creates a service-specific `stage <svc> export <file>` command that writes the single service to <file>.

func NewGlobalApplyCommand added in v1.10.0

func NewGlobalApplyCommand(gcfg GlobalConfig) *cli.Command

NewGlobalApplyCommand creates the provider-wide `stage apply` command.

func NewGlobalDiffCommand added in v1.10.0

func NewGlobalDiffCommand(gcfg GlobalConfig) *cli.Command

NewGlobalDiffCommand creates the provider-wide `stage diff` command.

func NewGlobalExportCommand added in v1.7.0

func NewGlobalExportCommand(gcfg GlobalConfig) *cli.Command

NewGlobalExportCommand creates the global `stage export <dir>` command. It writes <dir>/param.json and <dir>/secret.json, one file per service that has staged changes (empty services are skipped). The resolver determines the provider staging scope; its CommandPath renders the help examples.

func NewGlobalImportCommand added in v1.7.0

func NewGlobalImportCommand(gcfg GlobalConfig) *cli.Command

NewGlobalImportCommand creates the global `stage import <dir>` command. It reads <dir>/param.json and <dir>/secret.json (missing files are skipped; an error only when neither exists) into the working staging area. The config's ScopeResolver determines the provider staging scope; its per-service factories re-anchor conflict-detection timestamps on a cross-scope import.

func NewGlobalResetCommand added in v1.10.0

func NewGlobalResetCommand(gcfg GlobalConfig) *cli.Command

NewGlobalResetCommand creates the provider-wide `stage reset` command.

func NewGlobalStatusCommand added in v1.10.0

func NewGlobalStatusCommand(gcfg GlobalConfig) *cli.Command

NewGlobalStatusCommand creates the provider-wide `stage status` command.

func NewImportCommand added in v1.7.0

func NewImportCommand(cfg CommandConfig) *cli.Command

NewImportCommand creates a service-specific `stage <svc> import <file>` command that reads the single service from <file>. A service mismatch (the file holds another service) is a hard error.

func NewResetCommand

func NewResetCommand(cfg CommandConfig) *cli.Command

NewResetCommand creates a reset command with the given config.

func NewStatusCommand

func NewStatusCommand(cfg CommandConfig) *cli.Command

NewStatusCommand creates a status command with the given config.

func NewTagCommand

func NewTagCommand(cfg CommandConfig) *cli.Command

NewTagCommand creates a tag command with the given config.

func NewUntagCommand

func NewUntagCommand(cfg CommandConfig) *cli.Command

NewUntagCommand creates an untag command with the given config.

func SharedScopeResolver added in v1.10.0

func SharedScopeResolver(resolver staging.ScopeResolver) staging.ScopeResolver

SharedScopeResolver wraps a resolver that several services of one provider share (AWS Parameter Store and Secrets Manager resolve one account scope from the STS caller identity). Within one all-service command it runs once, and the other services reuse its result (or error). Outside those commands it just calls resolver.

Types

type AddOptions

type AddOptions struct {
	Name string
	// Value is the explicit value; it is used only when HasValue is set.
	Value string
	// HasValue reports that a value argument was given, even an empty one.
	HasValue bool
	// ValueFromStdin reads the value from Stdin (--value-stdin).
	ValueFromStdin bool
	Description    string
	// Namespace is the App Configuration namespace to stage under (empty for the
	// null/default namespace and every other provider).
	Namespace string
	// ValueType is the provider-neutral value type to record on the staged entry
	// (AWS Parameter Store axis). Empty for providers without a type axis.
	ValueType domain.ValueType
}

AddOptions holds options for the add command.

type AddRunner

type AddRunner struct {
	UseCase *stagingusecase.AddUseCase
	Stdout  io.Writer
	Stderr  io.Writer
	// Stdin is read for --value-stdin and decides whether the $EDITOR fallback
	// may run (only on a terminal). Nil is treated as a non-interactive stdin.
	Stdin      io.Reader
	OpenEditor editor.OpenFunc // Optional: defaults to editor.Open (TTY only) if nil
}

AddRunner executes add operations using a usecase.

func (*AddRunner) Run

func (r *AddRunner) Run(ctx context.Context, opts AddOptions) error

Run executes the add command.

type ApplyOptions

type ApplyOptions struct {
	Name            string // Optional: apply only this item, otherwise apply all
	IgnoreConflicts bool   // Skip conflict detection and force apply
}

ApplyOptions holds options for the apply command.

type ApplyRunner

type ApplyRunner struct {
	UseCase *stagingusecase.ApplyUseCase
	Store   store.ReadWriteOperator
	Parser  staging.Parser
	// ProviderLabel names the remote store in prompts and conflict warnings
	// (e.g. "AWS"); empty renders as "remote".
	ProviderLabel string
	Confirmer     applyConfirmer
	SkipConfirm   bool
	Stdout        io.Writer
	Stderr        io.Writer
}

ApplyRunner applies staged changes via the ApplyUseCase and reports the results. RunInteractive wraps Run with the presentation-layer orchestration (empty-check, name validation, and interactive confirmation) that the `stage <service> apply` command performs before applying.

func (*ApplyRunner) Run

func (r *ApplyRunner) Run(ctx context.Context, opts ApplyOptions) error

Run applies the staged changes via the usecase and reports the results.

func (*ApplyRunner) RunInteractive added in v0.8.0

func (r *ApplyRunner) RunInteractive(ctx context.Context, opts ApplyOptions) error

RunInteractive performs the command-level apply flow: it lists staged entries, short-circuits when nothing is staged, validates an optional target name, asks for confirmation, and then delegates to Run. Interactive confirmation lives here (presentation layer) rather than in the usecase.

type CommandConfig

type CommandConfig struct {
	// CommandName is the subcommand name (e.g., "param", "secret").
	CommandName string

	// ItemName is the item name for messages (e.g., "parameter", "secret").
	ItemName string

	// ProviderLabel is the human-readable provider name used in help text,
	// prompts, and messages (e.g., "AWS", "Google Cloud", "Azure").
	ProviderLabel string

	// CommandPath is the explicit command path of this service's stage group,
	// used in help examples and usage errors (e.g., "suve aws stage param",
	// "suve gcloud stage", "suve azure stage secret").
	CommandPath string

	// Factory creates a FullStrategy backed by a provider.Store.
	Factory staging.StrategyFactory

	// ParserFactory creates a Parser without provider access (for status, parsing).
	ParserFactory staging.ParserFactory

	// ScopeResolver resolves the provider staging scope used to key on-disk
	// state. Required: a nil resolver makes every staging command fail.
	ScopeResolver staging.ScopeResolver

	// HasDescription reports whether this service's writer honors a free-text
	// description (AWS param/secret and Google Cloud secret). When true, `stage
	// add`/`stage edit` register a --description flag; when false the flag is not
	// registered at all, so a description on an unsupported provider (Azure Key
	// Vault / App Configuration) is rejected as an unknown flag rather than being
	// accepted and then silently dropped on apply.
	HasDescription bool

	// Namespace resolves the App Configuration namespace a single-item staging
	// op targets, from the command context (the --namespace flag). It records
	// the namespace on the staged entry as part of its identity. Nil for
	// providers without a namespace axis (the namespace is then always empty).
	Namespace func(ctx context.Context) string

	// StrategyForNamespace builds a strategy backed by a provider store scoped to
	// the given namespace, so status/diff/apply act on each staged entry under
	// its own namespace (App Configuration keeps all namespaces in one staging
	// store). Nil for providers without a namespace axis.
	StrategyForNamespace func(ctx context.Context, namespace string) (staging.FullStrategy, error)

	// ValueTypeFlags are provider-specific flags appended to the add and edit
	// commands so the staged entry can carry a value type (the AWS Parameter
	// Store --type/--secure axis). Nil for providers without a value-type axis.
	ValueTypeFlags []cli.Flag

	// ValueTypeFromCmd validates and resolves the staged value type from the
	// add/edit command flags (ValueTypeFlags). Nil for providers without a
	// value-type axis, in which case the staged value type is left unset. An
	// empty return means "not specified": create applies plaintext and update
	// preserves the existing type.
	ValueTypeFromCmd func(cmd *cli.Command) (domain.ValueType, error)
}

CommandConfig holds service-specific configuration for building stage commands.

type DeleteOptions

type DeleteOptions struct {
	Name           string
	Force          bool // For Secrets Manager: force immediate deletion
	RecoveryWindow int  // For Secrets Manager: days before permanent deletion (7-30)
	// Namespace is the App Configuration namespace of the setting (empty for the
	// null/default namespace and every other provider).
	Namespace string
}

DeleteOptions holds options for the delete command.

type DeleteRunner

type DeleteRunner struct {
	UseCase *stagingusecase.DeleteUseCase
	Stdout  io.Writer
	Stderr  io.Writer
}

DeleteRunner executes delete operations using a usecase.

func (*DeleteRunner) Run

func (r *DeleteRunner) Run(ctx context.Context, opts DeleteOptions) error

Run executes the delete command.

type DiffOptions

type DiffOptions struct {
	Name      string // Optional: diff only this item, otherwise diff all
	ParseJSON bool
	NoPager   bool
}

DiffOptions holds options for the diff command.

type DiffRunner

type DiffRunner struct {
	UseCase *stagingusecase.DiffUseCase
	Stdout  io.Writer
	Stderr  io.Writer
	// RemoteLabel names the remote in diff labels and warnings. Empty uses the
	// strategy's ServiceName (e.g. "App Configuration", "Key Vault").
	RemoteLabel string
	// contains filtered or unexported fields
}

DiffRunner executes diff operations using a usecase.

func (*DiffRunner) OutputDiff

func (r *DiffRunner) OutputDiff(opts DiffOptions, entry stagingusecase.DiffEntry)

OutputDiff outputs a diff entry for an existing resource.

func (*DiffRunner) OutputDiffCreate

func (r *DiffRunner) OutputDiffCreate(opts DiffOptions, entry stagingusecase.DiffEntry)

OutputDiffCreate outputs a diff entry for a newly created resource.

func (*DiffRunner) OutputMetadata

func (r *DiffRunner) OutputMetadata(entry stagingusecase.DiffEntry)

OutputMetadata outputs metadata for a diff entry.

func (*DiffRunner) OutputTagEntry

func (r *DiffRunner) OutputTagEntry(tagEntry stagingusecase.DiffTagEntry)

OutputTagEntry outputs a tag entry.

func (*DiffRunner) Run

func (r *DiffRunner) Run(ctx context.Context, opts DiffOptions) error

Run executes the diff command.

type EditOptions

type EditOptions struct {
	Name string
	// Value is the explicit value; it is used only when HasValue is set.
	Value string
	// HasValue reports that a value argument was given, even an empty one.
	HasValue bool
	// ValueFromStdin reads the value from Stdin (--value-stdin).
	ValueFromStdin bool
	Description    string
	// Namespace is the App Configuration namespace of the setting (empty for the
	// null/default namespace and every other provider).
	Namespace string
	// ValueType is the provider-neutral value type to record on the staged entry
	// (AWS Parameter Store axis). Empty preserves the existing type.
	ValueType domain.ValueType
}

EditOptions holds options for the edit command.

type EditRunner

type EditRunner struct {
	UseCase *stagingusecase.EditUseCase
	// ProviderLabel names the remote store in messages (e.g. "AWS"); empty
	// renders as "remote".
	ProviderLabel string
	Stdout        io.Writer
	Stderr        io.Writer
	// Stdin is read for --value-stdin and decides whether the $EDITOR fallback
	// may run (only on a terminal). Nil is treated as a non-interactive stdin.
	Stdin      io.Reader
	OpenEditor editor.OpenFunc // Optional: defaults to editor.Open (TTY only) if nil
}

EditRunner executes edit operations using a usecase.

func (*EditRunner) Run

func (r *EditRunner) Run(ctx context.Context, opts EditOptions) error

Run executes the edit command.

type GlobalApplyRunner added in v1.10.0

type GlobalApplyRunner struct {
	UseCase *stagingusecase.GlobalApplyUseCase
	// ProviderLabel is the human-readable provider name (e.g. "AWS").
	ProviderLabel   string
	Stdout          io.Writer
	Stderr          io.Writer
	IgnoreConflicts bool
}

GlobalApplyRunner applies the staged changes of every service of one provider through the GlobalApplyUseCase and reports the results, each line prefixed with its service name.

func (*GlobalApplyRunner) Run added in v1.10.0

func (r *GlobalApplyRunner) Run(ctx context.Context) error

Run applies every service's staged changes and reports the results: value changes service by service, then tag changes service by service, each in the usecase's (name, namespace) order.

type GlobalConfig added in v0.8.1

type GlobalConfig struct {
	// ProviderLabel is the human-readable provider name used in prompts and
	// messages (e.g. "AWS", "Azure").
	ProviderLabel string
	// CommandPath is the explicit command path of the provider's stage group,
	// used in help text and usage errors (e.g. "suve aws stage").
	CommandPath string
	// ScopeResolver resolves the one provider staging scope that the all-service
	// export/import (NewGlobalExportCommand / NewGlobalImportCommand) read and
	// write. Required when those commands are wired; status / diff / apply /
	// reset use each service's own ScopeResolver instead.
	ScopeResolver staging.ScopeResolver
	// Services lists the provider's services in stable display order.
	Services []GlobalServiceSpec
}

GlobalConfig configures the provider-wide stage commands so a single set of implementations serves every multi-service provider: AWS and Azure each iterate param + secret, each service through its own ScopeResolver.

type GlobalDiffOptions added in v1.10.0

type GlobalDiffOptions struct {
	ParseJSON bool
	NoPager   bool
}

GlobalDiffOptions holds options for the all-service diff command.

type GlobalDiffRunner added in v1.10.0

type GlobalDiffRunner struct {
	// Services lists one per-service diff use case per service with staged
	// changes, in stable display order.
	Services []*stagingusecase.DiffUseCase
	// ProviderLabel is the human-readable provider name (e.g. "AWS") that
	// labels the remote side of every diff and warning.
	ProviderLabel string
	Stdout        io.Writer
	Stderr        io.Writer
}

GlobalDiffRunner diffs the staged changes of every service of one provider: all services' value entries first, then all services' tag changes.

func (*GlobalDiffRunner) Run added in v1.10.0

Run executes the all-service diff: each service is diffed through its own DiffUseCase (which auto-unstages no-op and vanished entries), then rendered by the per-service DiffRunner with the provider as the remote label.

type GlobalResetRunner added in v1.10.0

type GlobalResetRunner struct {
	// Services lists the provider services in stable display order.
	Services []GlobalServiceSpec
	// Store, when set, is used for every service (a test seam). When nil each
	// service resolves its own working store via its spec's ScopeResolver.
	Store  store.ReadWriteOperator
	Stdout io.Writer
	Stderr io.Writer
}

GlobalResetRunner unstages every service of one provider.

func (*GlobalResetRunner) Run added in v1.10.0

func (r *GlobalResetRunner) Run(ctx context.Context) error

Run executes the all-service reset command. Each configured service is reset in its OWN store through the per-service ResetUseCase; a service whose scope is not configured is skipped (it can hold no staged state).

type GlobalServiceSpec added in v0.8.1

type GlobalServiceSpec struct {
	// Service is the staging service (param or secret).
	Service staging.Service
	// ParserFactory builds a network-free parser for this service.
	ParserFactory staging.ParserFactory
	// Factory builds a provider-backed strategy for this service.
	Factory staging.StrategyFactory
	// ScopeResolver resolves THIS service's staging scope. It is per-service
	// because a provider's services may live in independent resources with
	// separate staging buckets: Azure App Configuration (param) is keyed by
	// store name, Key Vault (secret) by vault name. AWS keeps one account scope
	// for both; wrap such a shared resolver in SharedScopeResolver so the
	// all-service commands resolve it once. Required.
	ScopeResolver staging.ScopeResolver
	// StrategyForNamespace, when set, builds a strategy scoped to a given
	// namespace so apply/diff act on each staged entry under its own namespace
	// (Azure App Configuration keeps all namespaces in one staging store). Nil
	// for services without a namespace axis — the single Factory strategy is used.
	StrategyForNamespace func(ctx context.Context, namespace string) (staging.FullStrategy, error)
}

GlobalServiceSpec describes one service for the provider-wide (all-service) stage commands (status / diff / apply / reset in global_*.go). ParserFactory yields a network-free Parser (service name, delete-option support); Factory builds a FullStrategy backed by a provider.Store for apply/diff.

type GlobalStatusOptions added in v1.10.0

type GlobalStatusOptions struct {
	Verbose bool
}

GlobalStatusOptions holds options for the all-service status command.

type GlobalStatusRunner added in v1.10.0

type GlobalStatusRunner struct {
	// Services lists the provider services in stable display order.
	Services []GlobalServiceSpec
	// Store, when set, is used for every service (a test seam). When nil each
	// service resolves its own working store via its spec's ScopeResolver — Azure
	// App Configuration and Key Vault live in separate staging buckets.
	Store  store.ReadWriteOperator
	Stdout io.Writer
	Stderr io.Writer
}

GlobalStatusRunner shows the staged changes of every service of one provider, one "Staged <service> changes" block per service that has any.

func (*GlobalStatusRunner) Run added in v1.10.0

Run executes the all-service status command. Each service reads its OWN store through the per-service StatusUseCase; a service whose scope is not configured is skipped (it can hold no staged state).

type ImportModeChooser added in v1.7.0

type ImportModeChooser struct {
	Prompter *confirm.Prompter
	Stderr   io.Writer
	Stdout   io.Writer
}

ImportModeChooser resolves the reconciliation mode for the working staging area, mirroring the former stash-pop chooser: an explicit flag wins; otherwise a Merge/Overwrite/Cancel prompt appears only when the working area already holds changes and a TTY is available; the default is Merge.

func (*ImportModeChooser) ChooseMode added in v1.7.0

func (c *ImportModeChooser) ChooseMode(input ImportModeInput) (ImportModeResult, error)

ChooseMode determines the import mode, prompting interactively if needed.

type ImportModeInput added in v1.7.0

type ImportModeInput struct {
	MergeFlag     bool
	OverwriteFlag bool
	// SkipPrompt (--yes) accepts the default (Merge) without the interactive
	// Merge/Overwrite/Cancel prompt, for scripts/automation.
	SkipPrompt bool
	// PassphraseStdin (--passphrase-stdin) means stdin carries the passphrase, not
	// an interactive answer. Prompting would double-buffer/EOF against the
	// passphrase read (#472), so the mode is resolved from flags only (default
	// Merge) without prompting.
	PassphraseStdin bool
	HasChanges      bool
	ItemCount       int
	IsTTY           bool
}

ImportModeInput holds the inputs to import-mode selection.

type ImportModeResult added in v1.7.0

type ImportModeResult struct {
	Mode      usestaging.ImportMode
	Cancelled bool
}

ImportModeResult holds the outcome of import-mode selection.

type ResetOptions

type ResetOptions struct {
	Spec string // Name with optional version spec
	All  bool   // Reset all staged items for this service
	// Namespace is the App Configuration namespace of the entry to reset (empty
	// for the null/default namespace and every other provider; ignored with All).
	Namespace string
}

ResetOptions holds options for the reset command.

type ResetRunner

type ResetRunner struct {
	UseCase *stagingusecase.ResetUseCase
	Stdout  io.Writer
	Stderr  io.Writer
}

ResetRunner executes reset operations using a usecase.

func (*ResetRunner) Run

func (r *ResetRunner) Run(ctx context.Context, opts ResetOptions) error

Run executes the reset command.

type StatusOptions

type StatusOptions struct {
	Name    string
	Verbose bool
}

StatusOptions holds options for the status command.

type StatusRunner

type StatusRunner struct {
	UseCase *stagingusecase.StatusUseCase
	Stdout  io.Writer
	Stderr  io.Writer
}

StatusRunner executes status operations using a usecase.

func (*StatusRunner) Run

func (r *StatusRunner) Run(ctx context.Context, opts StatusOptions) error

Run executes the status command.

type TagOptions

type TagOptions struct {
	Name string
	// Namespace is the App Configuration namespace of the resource (empty for the
	// null/default namespace and every other provider).
	Namespace string
	Tags      []string // key=value pairs to add
}

TagOptions holds options for the tag command.

type TagRunner

type TagRunner struct {
	UseCase *stagingusecase.TagUseCase
	Stdout  io.Writer
	Stderr  io.Writer
}

TagRunner executes tag staging operations using a usecase.

func (*TagRunner) Run

func (r *TagRunner) Run(ctx context.Context, opts TagOptions) error

Run executes the tag command.

type UntagOptions

type UntagOptions struct {
	Name string
	// Namespace is the App Configuration namespace of the resource (empty for the
	// null/default namespace and every other provider).
	Namespace string
	Keys      []string // tag keys to remove
}

UntagOptions holds options for the untag command.

type UntagRunner

type UntagRunner struct {
	UseCase *stagingusecase.TagUseCase
	Stdout  io.Writer
	Stderr  io.Writer
}

UntagRunner executes untag staging operations using a usecase.

func (*UntagRunner) Run

func (r *UntagRunner) Run(ctx context.Context, opts UntagOptions) error

Run executes the untag command.

Jump to

Keyboard shortcuts

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