-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers.go
54 lines (43 loc) · 1.16 KB
/
helpers.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
package main
import "os"
func checkParams(params []string, expectedCommand string, value_required bool) bool {
shortCommand := "-" + string(expectedCommand[0])
longCommand := "--" + expectedCommand
for paramLocation, param := range params {
if param == shortCommand || param == longCommand {
if value_required {
// if the next param is a command, or the last param, return false
if paramLocation+1 < len(params) {
if checkValue(params[paramLocation+1]) {
return true
}
}
} else {
return true
}
}
}
return false
}
func checkValue(params string) bool {
return string(params[0]) != "-"
}
func getParams(params []string, expectedCommand string) string {
shortCommand := "-" + string(expectedCommand[0])
longCommand := "--" + expectedCommand
for paramLocation, param := range params {
if param == shortCommand || param == longCommand {
if paramLocation+1 < len(params) {
return params[paramLocation+1]
}
}
}
return ""
}
func getEnvVariable(envVar string) string {
variable, variable_ok := os.LookupEnv(envVar)
if !variable_ok {
logger.Fatal("Environment variable ", envVar, " not set")
}
return variable
}