-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
60 lines (50 loc) · 1.09 KB
/
main.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
60
package main
import (
"flag"
"fmt"
"runtime"
)
var (
Version = "0.0.0"
CommitSha = "xxxx"
BuildTime = "0000-00-00T00:00:00+00:00"
)
func main() {
var (
all bool
help bool
ignore int
getVersion bool
noOfCpus int
)
flag.BoolVar(&all, "all", true, "print the number of installed processors")
flag.BoolVar(&help, "help", false, "display help and exit")
flag.BoolVar(&getVersion, "version", false, "get version")
flag.IntVar(&ignore, "ignore", 0, "if possible, exclude N processing units")
flag.Parse()
if getVersion {
fmt.Printf(`go-nproc v%s / sha: %s / BuildTime: %s
Made by DaftCreations, Opensource org For People/Creator, By People/Creator.
https://github.com/daftcreations
`,
Version, CommitSha, BuildTime)
return
}
if help {
fmt.Println("go-nproc Usage")
flag.PrintDefaults()
return
}
noOfCpus = runtime.NumCPU()
if ignore > 0 {
if ignore >= noOfCpus {
fmt.Println(1)
} else {
fmt.Println(noOfCpus - ignore)
}
} else if ignore < 0 {
fmt.Printf("go-nproc: invalid number: '%v'", ignore)
} else {
fmt.Println(noOfCpus)
}
}