-
Notifications
You must be signed in to change notification settings - Fork 1
/
flags_test.go
39 lines (32 loc) · 926 Bytes
/
flags_test.go
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
32
33
34
35
36
37
38
39
package flagstruct_test
import (
"github.com/Benzinga/flagstruct"
)
// This snippet shows how to use flag and environment variable parsing with
// flagstruct.
func Example_simple() {
conf := struct {
Compress bool `flag:"z" usage:"whether or not to use compression" env:"COMPRESS"`
OutputFn string `flag:"out" usage:"output ~filename~"`
}{
Compress: true,
}
// Parse flags based on structure.
flagstruct.Configure(&conf)
}
// This snippet shows how to use flag and environment parsing without using
// the Configure helper that couples configuration with parsing.
func Example_advanced() {
conf := struct {
Compress bool `flag:"z" usage:"whether or not to use compression" env:"COMPRESS"`
OutputFn string `flag:"out" usage:"output ~filename~"`
}{
Compress: true,
}
// Set up flags.
flagstruct.Struct(&conf)
// Parse environment.
flagstruct.ParseEnv()
// Parse flags.
flagstruct.Parse()
}