Adds version flag

This commit is contained in:
Stephen McQuay 2018-02-28 23:20:34 -08:00
parent ae4a2ba084
commit 1f89e3a7bc
Signed by: sm
GPG Key ID: 4E4B72F479BA3CE5

26
main.go
View File

@ -1,11 +1,17 @@
package main package main
import ( import (
"fmt"
"math" "math"
"os"
"runtime" "runtime"
"sync" "sync"
) )
const version = "v1.0.1"
const usage = "heat [-v|--verbose]"
func heat() { func heat() {
var t float64 = math.MaxFloat64 var t float64 = math.MaxFloat64
for { for {
@ -17,6 +23,15 @@ func heat() {
} }
func main() { func main() {
if len(os.Args) > 1 {
if verbose(os.Args) {
fmt.Printf("heat version %v\n", version)
os.Exit(0)
} else {
fmt.Fprintf(os.Stderr, "usage: %v\n", usage)
os.Exit(1)
}
}
wg := sync.WaitGroup{} wg := sync.WaitGroup{}
wg.Add(1) wg.Add(1)
for i := 0; i < runtime.NumCPU(); i++ { for i := 0; i < runtime.NumCPU(); i++ {
@ -24,3 +39,14 @@ func main() {
} }
wg.Wait() wg.Wait()
} }
func verbose(args []string) bool {
r := false
for _, arg := range args {
switch arg {
case "-v", "-version", "--version", "v", "version":
r = true
}
}
return r
}