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
1 changed files with 26 additions and 0 deletions

26
main.go
View File

@ -1,11 +1,17 @@
package main
import (
"fmt"
"math"
"os"
"runtime"
"sync"
)
const version = "v1.0.1"
const usage = "heat [-v|--verbose]"
func heat() {
var t float64 = math.MaxFloat64
for {
@ -17,6 +23,15 @@ func heat() {
}
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.Add(1)
for i := 0; i < runtime.NumCPU(); i++ {
@ -24,3 +39,14 @@ func main() {
}
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
}