Documentation
¶
Overview ¶
Package cliparser parses argv into a map of stable config keys using precomputed flag definitions. Code generators build Def values at generate time; runtime parsing does not use reflection.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConfigKeyPath ¶
ConfigKeyPath builds the stable config key "prefix.key".
func DefaultLongName ¶
DefaultLongName builds the default long flag name without leading dashes: "{prefix}-{key}", with '.' in both prefix and key replaced by '-'.
Types ¶
type Def ¶
type Def struct {
// ConfigKey is the stable overlay key (e.g. "webserver.port").
ConfigKey string
// Longs are long flag names without leading dashes (e.g. "webserver-port" or "port").
Longs []string
// Shorts are optional single-letter short names without leading dashes (e.g. "p").
Shorts []string
// Help is optional usage text.
Help string
// Env is an optional exact environment variable override. Empty derives the
// name from the first long option; "-" disables environment loading.
Env string
// Kind selects value parsing behavior.
Kind Kind
// Enum is the allowlist this flag accepts, already split and trimmed at
// generation time. A usage renderer lists the choices; the value check
// itself lives in the generated apply code, not here.
Enum []string
// UsesOptOverride is true when names came from an opt-style override.
UsesOptOverride bool
}
Def is one CLI flag definition mapping long/short names to a stable config key. Aligns with data:cli-flag-def / decision:cli-flag-naming.
func BuildDefs ¶
BuildDefs builds flag definitions for a slice of field metadata (codegen helper entry point).
func DefFromField ¶
DefFromField builds a Def from FieldMeta using decision:cli-flag-naming rules.
type FieldMeta ¶
type FieldMeta struct {
// Prefix is the Bind prefix / table name (e.g. "webserver").
Prefix string
// Key is the relative field key under the prefix (e.g. "port" or "tls.enabled").
Key string
// Opt is an optional override of the form "long" or "long,short" (no dashes).
// When set, only those names are registered; default --prefix-key is suppressed.
Opt string
// Help is optional CLI help text.
Help string
// Env is an optional exact environment variable override, or "-" to disable
// environment loading for this field.
Env string
// Kind defaults to KindString when zero value is left as KindString.
Kind Kind
// Enum is the field's allowlist, already split and trimmed, for usage text.
Enum []string
}
FieldMeta is codegen-facing field metadata used to build Def values without runtime tags.
type Result ¶
type Result struct {
// Values maps stable config keys to a single string (last write wins for KindString/KindBool).
Values map[string]string
// Multi maps stable config keys to accumulated values for KindArray flags.
Multi map[string][]string
// Rest is non-flag arguments after flags (or after "--").
Rest []string
}
Result is the outcome of parsing argv against flag definitions.