Skip to content

bfontaine/envflag

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

envflag

enflag is a lightweight Go library to allow environment variables overriding with command-line flags.

Install

go get github.com/bfontaine/envflag

Example

This example is available in example/main.go:

package main

import (
    "flag"
    "fmt"
    "os"

    "github.com/bfontaine/envflag"
)

func main() {
    envflag.AutoSetup()
    flag.Parse()

    fmt.Printf("The key is '%s'\n", os.Getenv("KEY"))
}

Once compiled, here is how to use it:

$ ./example -e KEY=42
The key is '42'

$ export KEY=43
$ ./example
The key is '43'

$ export KEY=43
$ ./example -e KEY=41
The key is '41'

$ ./example -e KEY=41 -e KEY=abcd
The key is 'abcd'

About

🎏 Set environment variables from command-line flags

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages