Documentation ¶
Overview ¶
Package envflag provides a way to override environment variables with flags
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrMalformedValue = errors.New("Malformed environment key/value pair, expected <key>=<value>")
ErrMalformedValue is returned by Value.Set if the given key/value pair is not valid.
Functions ¶
func AutoSetup ¶
func AutoSetup()
AutoSetup is a shortcut for Setup("e", "Override environment variables"). It must be called before flag.Parse().
func Setup ¶
func Setup(flagName, usage string)
Setup creates a flag that will be used to override environment variables. It must be called before flag.Parse(). The flag can occur multiple times in the command-line.
Example ¶
package main import ( "flag" "fmt" "os" "github.com/bfontaine/envflag" ) func main() { envflag.Setup("e", "Override env variables") flag.Parse() fmt.Printf("The key is '%s'\n", os.Getenv("KEY")) // This example will print: // - "foobar" if it’s called as ./example -e KEY=foobar regardless of the // environment variable "KEY" // - "abc123" if it’s called as ./example AND the environment variable // "KEY" is set to "abc123" // - an empty key if no -e flag is passed and the environment variable // "KEY" is empty or doesn’t exist }
Output:
Types ¶
Click to show internal directories.
Click to hide internal directories.