-
Notifications
You must be signed in to change notification settings - Fork 4
/
args.go
60 lines (47 loc) · 1.8 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
package main
// Defines the command line parsing function and global variables
import (
"flag"
"fmt"
"os"
)
var gArgLogPath string
var gArgAuditPath string
var gArgAuditBoth bool
var gArgLogBoth bool
var gArgNoAuditBool bool
var gArgConfigPath string
var gArgPACPath string
var gArgQuietBool bool
var gArgVerboseBool bool
func cmdlineError(a ...interface{}) {
fmt.Fprintln(os.Stderr, a...)
os.Exit(1)
}
// parseArgs parses the command line arguments, performs some checks, and store them in the associated global variables
func parseArgs() {
flag.BoolVar(&gArgQuietBool, "q", false, "Quiet mode")
flag.BoolVar(&gArgVerboseBool, "v", false, "Verbose mode")
flag.StringVar(&gArgAuditPath, "audit-file", "", "File to output audit traces. Output to STDOUT if empty")
flag.BoolVar(&gArgAuditBoth, "audit-both", false, "Output audit traces to both -audit-file and STDOUT.")
flag.StringVar(&gArgLogPath, "log-file", "", "File to output logs. Output to STDOUT if empty")
flag.BoolVar(&gArgLogBoth, "log-both", false, "Output logs to both -log-file and STDOUT.")
flag.StringVar(&gArgConfigPath, "c", "./bbs.json", "JSON configuration file path")
flag.BoolVar(&gArgNoAuditBool, "no-audit", false, "No audit traces mode")
if gPACcompiled {
flag.StringVar(&gArgPACPath, "pac", "", "PAC script file path")
}
flag.Parse()
if gArgQuietBool && gArgVerboseBool {
cmdlineError("Arguments -q and -v cannot be used together")
}
if gArgAuditBoth && gArgAuditPath == "" {
cmdlineError("-audit-file must be defined if -audit-both is set")
}
if gArgLogBoth && gArgLogPath == "" {
cmdlineError("-log-file must be defined if -log-both is set")
}
if (gArgNoAuditBool && gArgAuditBoth) || (gArgNoAuditBool && gArgAuditPath != "") {
cmdlineError("Arguments -no-audit and -audit-file/-audit-both cannot be used together")
}
}