Documentation
¶
Overview ¶
Package iacargs provides types and utilities for handling IaC (terraform/tofu) CLI arguments.
Index ¶
- Constants
- func IsKnownSubCommand(arg string) bool
- type IacArgs
- func (a *IacArgs) AddFlagIfNotPresent(flag string) *IacArgs
- func (a *IacArgs) AppendArgument(args ...string) *IacArgs
- func (a *IacArgs) AppendFlag(flags ...string) *IacArgs
- func (a *IacArgs) AppendSubCommand(subs ...string) *IacArgs
- func (a *IacArgs) Clone() *IacArgs
- func (a *IacArgs) Contains(target string) bool
- func (a *IacArgs) First() string
- func (a *IacArgs) HasFlag(name string) bool
- func (a *IacArgs) HasPlanFile() bool
- func (a *IacArgs) InsertArgument(pos int, arg string) *IacArgs
- func (a *IacArgs) InsertArguments(pos int, args ...string) *IacArgs
- func (a *IacArgs) InsertFlag(pos int, flags ...string) *IacArgs
- func (a *IacArgs) IsDestroyCommand(cmd string) bool
- func (a *IacArgs) Last() string
- func (a *IacArgs) MergeFlags(other *IacArgs) *IacArgs
- func (a *IacArgs) Normalize(acts ...NormalizeActsType) *IacArgs
- func (a *IacArgs) RemoveFlag(name string) *IacArgs
- func (a *IacArgs) Second() string
- func (a *IacArgs) SetCommand(cmd string) *IacArgs
- func (a *IacArgs) Slice() []string
- func (a *IacArgs) Tail() []string
- type NormalizeActsType
Constants ¶
const (
// CommandNameDestroy is the terraform destroy command name
CommandNameDestroy = "destroy"
)
Variables ¶
This section is empty.
Functions ¶
func IsKnownSubCommand ¶
IsKnownSubCommand returns true if arg is a known terraform subcommand.
Types ¶
type IacArgs ¶
type IacArgs struct {
Command string // e.g., "apply", "plan", "providers"
SubCommand []string // e.g., "lock" in "providers lock -platform=..."
Flags []string // e.g., "-input=false", "-auto-approve"
Arguments []string // e.g., plan files, resource addresses
}
IacArgs represents parsed IaC (terraform/tofu) CLI arguments with separate command, flags, and arguments fields. Provides a builder pattern for constructing CLI arguments.
Structure: [Command] [SubCommand...] [Flags...] [Arguments...] - Command: main terraform command (e.g., "apply", "providers") - SubCommand: non-flag args before any flags (e.g., "lock" in "providers lock") - Flags: all flags with their values - Arguments: non-flag args after flags (e.g., plan files)
func (*IacArgs) AddFlagIfNotPresent ¶
AddFlagIfNotPresent adds a flag only if not already present.
func (*IacArgs) AppendArgument ¶
AppendArgument adds argument(s) and returns self for chaining.
func (*IacArgs) AppendFlag ¶
AppendFlag adds flag(s) and returns self for chaining.
func (*IacArgs) AppendSubCommand ¶
AppendSubCommand adds subcommand(s) and returns self for chaining.
func (*IacArgs) Clone ¶
Clone returns a deep copy of IacArgs. Note: This performs a deep copy of slices (Command, SubCommand, Flags, Arguments). If IacArgs is extended with pointer fields or nested structs in the future, this method must be updated to ensure deep copying of those fields as well.
func (*IacArgs) Contains ¶
Contains checks if the args contain the target (in command, subcommand, flags, or arguments).
func (*IacArgs) HasFlag ¶
HasFlag checks if flag exists (handles -flag, --flag and -flag=value formats). Note: Values starting with "-" (like -module.resource) are indistinguishable from flags.
func (*IacArgs) HasPlanFile ¶
HasPlanFile checks if a plan file is already specified in args. Checks for -out= flag (plan command) or any argument present (apply/destroy).
func (*IacArgs) InsertArgument ¶
InsertArgument inserts an argument at position and returns self for chaining.
func (*IacArgs) InsertArguments ¶
InsertArguments inserts arguments at position and returns self for chaining.
func (*IacArgs) InsertFlag ¶
InsertFlag inserts flag(s) at position and returns self for chaining.
func (*IacArgs) IsDestroyCommand ¶
IsDestroyCommand returns true if this represents a destroy operation. It checks both the command name and the -destroy flag.
func (*IacArgs) MergeFlags ¶
MergeFlags merges flags from another IacArgs, adding only flags not already present. Handles both -flag=value and space-separated -flag value formats. Returns self for chaining.
func (*IacArgs) Normalize ¶
func (a *IacArgs) Normalize(acts ...NormalizeActsType) *IacArgs
Normalize formats the flags according to the given actions.
func (*IacArgs) RemoveFlag ¶
RemoveFlag removes a flag by name (handles -flag, --flag, -flag=value, and space-separated -flag value).
func (*IacArgs) Second ¶
Second returns the second element (first subcommand, first flag, or first argument).
func (*IacArgs) SetCommand ¶
SetCommand sets the command and returns self for chaining.
type NormalizeActsType ¶
type NormalizeActsType byte
const ( SingleDashFlag NormalizeActsType = iota DoubleDashFlag )