compat

package
v1.202.1 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2025 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetSeparated added in v1.202.0

func GetSeparated() []string

GetSeparated returns the separated args (terraform pass-through flags like -out, -var). Returns nil if no separated args were set during preprocessing.

Usage in RunE.

separatedArgs := compat.GetSeparated()

func ResetSeparated added in v1.202.0

func ResetSeparated()

ResetSeparated clears the separated args. Used for testing.

func SetSeparated added in v1.202.0

func SetSeparated(separatedArgs []string)

SetSeparated stores the separated args (pass-through flags for terraform, etc.). Called once during preprocessing in Execute() before Cobra parses.

Separated args are flags that should be passed through to the underlying command, (e.g., terraform -out=/tmp/plan, -var=foo=bar) rather than being parsed by Atmos. These are identified by the CompatibilityFlagTranslator during preprocessing.

Types

type CompatibilityBehavior

type CompatibilityBehavior int

CompatibilityBehavior defines how a compatibility flag should be handled.

const (
	// MapToAtmosFlag converts the legacy flag to a modern Atmos flag.
	// Example: -s → --stack, -var → --var.
	MapToAtmosFlag CompatibilityBehavior = iota

	// AppendToSeparated appends the flag and its value to separated args.
	// Example: -var-file → append to separated args for pass-through to terraform.
	AppendToSeparated
)

type CompatibilityFlag

type CompatibilityFlag struct {
	Behavior    CompatibilityBehavior
	Target      string // Target flag name (for MapToAtmosFlag) or empty (for AppendToSeparated).
	Description string // Human-readable description for help output.
}

CompatibilityFlag defines how a single compatibility flag should be handled.

type CompatibilityFlagTranslator

type CompatibilityFlagTranslator struct {
	// contains filtered or unexported fields
}

CompatibilityFlagTranslator translates legacy flag syntax to modern Cobra-compatible format. It separates args into two categories:

  • atmosArgs: Args that should be parsed by Cobra (Atmos flags)
  • separatedArgs: Args that should be passed through to subprocess (terraform, etc.)

func NewCompatibilityFlagTranslator

func NewCompatibilityFlagTranslator(flagMap map[string]CompatibilityFlag) *CompatibilityFlagTranslator

NewCompatibilityFlagTranslator creates a new translator with the given flag map.

func (*CompatibilityFlagTranslator) Translate

func (t *CompatibilityFlagTranslator) Translate(args []string) (atmosArgs []string, separatedArgs []string)

Translate processes args and separates them into Atmos args and separated args. Returns:

  • atmosArgs: Arguments for Cobra to parse (Atmos flags + positional args)
  • separatedArgs: Arguments to pass through to subprocess

func (*CompatibilityFlagTranslator) ValidateNoConflicts

func (t *CompatibilityFlagTranslator) ValidateNoConflicts(cmd *cobra.Command) error

ValidateNoConflicts validates that compatibility flags don't conflict with Cobra native shorthands. This detects configuration errors where someone adds -s or -i to compatibility flags when they're already registered as Cobra shorthands via StringP("stack", "s", ...). This should be called after flags are registered.

func (*CompatibilityFlagTranslator) ValidateTargets

func (t *CompatibilityFlagTranslator) ValidateTargets(cmd *cobra.Command) error

ValidateTargets validates that all compatibility flags with MapToAtmosFlag behavior reference flags that are actually registered on the command. This should be called after flags are registered but before parsing.

func (*CompatibilityFlagTranslator) ValidateTargetsInArgs

func (t *CompatibilityFlagTranslator) ValidateTargetsInArgs(cmd *cobra.Command, args []string) error

ValidateTargetsInArgs validates that compatibility flags used in the given args reference flags that are actually registered on the command. This only validates compatibility flags that appear in the args, not all registered flags.

Jump to

Keyboard shortcuts

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