internalenv

package
v0.17.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 30, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FlagAnnotation        = "leodido/structcli/flag-envs"
	FlagEnvOnlyAnnotation = "leodido/structcli/flag-env-only"
)

Variables

View Source
var (
	EnvSep = "_"
)

Functions

func BindEnv

func BindEnv(c *cobra.Command) error

func GetPrefix added in v0.10.0

func GetPrefix() string

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

func IsValidFlagEnvTag(tagValue string) bool

IsValidFlagEnvTag validates the flagenv tag value. Returns nil for valid values ("", "true", "false", "only") and an error otherwise.

func NormEnv

func NormEnv(str string) string

func PatchEnvPrefix added in v0.17.0

func PatchEnvPrefix(c *cobra.Command, oldPrefix, newPrefix string)

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.

func SetPrefix added in v0.10.0

func SetPrefix(v string)

Types

type EnvMode added in v0.16.0

type EnvMode int

EnvMode describes how a field participates in environment variable binding.

const (
	// EnvOff means no env binding for this field.
	EnvOff EnvMode = iota
	// EnvOn means the field has both a CLI flag and env binding.
	EnvOn
	// EnvOnly means the field is settable only via env var (and config), not CLI.
	EnvOnly
)

func GetEnv

func GetEnv(f reflect.StructField, inherit bool, path, alias, envPrefix string) ([]string, EnvMode)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL