Skip to content
felixPublic

About

[mirror] Set flags using the standard library `flag` package, and complement them with environment variables

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

4 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Environment variables and flags

Set flags using the standard library flag package, and complement them with environment variables.

  • All Go's standard flag functions are used as normal and parse errors are returned as expected.

  • Flags, if set, take precedence over the environment.

  • Environment variables can have custom prefixes and suffixes.

  • Usage output can be displayed with the standard -h flag.

  • Usage output can be annotated with the configured environment variables.

fs := flag.NewFlagSet("test", flag.ContinueOnError)
fs.String("db", "", "Database thing")
_ = envflag.ParseFlagSet(fs, envflag.Prefix("APP_"), envflag.UsageSuffixer())

produces the following usage

Usage of test:
  -db string
        Database thing [APP_DB]

About

[mirror] Set flags using the standard library `flag` package, and complement them with environment variables

Resources

Stars

0 stars

Watchers

0 watching

Forks

Contributors

Languages