Documentation
¶
Index ¶
- func ContainsStdinRef(values []string) bool
- func GetAll(m map[string][]string, key string) []string
- func GetFirst(m map[string][]string, key string) string
- func Has(m map[string][]string, key string) bool
- func LoadParameterFile(path string) (map[string]any, error)
- func LoadParameterReader(r io.Reader, source string) (map[string]any, error)
- func MergeValue(existing, newVal any) any
- func ParseDynamicInputArgs(args []string) ([]string, error)
- func ParseKeyValue(pairs []string) (map[string][]string, error)
- func ParseKeyValueCSV(pairs []string) (map[string][]string, error)
- func ParseResolverFlags(values []string) (map[string]any, error)
- func ParseResolverFlagsWithStdin(values []string, stdin io.Reader) (map[string]any, error)
- func ValidateInputKeys(inputs map[string]any, validKeys []string, contextName string) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ContainsStdinRef ¶ added in v0.7.0
ContainsStdinRef returns true if any of the values contain the @- token (either standalone or as key=@-), indicating that stdin will be consumed.
func LoadParameterFile ¶ added in v0.6.0
LoadParameterFile loads parameters from a YAML or JSON file. The file format is auto-detected based on extension, or by trying YAML first then JSON if the extension is not recognized.
func LoadParameterReader ¶ added in v0.7.0
LoadParameterReader loads parameters from an io.Reader containing YAML or JSON. It tries YAML first, then JSON, matching the behavior of LoadParameterFile for files with unknown extensions. The source parameter is used in error messages to identify the input origin (e.g., "stdin").
func MergeValue ¶ added in v0.6.0
MergeValue merges a new value with an existing value, creating arrays as needed. If existing is nil, returns newVal. If both are slices, concatenates them. If existing is a scalar and newVal is provided, creates a slice.
func ParseDynamicInputArgs ¶ added in v0.6.0
ParseDynamicInputArgs normalises raw CLI arguments into key=value strings suitable for ParseResolverFlags.
Three forms are recognised:
--key=value → strip the leading "--" → "key=value" key=value → passed through unchanged @file.yaml → passed through unchanged (file reference)
A bare "--key" (no "=") is rejected because we cannot distinguish a boolean flag from a flag that expects the next token as a value. Single-dash forms ("-k=v") are also rejected to avoid collisions with existing short flags.
func ParseKeyValue ¶
ParseKeyValue parses a slice of "key=value" strings into a map where multiple values for the same key are combined into a slice. The first '=' separates key from value - any additional '=' chars are part of the value.
This function does NOT parse CSV - each string in pairs is treated as a single key=value entry. Use ParseKeyValueCSV for CSV support.
func ParseKeyValueCSV ¶
ParseKeyValueCSV parses a slice of "key=value" strings that may contain comma-separated pairs. Commas within quoted values are preserved. Multiple values for the same key are combined into a slice.
Supports shorthand syntax: values without '=' are treated as additional values for the previous key within the same flag.
Examples:
- "env=prod,qa" -> env: [prod, qa] (shorthand)
- "region=us-east1,region=us-west1" -> region: [us-east1, us-west1]
- "env=prod,qa,staging" -> env: [prod, qa, staging] (shorthand)
- "region=us-east,env=prod,debug" -> region: [us-east], env: [prod, debug]
- "msg=\"Hello, world\"" -> msg: ["Hello, world"]
- "key=\"escaped \\\"quotes\\\"\"" -> key: ["escaped \"quotes\""]
Whitespace around commas is trimmed.
func ParseResolverFlags ¶ added in v0.6.0
ParseResolverFlags parses -r flag values, handling both key=value syntax and @file.yaml syntax for loading parameters from files.
Supported formats:
- key=value: Simple key-value pair
- key=value1,value2: Multiple values (becomes an array)
- @file.yaml: Load all parameters from a YAML file
- @file.json: Load all parameters from a JSON file
Multiple values for the same key are automatically combined into an array.
func ParseResolverFlagsWithStdin ¶ added in v0.7.0
ParseResolverFlagsWithStdin parses -r flag values like ParseResolverFlags, but additionally supports @- to read parameters from stdin as YAML or JSON.
Supported formats:
- key=value: Simple key-value pair
- key=value1,value2: Multiple values (becomes an array)
- key=@-: Read raw stdin content as the value for key
- key=@file: Read raw file content as the value for key
- @file.yaml: Load all parameters from a YAML file
- @file.json: Load all parameters from a JSON file
- @-: Read all parameters from stdin (YAML or JSON)
The @- token (both standalone and in key=@-) may only appear once. If stdin is nil and @- is used, an error is returned. Multiple values for the same key are automatically combined into an array.
func ValidateInputKeys ¶ added in v0.6.0
ValidateInputKeys checks that every key in inputs exists in validKeys. Unknown keys produce an error with a "did you mean?" suggestion when a close match (Levenshtein distance ≤ maxSuggestionDistance) is found.
contextName is used in error messages (e.g. "provider \"http\"" or "solution").
Types ¶
This section is empty.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package main provides an example of using pkg/flags for key-value parsing with validation.
|
Package main provides an example of using pkg/flags for key-value parsing with validation. |
|
Package resolve provides resolution and fetching of key-value flag values based on URI scheme prefixes.
|
Package resolve provides resolution and fetching of key-value flag values based on URI scheme prefixes. |
|
Package validate provides validation for key-value flag values based on URI scheme prefixes.
|
Package validate provides validation for key-value flag values based on URI scheme prefixes. |