package flagutil

import "github.com/coreos/pkg/flagutil"

Index

Functions

func SetFlagsFromEnv

func SetFlagsFromEnv(fs *flag.FlagSet, prefix string) (err error)

SetFlagsFromEnv parses all registered flags in the given flagset, and if they are not already set it attempts to set their values from environment variables. Environment variables take the name of the flag but are UPPERCASE, and any dashes are replaced by underscores. Environment variables additionally are prefixed by the given string followed by and underscore. For example, if prefix=PREFIX: some-flag => PREFIX_SOME_FLAG

func SetFlagsFromEnvFile

func SetFlagsFromEnvFile(fs *flag.FlagSet, prefix string, path string) (err error)

SetFlagsFromEnvFile iterates the given flagset and if any flags are not already set it attempts to set their values from the given env file. Env files may have KEY=VALUE lines where the environment variable names are in UPPERCASE, prefixed by the given PREFIX, and dashes are replaced by underscores. For example, if prefix=PREFIX, some-flag is named PREFIX_SOME_FLAG. Comment lines are skipped, but more complex env file parsing is not performed.

Types

type IPv4Flag

type IPv4Flag struct {
	// contains filtered or unexported fields
}

IPv4Flag parses a string into a net.IP after asserting that it is an IPv4 address. This type implements the flag.Value interface.

func (*IPv4Flag) IP

func (f *IPv4Flag) IP() net.IP

func (*IPv4Flag) Set

func (f *IPv4Flag) Set(v string) error

func (*IPv4Flag) String

func (f *IPv4Flag) String() string

type StringSliceFlag

type StringSliceFlag []string

StringSliceFlag parses a comma-delimited list of strings into a []string. This type implements the flag.Value interface.

func (*StringSliceFlag) Set

func (ss *StringSliceFlag) Set(v string) error

func (*StringSliceFlag) String

func (ss *StringSliceFlag) String() string

Source Files

env.go env_file.go types.go

Version
v0.0.0-20240122114842-bbd7aa9bf6fb (latest)
Published
Jan 22, 2024
Platform
linux/amd64
Imports
7 packages
Last checked
2 weeks ago

Tools for package owners.