-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_test.go
More file actions
31 lines (23 loc) · 769 Bytes
/
example_test.go
File metadata and controls
31 lines (23 loc) · 769 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package envflags_test
import (
"fmt"
"os"
"github.com/goodfoo/envflags"
)
// Environment variabable IVAL and SVAL will have highest precedence
// command line params -ival and -sval will have next precedence
// and finally defaults
func Example() {
flags := envflags.New() // .Transform(strings.ToLower) <- optional, default is strings.ToUpper
i := flags.Int("ival", 1, "provide and ival as a parameter or env var")
s := flags.String("sval", "flags", "provide a sval as a parameter or env var")
// ignore - required if user runs: go test -v
flags.Bool("test.v", false, "verbosity")
// simulate environment settings
os.Setenv("SVAL", "awesome flags!")
flags.Parse()
fmt.Printf("i = %d\ns = %s", *i, *s)
// Output:
// i = 1
// s = awesome flags!
}