Documentation
¶
Index ¶
- Constants
- Variables
- func BindEnv(c *cobra.Command) error
- func GetPrefix() string
- func IsEnvOnly(f reflect.StructField) bool
- func IsValidFlagEnvTag(tagValue string) bool
- func NormEnv(str string) string
- func PatchEnvPrefix(c *cobra.Command, oldPrefix, newPrefix string)
- func SetPrefix(v string)
- type EnvMode
Constants ¶
View Source
const ( FlagAnnotation = "leodido/structcli/flag-envs" FlagEnvOnlyAnnotation = "leodido/structcli/flag-env-only" )
Variables ¶
View Source
var (
EnvSep = "_"
)
Functions ¶
func IsEnvOnly ¶ added in v0.16.0
func IsEnvOnly(f reflect.StructField) bool
IsEnvOnly returns true if the struct field's flagenv tag is set to "only".
func IsValidFlagEnvTag ¶ added in v0.16.0
IsValidFlagEnvTag validates the flagenv tag value. Returns nil for valid values ("", "true", "false", "only") and an error otherwise.
func PatchEnvPrefix ¶ added in v0.17.0
PatchEnvPrefix updates env annotations on all flags of c to use newPrefix. It strips any existing oldPrefix from annotation values and prepends newPrefix. When oldPrefix is empty and c is the root command, the root command's name was used as a pseudo-prefix by GetEnv and must be stripped before applying newPrefix. For each patched flag, it clears the bound-env marker in the command's scope so that a subsequent BindEnv call will re-bind with the corrected env var names.
Types ¶
Click to show internal directories.
Click to hide internal directories.