-
Notifications
You must be signed in to change notification settings - Fork 0
/
args.go
62 lines (53 loc) · 1.64 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
56
57
58
59
60
61
62
package main
import (
"flag"
"fmt"
"os"
)
type Arguments struct {
Host string
TestsDir string
User string
Password string
Threads int
Timeout int
Verbosity int
TlsLogPath string
CliMode bool
}
func parseArguments() Arguments {
var args Arguments
flag.StringVar(&args.TestsDir, "d", "./tests", "The directory containing the test groups. Defaults to './tests'.")
flag.StringVar(&args.User, "u", "wazuh", "The username for the Wazuh API. Defaults to 'wazuh'.")
flag.StringVar(&args.Password, "p", "wazuh", "The password for the Wazuh API. Defaults to 'wazuh'.")
flag.IntVar(&args.Threads, "t", 1, "The number of threads to use for running tests. Defaults to 1.")
flag.IntVar(&args.Timeout, "o", 5, "The timeout for API requests. Defaults to 5 seconds.")
flag.StringVar(&args.TlsLogPath, "tls-log", "", "Enable and log the TLS key to the path specified.")
flag.BoolVar(&args.CliMode, "c", false, "Enable cli mode for use in pipelines and automations. Defaults to false.")
// Custom parsing for verbosity
var vFlag, vvFlag bool
flag.BoolVar(&vFlag, "v", false, "Enable verbosity level 1.")
flag.BoolVar(&vvFlag, "vv", false, "Enable verbosity level 2.")
flag.Usage = func() {
fmt.Fprintf(os.Stderr, "Usage: %s [options] host\n", os.Args[0])
flag.PrintDefaults()
}
flag.Parse()
// Handle verbosity
if vvFlag {
args.Verbosity = 2
} else if vFlag {
args.Verbosity = 1
} else {
args.Verbosity = 0
}
// Positional argument for host
if len(flag.Args()) < 1 {
fmt.Fprintln(os.Stderr, "Error: host argument is required.")
flag.Usage()
os.Exit(1)
} else {
args.Host = flag.Args()[0]
}
return args
}