-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
68 lines (59 loc) · 1.4 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
package main
import (
"fmt"
"log"
"os"
"time"
"github.com/urfave/cli"
)
const Version string = "1.0.0"
func main() {
daemon := NewDaemon()
app := cli.NewApp()
app.Version = Version
app.Name = "powerd"
app.Usage = "Simple daemon to handle battery power levels"
app.Action = func(c *cli.Context) error {
fmt.Println("Hello friend!")
return nil
}
app.Flags = []cli.Flag{
cli.IntFlag{
Name: "check-interval",
Value: 60,
Usage: "Sets the interval to check the battery level in seconds",
},
cli.IntFlag{
Name: "warn-on-level",
Value: 10,
Usage: "Sets the battery level which will trigger a warn message",
},
cli.StringFlag{
Name: "warn-message",
Value: "Battery level at 10%",
Usage: "Sets the warning message",
},
cli.IntFlag{
Name: "exec-on-level",
Value: 5,
Usage: "Sets the battery level which will trigger a command execution",
},
cli.StringFlag{
Name: "exec-command",
Value: "poweroff",
Usage: "Sets the exec command",
},
}
app.Action = func(c *cli.Context) {
daemon.config.checkInterval = time.Duration(c.Int("check-interval"))
daemon.config.execCommand = c.String("exec-command")
daemon.config.execOnLevel = c.Int("exec-on-level")
daemon.config.warnMessage = c.String("warn-message")
daemon.config.warnOnLevel = c.Int("warn-on-level")
daemon.Start()
}
err := app.Run(os.Args)
if err != nil {
log.Fatal(err)
}
}