x: within.website/x/internal/flagenv Index | Examples | Files

package flagenv

import "within.website/x/internal/flagenv"

Package flagenv provides the ability to populate flags from environment variables.

Index

Examples

Package Files

flagenv.go legal.go

Variables

var Prefix = ""

Specify a prefix for environment variables.

func Parse Uses

func Parse()

Parse will set each defined flag from its corresponding environment variable . If dots or dash are presents in the flag name, they will be converted to underscores.

If Parse fails, a fatal error is issued.

Code:

var raz string
flag.StringVar(&raz, "raz-value", "bar", "set the raz")

// override default flag value with value found in MY_RAZ_VALUE
flagenv.Prefix = "my_"
flagenv.Parse()

// override value found in MY_RAZ_VALUE with command line flag value -raz-value=foo
flag.Parse()

func ParseSet Uses

func ParseSet(prefix string, set *flag.FlagSet) error

ParseSet parses the given flagset. The specified prefix will be applied to the environment variable names.

Package flagenv imports 6 packages (graph) and is imported by 5 packages. Updated 2019-06-07. Refresh now. Tools for package owners.