Documentation
¶
Overview ¶
Package common provides shared utilities for CLI commands.
Index ¶
- func AddTargetFlags(cmd *cobra.Command)
- func CreateClientFactory() *dockercli.DefaultClientFactory
- func CreatePlannerWithFactory(factory *dockercli.DefaultClientFactory, pr ui.Printer) *planner.Planner
- func DisplayDaemonInfo(pr ui.Printer, cfg *manifest.Config)
- func DynamicSpinnerOperation(pr ui.StdPrinter, message string, operation func(*ui.Spinner) error) error
- func EnsureContextsReachable(ctx context.Context, cfg *manifest.Config, factory dockercli.ClientFactory) error
- func GetConfirmation(cmd *cobra.Command, pr ui.Printer, opts ConfirmationOptions) (bool, error)
- func GetDestroyConfirmation(cmd *cobra.Command, pr ui.Printer, opts DestroyConfirmationOptions) (bool, error)
- func GetFirstDaemon(cfg *manifest.Config) (string, manifest.ContextConfig)
- func GetFirstIdentifier(cfg *manifest.Config) string
- func LoadConfigWithWarnings(cmd *cobra.Command, pr ui.Printer) (*manifest.Config, error)
- func MaskSecretsSimple(yamlStr string, stack manifest.Stack, strategy string) string
- func ResolveManifestPath(cmd *cobra.Command, pr ui.Printer, root string, maxDepth int) (string, error)
- func ResolveTargets(cfg *manifest.Config, opts TargetOptions) (*manifest.Config, error)
- func RunWithRollingOrDirect(cmd *cobra.Command, verbose bool, ...) (string, bool, error)
- func SelectManifestPath(cmd *cobra.Command, pr ui.Printer, root string, maxDepth int) (string, bool, error)
- func SpinnerOperation(pr ui.StdPrinter, message string, operation func() error) error
- func ValidateWithFactory(ctx context.Context, cfg *manifest.Config, ...) error
- type CLIContext
- func (ctx *CLIContext) ApplyPlan() error
- func (ctx *CLIContext) ApplyPlanWithContext(plan *planner.Plan) error
- func (ctx *CLIContext) BuildDestroyPlan() (*planner.Plan, error)
- func (ctx *CLIContext) BuildPlan() (*planner.Plan, error)
- func (ctx *CLIContext) ExecuteDestroy(bgCtx context.Context) error
- func (ctx *CLIContext) ExecuteDestroyWithOptions(bgCtx context.Context, opts planner.CleanupOptions) error
- func (ctx *CLIContext) GetDefaultClient() *dockercli.Client
- func (ctx *CLIContext) PrunePlan() error
- func (ctx *CLIContext) PrunePlanWithContext(plan *planner.Plan) error
- func (ctx *CLIContext) PrunePlanWithOptions(plan *planner.Plan, opts planner.CleanupOptions) error
- func (c *CLIContext) WithRunContext(runCtx context.Context, fn func() error) error
- type ConfirmationOptions
- type DestroyConfirmationOptions
- type TargetOptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddTargetFlags ¶ added in v0.9.0
AddTargetFlags adds deployment targeting flags to a command.
func CreateClientFactory ¶ added in v0.9.0
func CreateClientFactory() *dockercli.DefaultClientFactory
CreateClientFactory creates a Docker client factory for multi-context support.
func CreatePlannerWithFactory ¶ added in v0.9.0
func CreatePlannerWithFactory(factory *dockercli.DefaultClientFactory, pr ui.Printer) *planner.Planner
CreatePlannerWithFactory creates a planner with client factory and printer configured.
func DisplayDaemonInfo ¶ added in v0.9.0
DisplayDaemonInfo shows the context configuration information.
func DynamicSpinnerOperation ¶ added in v0.7.0
func DynamicSpinnerOperation(pr ui.StdPrinter, message string, operation func(*ui.Spinner) error) error
DynamicSpinnerOperation runs an operation with a spinner that can be updated.
func EnsureContextsReachable ¶ added in v0.9.1
func EnsureContextsReachable(ctx context.Context, cfg *manifest.Config, factory dockercli.ClientFactory) error
EnsureContextsReachable probes every context in cfg in parallel and returns an aggregated Unavailable error (exit 69) if any daemon is unreachable. cfg is expected to already be narrowed to the selected contexts by ResolveTargets.
func GetConfirmation ¶
GetConfirmation handles user confirmation with TTY detection and appropriate prompting.
func GetDestroyConfirmation ¶
func GetDestroyConfirmation(cmd *cobra.Command, pr ui.Printer, opts DestroyConfirmationOptions) (bool, error)
GetDestroyConfirmation handles user confirmation for destroy operations, requiring the user to type the identifier name.
func GetFirstDaemon ¶ added in v0.9.0
func GetFirstDaemon(cfg *manifest.Config) (string, manifest.ContextConfig)
GetFirstDaemon returns the name and config of the first context, ordered by context name so the choice is deterministic (Go map iteration is randomized).
func GetFirstIdentifier ¶ added in v0.9.0
GetFirstIdentifier returns the project identifier (for destroy confirmation).
func LoadConfigWithWarnings ¶
LoadConfigWithWarnings loads the configuration from the --manifest flag and displays warnings.
func MaskSecretsSimple ¶
MaskSecretsSimple redacts secret-like values from a YAML string based on stack config. This is a pragmatic heuristic: it masks occurrences of values provided via stack/environment inline env and sops secrets (after decryption via BuildInlineEnv), as well as common sensitive keys.
func ResolveManifestPath ¶ added in v0.9.0
func ResolveManifestPath(cmd *cobra.Command, pr ui.Printer, root string, maxDepth int) (string, error)
ResolveManifestPath determines the manifest path to load. If --manifest is set, it is returned as-is. If omitted and a manifest exists in CWD defaults, returns empty string (loader defaults apply). If omitted and no CWD manifest exists, it attempts discovery and interactive selection.
func ResolveTargets ¶ added in v0.9.0
ResolveTargets filters a config to only include the targeted contexts and stacks. If no targeting options are set, the config is returned unchanged. The returned config is a shallow copy with filtered Contexts, Stacks, and DiscoveredStacks/Filesets.
func RunWithRollingOrDirect ¶
func RunWithRollingOrDirect(cmd *cobra.Command, verbose bool, fn func(runCtx context.Context) (string, error)) (string, bool, error)
RunWithRollingOrDirect executes fn while showing rolling logs when stdout is a TTY and verbose is false. Returns the fn's string result and whether the rolling TUI was used.
func SelectManifestPath ¶
func SelectManifestPath(cmd *cobra.Command, pr ui.Printer, root string, maxDepth int) (string, bool, error)
SelectManifestPath scans for manifest files up to maxDepth and presents an interactive picker when attached to a TTY. Returns the chosen manifest path and whether a selection was made.
func SpinnerOperation ¶
func SpinnerOperation(pr ui.StdPrinter, message string, operation func() error) error
SpinnerOperation runs an operation with a spinner, automatically handling start/stop.
func ValidateWithFactory ¶ added in v0.9.0
func ValidateWithFactory(ctx context.Context, cfg *manifest.Config, factory *dockercli.DefaultClientFactory) error
ValidateWithFactory runs validation against the configuration using a client factory.
Types ¶
type CLIContext ¶
type CLIContext struct {
Ctx context.Context
Config *manifest.Config
Factory *dockercli.DefaultClientFactory
Printer ui.Printer
Planner *planner.Planner
}
CLIContext contains all the components needed for most CLI operations.
func SetupCLIContext ¶
func SetupCLIContext(cmd *cobra.Command) (*CLIContext, error)
SetupCLIContext performs the standard CLI setup: load config, create client factory, validate, and create planner.
func (*CLIContext) ApplyPlan ¶
func (ctx *CLIContext) ApplyPlan() error
ApplyPlan executes the plan with dynamic spinner.
func (*CLIContext) ApplyPlanWithContext ¶ added in v0.7.0
func (ctx *CLIContext) ApplyPlanWithContext(plan *planner.Plan) error
ApplyPlanWithContext executes the plan with progress tracking, reusing a pre-built plan. This avoids redundant state detection by passing the execution context from the plan.
func (*CLIContext) BuildDestroyPlan ¶
func (ctx *CLIContext) BuildDestroyPlan() (*planner.Plan, error)
BuildDestroyPlan creates a destruction plan for all managed resources.
func (*CLIContext) BuildPlan ¶
func (ctx *CLIContext) BuildPlan() (*planner.Plan, error)
BuildPlan creates a plan using the CLI context with spinner UI.
func (*CLIContext) ExecuteDestroy ¶
func (ctx *CLIContext) ExecuteDestroy(bgCtx context.Context) error
ExecuteDestroy executes the destruction of all managed resources.
func (*CLIContext) ExecuteDestroyWithOptions ¶ added in v0.9.0
func (ctx *CLIContext) ExecuteDestroyWithOptions(bgCtx context.Context, opts planner.CleanupOptions) error
ExecuteDestroyWithOptions executes destruction with explicit cleanup options.
func (*CLIContext) GetDefaultClient ¶ added in v0.9.0
func (ctx *CLIContext) GetDefaultClient() *dockercli.Client
GetDefaultClient returns a Docker client for the first context (for single-context operations).
func (*CLIContext) PrunePlan ¶
func (ctx *CLIContext) PrunePlan() error
PrunePlan executes pruning with spinner.
func (*CLIContext) PrunePlanWithContext ¶ added in v0.7.0
func (ctx *CLIContext) PrunePlanWithContext(plan *planner.Plan) error
PrunePlanWithContext executes pruning with spinner, reusing a pre-built plan.
func (*CLIContext) PrunePlanWithOptions ¶ added in v0.9.0
func (ctx *CLIContext) PrunePlanWithOptions(plan *planner.Plan, opts planner.CleanupOptions) error
PrunePlanWithOptions executes pruning with spinner, reusing a pre-built plan and explicit cleanup options.
func (*CLIContext) WithRunContext ¶ added in v0.9.0
func (c *CLIContext) WithRunContext(runCtx context.Context, fn func() error) error
WithRunContext temporarily swaps the context's Ctx to runCtx for the duration of fn, restoring the original afterwards.
type ConfirmationOptions ¶
ConfirmationOptions configures the confirmation prompt behavior.
type DestroyConfirmationOptions ¶
type DestroyConfirmationOptions struct {
SkipConfirmation bool
Identifier string
// Targeted indicates the destroy was scoped by --stack/--context/--deployment,
// so only the targeted resources (shown in the plan) will be removed.
Targeted bool
}
DestroyConfirmationOptions configures the destroy confirmation prompt behavior.
type TargetOptions ¶ added in v0.9.0
type TargetOptions struct {
Contexts []string // --context flag values
Stacks []string // --stack flag values (context/stack format)
Deployment string // --deployment flag value
}
TargetOptions represents CLI targeting flags for filtering contexts/stacks.
func ReadTargetOptions ¶ added in v0.9.0
func ReadTargetOptions(cmd *cobra.Command) TargetOptions
ReadTargetOptions reads targeting flags from a command.
func (TargetOptions) IsEmpty ¶ added in v0.9.0
func (t TargetOptions) IsEmpty() bool
IsEmpty returns true if no targeting flags were provided.