flag

package
v0.0.0-...-1b2a2de Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AdditionalEnv

func AdditionalEnv(fs *pflag.FlagSet, flagName, envName string)

AdditionalEnv allows additional env vars to set the flag value as well. Unlike BindEnv, this does not do any transformations.

func Bind

func Bind[T Flaggable](fs *pflag.FlagSet, name, shorthand, usage string, val *T)

Bind registers a flag to the FlagSet. When parsed, the value will be set via pointer. Usage:

cfg := Config{Foo: "default-foo"}
flag.Bind(fs, "foo", "f", "the foo value", &cfg.Foo)

func BindEnv

func BindEnv[T Flaggable](fs *pflag.FlagSet, name, shorthand, usage string, val *T)

BindEnv behaves like Bind, but additionally allows an environment variable to override. This will transform to name field: foo-bar becomes FOO_BAR.

Types

type Flaggable

type Flaggable interface {
	string | bool | uint16 | time.Duration
}

Flaggable defines the set of types that can be flags. This is not exhaustive; add more as needed

Jump to

Keyboard shortcuts

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