Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BoolFlagInfo ¶ added in v1.232.0
type BoolFlagInfo interface {
// IsBool reports whether the flag is boolean.
IsBool() bool
}
BoolFlagInfo is an optional interface a FlagInfo may implement to declare that it is a boolean flag. Flags that do not implement it are not boolean.
type BoolValuePreprocessor ¶ added in v1.232.0
type BoolValuePreprocessor struct {
// contains filtered or unexported fields
}
BoolValuePreprocessor rewrites "--flag true|false" to "--flag=true|false" for registered boolean flags.
Cobra boolean flags never consume the following argument, so without this step "--no-color false" leaves "false" behind as a stray positional argument (an unknown command, or an argument forwarded to Terraform). Only the exact literals "true" and "false" (case-insensitive) are folded into the flag. Any other following argument, such as a subcommand or component name, is left alone so a bare "--flag" keeps meaning "true".
Example transformation:
Input: ["--logs-color", "false", "version"] Output: ["--logs-color=false", "version"]
Arguments after the "--" terminator are never modified.
func NewBoolValuePreprocessor ¶ added in v1.232.0
func NewBoolValuePreprocessor(flags []FlagInfo) *BoolValuePreprocessor
NewBoolValuePreprocessor creates a preprocessor for the boolean flags among the given flags. Both the long name and the shorthand of each boolean flag are recognized.
func (*BoolValuePreprocessor) Preprocess ¶ added in v1.232.0
func (p *BoolValuePreprocessor) Preprocess(args []string) []string
Preprocess rewrites "--flag true|false" to "--flag=true|false" for boolean flags.
type FlagInfo ¶
type FlagInfo interface {
// GetName returns the flag's name (e.g., "identity").
GetName() string
// GetShorthand returns the flag's shorthand (e.g., "i").
GetShorthand() string
// GetNoOptDefVal returns the flag's NoOptDefVal sentinel value.
GetNoOptDefVal() string
// GetNoOptDefValConsumesNextArg reports whether "--flag value" should be
// rewritten to "--flag=value".
GetNoOptDefValConsumesNextArg() bool
}
FlagInfo represents the information needed about a flag for preprocessing. This interface matches the methods needed from flags.Flag, avoiding circular imports.
type NoOptDefValPreprocessor ¶
type NoOptDefValPreprocessor struct {
// contains filtered or unexported fields
}
NoOptDefValPreprocessor rewrites space-separated syntax to equals syntax for flags with NoOptDefVal set.
This works around a Cobra/pflag limitation where NoOptDefVal only works with equals syntax (--flag=value), not space-separated syntax (--flag value). See: https://github.com/spf13/pflag/issues/134, pflag#321, cobra#1962
Example transformation:
Input: ["--identity", "prod", "plan"] Output: ["--identity=prod", "plan"]
Without preprocessing, "prod" would be treated as a positional argument because Cobra's NoOptDefVal assumes the user wants the default value when no equals sign is present.
func NewNoOptDefValPreprocessor ¶
func NewNoOptDefValPreprocessor(flags []FlagInfo) *NoOptDefValPreprocessor
NewNoOptDefValPreprocessor creates a new preprocessor with the given flags. The flags slice should contain all flags that may have NoOptDefVal set.
func (*NoOptDefValPreprocessor) Preprocess ¶
func (p *NoOptDefValPreprocessor) Preprocess(args []string) []string
Preprocess rewrites space-separated flag syntax to equals syntax for flags that have NoOptDefVal set.
type Pipeline ¶
type Pipeline struct {
// contains filtered or unexported fields
}
Pipeline runs multiple preprocessors in sequence. This allows composing multiple preprocessing steps in a clear, testable manner.
func NewPipeline ¶
func NewPipeline(preprocessors ...Preprocessor) *Pipeline
NewPipeline creates a new preprocessing pipeline with the given preprocessors. Preprocessors are run in the order they are provided.
type Preprocessor ¶
type Preprocessor interface {
// Preprocess transforms args and returns the modified args.
// Implementations should not modify the input slice.
Preprocess(args []string) []string
}
Preprocessor transforms command-line arguments before Cobra parses them. This is distinct from compatibility flags (pkg/flags/compat) which translate external tool syntax like Terraform's -var.
Preprocessing handles native Atmos flag behavior that requires argument transformation before Cobra's parsing phase.