https://github.com/bfontaine/envflag
:flags: Set environment variables from command-line flags
https://github.com/bfontaine/envflag
go library
Last synced: over 1 year ago
JSON representation
:flags: Set environment variables from command-line flags
- Host: GitHub
- URL: https://github.com/bfontaine/envflag
- Owner: bfontaine
- License: mit
- Created: 2015-09-11T19:45:01.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2015-09-11T19:45:07.000Z (almost 11 years ago)
- Last Synced: 2025-03-23T23:43:40.166Z (over 1 year ago)
- Topics: go, library
- Language: Go
- Homepage: https://godoc.org/github.com/bfontaine/envflag
- Size: 109 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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`:
```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'
```