-
Notifications
You must be signed in to change notification settings - Fork 3
/
options.go
89 lines (71 loc) · 2.11 KB
/
options.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package main
import (
"flag"
"fmt"
"os"
"strings"
)
func Banner() {
banner := fmt.Sprintf(` ______ _____ ______ __ __ _____
/_/\___\ ) ___ ( / ____/\/_/\ /\_\ /\___/\
) ) ___/ / /\_/\ \) ) __\/) ) \ ( ( / / _ \ \
/_/ / ___ / /_/ (_\ \\ \ \ /_/ \ \_\\ \(_)/ /
\ \ \_/\__\\ \ )_/ / /_\ \ \\ \ \ / // / _ \ \
)_) \/ _/ \ \/_\/ /)____) ))_) \ (_(( (_( )_) )
\_\____/ )_____( \____\/ \_\/ \/_/ \/_/ \_\/
v1.0 @alanEG
`)
fmt.Println(banner)
}
//declare flag.Usage values
func init() {
flag.Usage = func() {
h := "Usage: ./gosna [options]\n"
h += " -run Run type [add,check]\n"
h += " -timeout Requests timeout (default 5)\n"
h += " -thread Requests thread\n"
h += " -header -H Requests header\n"
h += " -repeat -r Repeat Check [m,h,d]\n"
h += " -dynamic Check dynamic (default false)\n"
h += " -config Config file (default ~/.gosna_config.json)\n"
h += " -no-color Disable color\n"
fmt.Fprintf(os.Stderr, h)
}
}
func (i *arrayFlags) String() string {
return ""
}
func (i *arrayFlags) Set(value string) error {
*i = append(*i, value)
return nil
}
func options_parse() {
//handling header array
// ./change -headers value1 -headers value2
flag.StringVar(&Run, "run", "", "")
directoryHome, _ := os.UserHomeDir()
flag.StringVar(&configFileFlag, "config", directoryHome+"/.gosna_config.json", "")
flag.StringVar(&flagRepeat, "repeat", "", "")
flag.StringVar(&flagRepeat, "r", "", "")
flag.BoolVar(&flagDynmaic, "dynamic", false, "")
flag.BoolVar(&flagNoColor, "no-color", false, "")
flag.IntVar(&flagTimeout, "timeout", 5, "")
flag.IntVar(&Thread, "thread", 5, "")
flag.Var(&Headers, "header", "")
flag.Var(&Headers, "H", "")
flag.Parse()
Header = parse_headers(Headers)
if len(os.Args) < 2 {
flag.Usage()
os.Exit(0)
}
}
//handling headers flags
func parse_headers(headers []string) map[string]string {
headersv := make(map[string]string)
for _, header := range headers {
hv := strings.Split(header, `:`)
headersv[hv[0]] = hv[1]
}
return headersv
}