-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
69 lines (57 loc) · 1.2 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
package main
import (
"fmt"
"os"
"os/exec"
"strings"
"time"
"github.com/gen2brain/beeep"
"github.com/olebedev/when"
"github.com/olebedev/when/rules/common"
"github.com/olebedev/when/rules/en"
)
const (
markName = "GOLANG_CLI_REMINDER"
markValue = "1"
)
func main() {
if len(os.Args) < 3 {
fmt.Printf("Usage: %s <hh:mm> <text message\n>", os.Args[0])
os.Exit(1)
}
now := time.Now()
w := when.New(nil)
w.Add(en.All...)
w.Add(common.All...)
t, err := w.Parse(os.Args[1], now)
if err != nil {
fmt.Println(err)
os.Exit(2)
}
if t == nil {
fmt.Println("Unable to parse time!")
os.Exit(3)
}
if now.After(t.Time) {
fmt.Println("Set a future time!")
os.Exit(4)
}
diff := t.Time.Sub(now)
if os.Getenv(markName) == markValue {
time.Sleep(diff)
err = beeep.Alert("Reminder", strings.Join(os.Args[2:], " "), "assets/information.png")
if err != nil {
fmt.Println(err)
os.Exit(5)
}
} else {
cmd := exec.Command(os.Args[0], os.Args[1:]...)
cmd.Env = append(os.Environ(), fmt.Sprintf("%s=%s", markName, markValue))
if err := cmd.Start(); err != nil {
fmt.Println(err)
os.Exit(5)
}
fmt.Println("Reminder will be displayed", diff.Round(time.Second))
os.Exit(0)
}
}