-
Notifications
You must be signed in to change notification settings - Fork 2
/
example.go
41 lines (36 loc) · 1.04 KB
/
example.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
40
41
package main
import (
"fmt"
"github.com/urfave/cli"
"github.com/urfave/cli/altsrc"
)
func main() {
var (
defaultValue cli.StringSlice = []string{"Hello", "world"}
)
fmt.Printf("--- Start --------------------------------\n")
fmt.Printf("Have test-string-slice value: %v\n", defaultValue)
flags := []cli.Flag{
altsrc.NewStringSliceFlag(cli.StringSliceFlag{
Name: "test-string-slice,s",
EnvVar: "SLICE",
Value: &defaultValue,
}),
altsrc.NewStringFlag(cli.StringFlag{
Name: "load",
Value: "conf.json",
}),
}
(&cli.App{
EnableBashCompletion: true,
Action: func(c *cli.Context) error {
fmt.Printf("--- Action --------------------------------\n")
fmt.Printf("Have test-string-slice value: %v\n", defaultValue)
fmt.Printf("Have test-string-slice context: %v\n", c.StringSlice("test-string-slice"))
fmt.Printf("Have load context: %v\n", c.String("load"))
return nil
},
Before: altsrc.InitInputSourceWithContext(flags, altsrc.NewYamlSourceFromFlagFunc("load")),
Flags: flags,
}).RunAndExitOnError()
}