Skip to content

Commit

Permalink
Exit with a return code for commands that return a boolean (#1)
Browse files Browse the repository at this point in the history
Signed-off-by: delucks <ping@jamieluck.com>
  • Loading branch information
delucks authored Mar 11, 2020
1 parent 521ff85 commit 36a832b
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,26 @@ func main() {
os.Exit(1)
}
command := os.Args[1]
var exitCode int
switch command {
case "contains":
result, err := contains(os.Args[2], os.Args[3])
if err != nil {
fmt.Println(err)
}
fmt.Println(result)
if result == "no\n" {
exitCode = 1
}
case "overlaps":
result, err := overlaps(os.Args[2], os.Args[3])
if err != nil {
fmt.Println(err)
}
fmt.Println(result)
if result == "no\n" {
exitCode = 1
}
case "expand":
result, err := expand(os.Args[2])
if err != nil {
Expand All @@ -89,8 +96,10 @@ func main() {
fmt.Println(result)
default:
fmt.Println("unknown command")
exitCode = 1
flag.Usage()
}
os.Exit(exitCode)
}

// contains returns "yes" if the input IP or CIDR is in the target CIDR
Expand Down

0 comments on commit 36a832b

Please sign in to comment.