-
Notifications
You must be signed in to change notification settings - Fork 0
/
iif.go
59 lines (53 loc) · 1.37 KB
/
iif.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
package main
import ("os"
"fmt"
"flag"
"strconv"
)
/*
iff left cmd right value other
*/
func main() {
left := flag.String("left", "true", "left hand")
cmd := flag.String("test", "==", "actions: [== != <= < >= > && ||]")
right := flag.String("right", "true", "right hand")
value := flag.String("value", "true", "return value on success")
alt := flag.String("alt", "false", "return value on fail")
flag.Parse()
state := "unknown"
switch *cmd {
case "==":
state = iff (*left==*right, *value, *alt)
case "!=":
state = iff (*left!=*right, *value, *alt)
case "<=":
state = iff (*left<=*right, *value, *alt)
case "<":
state = iff (*left<*right, *value, *alt)
case ">=":
state = iff (*left>=*right, *value, *alt)
case ">":
state = iff (*left>*right, *value, *alt)
case "&&":
l, _ := strconv.ParseBool(*left)
r, _ := strconv.ParseBool(*right)
state = iff (l && r, *value, *alt)
case "||":
l, _ := strconv.ParseBool(*left)
r, _ := strconv.ParseBool(*right)
state = iff (l || r, *value, *alt)
}
fmt.Printf("%s\n", state)
if (state==*value) {
os.Exit(0);
} else {
os.Exit(1);
}
}
func iff(test bool, good string, bad string) string {
if test==true {
return good
} else {
return bad
}
}