-
Notifications
You must be signed in to change notification settings - Fork 0
/
basic_usage.go
55 lines (44 loc) · 1.21 KB
/
basic_usage.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package main
import (
"fmt"
"os"
"github.com/leeif/kiper"
)
type KiperTester struct {
StringVar string `kiper_value:"name:string_var;help:"string var";default:test string"`
IntVar int `kiper_value:"name:int_var;default:10"`
BoolVar bool `kiper_value:"name:bool_var;default:true"`
ArrayVar []string `kiper_value:"name:array_var;default:test1, test2"`
StructVar *StructVar `kiper_value:"name:struct_var;default:I am a struct"`
}
type StructVar struct {
data string
}
func (structVar *StructVar) Set(data string) error {
structVar.data = data
return nil
}
func (structVar *StructVar) String() string {
return structVar.data
}
func main() {
// initialize config struct
kt := &KiperTester{
StructVar: &StructVar{},
}
// new kiper
k := kiper.NewKiper("example", "example of kiper")
// set your own config file path flag with default value
k.SetConfigFileFlag("config", "config file", "./config.json")
k.Kingpin.HelpFlag.Short('h')
// parse command line and config file
if err := k.Parse(kt, os.Args[1:]); err != nil {
fmt.Println(err)
os.Exit(1)
}
fmt.Println(kt.StringVar)
fmt.Println(kt.IntVar)
fmt.Println(kt.BoolVar)
fmt.Println(kt.StructVar.data)
fmt.Println(kt.ArrayVar)
}