common

package
v0.8.0-rc.1 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package common provides shared utilities for CLI commands.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddTargetFlags

func AddTargetFlags(cmd *cobra.Command)

AddTargetFlags adds deployment targeting flags to a command.

func CreateClientFactory

func CreateClientFactory() *dockercli.DefaultClientFactory

CreateClientFactory creates a Docker client factory for multi-context support.

func CreatePlannerWithFactory

func CreatePlannerWithFactory(factory *dockercli.DefaultClientFactory, pr ui.Printer) *planner.Planner

CreatePlannerWithFactory creates a planner with client factory and printer configured.

func DisplayDaemonInfo

func DisplayDaemonInfo(pr ui.Printer, cfg *manifest.Config)

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 GetConfirmation

func GetConfirmation(cmd *cobra.Command, pr ui.Printer, opts ConfirmationOptions) (bool, error)

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

func GetFirstDaemon(cfg *manifest.Config) (string, manifest.ContextConfig)

GetFirstDaemon returns the name and config of the first context.

func GetFirstIdentifier

func GetFirstIdentifier(cfg *manifest.Config) string

GetFirstIdentifier returns the project identifier (for destroy confirmation).

func LoadConfigWithWarnings

func LoadConfigWithWarnings(cmd *cobra.Command, pr ui.Printer) (*manifest.Config, error)

LoadConfigWithWarnings loads the configuration from the --manifest flag and displays warnings.

func MaskSecretsSimple

func MaskSecretsSimple(yamlStr string, stack manifest.Stack, strategy string) string

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

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

func ResolveTargets(cfg *manifest.Config, opts TargetOptions) (*manifest.Config, error)

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

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

func (ctx *CLIContext) ExecuteDestroyWithOptions(bgCtx context.Context, opts planner.CleanupOptions) error

ExecuteDestroyWithOptions executes destruction with explicit cleanup options.

func (*CLIContext) GetDefaultClient

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

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

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

type ConfirmationOptions struct {
	SkipConfirmation bool
	Message          string
}

ConfirmationOptions configures the confirmation prompt behavior.

type DestroyConfirmationOptions

type DestroyConfirmationOptions struct {
	SkipConfirmation bool
	Identifier       string
}

DestroyConfirmationOptions configures the destroy confirmation prompt behavior.

type TargetOptions

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

func ReadTargetOptions(cmd *cobra.Command) TargetOptions

ReadTargetOptions reads targeting flags from a command.

func (TargetOptions) IsEmpty

func (t TargetOptions) IsEmpty() bool

IsEmpty returns true if no targeting flags were provided.

Jump to

Keyboard shortcuts

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