forked from ligato/cn-infra
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
66 lines (58 loc) · 1.78 KB
/
main.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
56
57
58
59
60
61
62
63
64
65
66
package main
import (
"fmt"
"time"
"github.com/namsral/flag"
)
// *************************************************************************
// This file contains example of how to register CLI flags and how to show
// their runtime values.
// ************************************************************************/
func main() {
RegisterFlags()
ParseFlags()
PrintFlags()
}
// Flag variables
var (
testFlagString string
testFlagInt int
testFlagInt64 int64
testFlagUint uint
testFlagUint64 uint64
testFlagBool bool
testFlagDur time.Duration
)
// RegisterFlags contains examples of how to register flags of various types.
func RegisterFlags() {
fmt.Println("Registering flags...")
flag.StringVar(&testFlagString, "ep-string", "my-value",
"Example of a string flag.")
flag.IntVar(&testFlagInt, "ep-int", 1122,
"Example of an int flag.")
flag.Int64Var(&testFlagInt64, "ep-int64", -3344,
"Example of an int64 flag.")
flag.UintVar(&testFlagUint, "ep-uint", 5566,
"Example of a uint flag.")
flag.Uint64Var(&testFlagUint64, "ep-uint64", 7788,
"Example of a uint64 flag.")
flag.BoolVar(&testFlagBool, "ep-bool", true,
"Example of a bool flag.")
flag.DurationVar(&testFlagDur, "ep-duration", time.Second*5,
"Example of a duration flag.")
}
// ParseFlags parses the command-line flags.
func ParseFlags() {
flag.Parse()
}
// PrintFlags shows the runtime values of CLI flags.
func PrintFlags() {
fmt.Println("Printing flags...")
fmt.Printf("testFlagString:'%s'\n", testFlagString)
fmt.Printf("testFlagInt:'%d'\n", testFlagInt)
fmt.Printf("testFlagInt64:'%d'\n", testFlagInt64)
fmt.Printf("testFlagUint:'%d'\n", testFlagUint)
fmt.Printf("testFlagUint64:'%d'\n", testFlagUint64)
fmt.Printf("testFlagBool:'%v'\n", testFlagBool)
fmt.Printf("testFlagDur:'%v'\n", testFlagDur)
}