-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathmain.go
76 lines (63 loc) · 1.65 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package main
import (
"log"
"os"
"runtime"
cli "github.com/urfave/cli/v2"
)
// EINVAL Error Code: #define EINVAL 22 /* Invalid argument */
const EINVAL = 23
const maxInt32 = 2147483647
const unLimitedTime = maxInt32
const missPercentageVal = 0
func main() {
var coresCount int
var timeSeconds int
var percentage int
app := cli.NewApp()
// app.Version = "0.0.2"
app.Flags = []cli.Flag{
&cli.IntFlag{
Name: "coresCount",
Aliases: []string{"c"},
Value: runtime.NumCPU(),
Usage: "how many cores",
Destination: &coresCount,
},
&cli.IntFlag{
Name: "timeSeconds",
Aliases: []string{"t"},
Value: unLimitedTime,
Usage: "how long",
Destination: &timeSeconds,
},
&cli.IntFlag{
Name: "percentage",
Aliases: []string{"p"},
Value: missPercentageVal,
Usage: "percentage of each specify cores",
Destination: &percentage,
},
}
app.Action = func(c *cli.Context) error {
// fmt.Println("coresCount: ", coresCount)
// fmt.Println("timeSeconds: ", timeSeconds)
// fmt.Println("percentage: ", percentage)
// fmt.Println("------")
if coresCount < 1 || coresCount > runtime.NumCPU() {
return cli.NewExitError("coresCount not correct must between 1 - `max CPU cores`", EINVAL)
}
if timeSeconds <= 0 {
return cli.NewExitError("timeSeconds not correct must be positive int", EINVAL)
}
if percentage <= 0 || percentage > 100 {
return cli.NewExitError("percentage must between 1 - 100", EINVAL)
}
RunCPULoad(coresCount, timeSeconds, percentage)
return nil
}
err := app.Run(os.Args)
if err != nil {
log.Fatal(err)
}
}