-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
44 lines (36 loc) · 870 Bytes
/
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
package main
import (
"flag"
"fmt"
"os"
)
var (
stringValue string
intValue int
boolValue bool
helpText = `
Usage: foo [--<optional parameters>=value]
Simple command that prints argument
Options:
--string-value=<Just string value>
--int-value=<Just int value>
--bool-value=<Just bool value>
`
)
func main() {
flags := flag.NewFlagSet("foo commands", flag.ContinueOnError)
flags.Usage = func() {
fmt.Println(helpText)
}
flags.StringVar(&stringValue, "string-value", "string", "Just string value")
flags.IntVar(&intValue, "int-value", 60, "Just int value")
flags.BoolVar(&boolValue, "bool-value", true, "Just bool value")
args := os.Args[1:]
if err := flags.Parse(args); err != nil {
os.Exit(1)
}
fmt.Println("stringValue: ", stringValue)
fmt.Println("intValue: ", intValue)
fmt.Println("boolValue: ", boolValue)
os.Exit(0)
}