-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathargs.go
55 lines (46 loc) · 1.25 KB
/
args.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 tob
import (
"flag"
"fmt"
)
// Argument type
type Argument struct {
ShowVersion bool
ConfigFile string
Help func()
Message []byte
Verbose bool
}
// ParseArgument will parse the OS args into Argument type
func ParseArgument() (*Argument, error) {
argument := new(Argument)
var (
configFile string
showVersion bool
verbose bool
)
flag.StringVar(&configFile, "config", "config.json", "config file (.json)")
flag.StringVar(&configFile, "c", "config.json", "config file (.json)")
flag.BoolVar(&showVersion, "version", false, "show version")
flag.BoolVar(&showVersion, "v", false, "show version")
flag.BoolVar(&verbose, "V", true, "verbose mode (if true log will appear otherwise no)")
flag.Usage = func() {
fmt.Println()
fmt.Println("Usage: ")
fmt.Println("tob -[options]")
fmt.Println()
fmt.Println("tob -c config.json")
fmt.Println()
fmt.Println("-config | -c (configuration .json file)")
fmt.Println("-h | -help (show help)")
fmt.Println("-v | -version (show version)")
fmt.Println("-V : verbose mode")
fmt.Println("---------------------------")
fmt.Println()
}
flag.Parse()
argument.ConfigFile = configFile
argument.ShowVersion = showVersion
argument.Verbose = verbose
return argument, nil
}