Documentation
¶
Overview ¶
Package flagalias owns parse-time aliases for Cobra/pflag commands.
An alias is another accepted spelling of one canonical flag. It is not a second pflag: parsing an alias resolves to the canonical flag before pflag applies the value, so type, default, Changed state, required/enum/input contracts, and repeated-flag behavior all stay attached to one object.
Value conversion for non-equivalent legacy inputs is a business compatibility concern, not an alias. Exact aliases always use the canonical flag's native occurrence semantics; domains must not add a separate conflict policy.
Index ¶
Constants ¶
const AnnotationAliases = "lark-cli/flag-aliases"
AnnotationAliases is attached to the canonical pflag. Consumers should use Aliases instead of reading the annotation directly.
Variables ¶
This section is empty.
Functions ¶
func Aliases ¶
Aliases returns a defensive copy of the raw accepted alias spellings stored on a canonical pflag. Alias order matches declaration order.
func Bind ¶
Bind installs exact-name aliases on cmd and records them on their canonical pflags for manifest/tooling introspection. Existing pflag normalization is composed first; alias resolution is then applied to the normalized spelling. The canonical pflag also remembers the spelling that supplied its most recently applied value so validation errors can point back to the caller's actual input without changing native repeated-flag semantics.
Bind is intentionally the only production owner of SetNormalizeFunc. It validates the complete accepted-name set before installing alias metadata or a normalizer, so a configuration error cannot leave aliases partially bound.
Types ¶
type InvalidValueAttribution ¶
InvalidValueAttribution identifies the canonical flag and the long-form spelling that supplied a value which pflag could not convert. Names do not include leading dashes.
func InvalidValueAttributionOf ¶
func InvalidValueAttributionOf(err error) (InvalidValueAttribution, bool)
InvalidValueAttributionOf resolves a typed pflag conversion error for a flag managed by Bind. Ordinary pflags return ok=false so installing aliases does not broaden the root error contract for unrelated commands.
pflag's InvalidValueError does not report whether a canonical flag with a shorthand was supplied as -x or --long. That ambiguous case also returns ok=false; an alias spelling remains unambiguous because Bind records it before value conversion.