-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
60 lines (49 loc) · 1.22 KB
/
Copy pathmain.go
File metadata and controls
60 lines (49 loc) · 1.22 KB
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 (
"fmt"
"os"
"regexp"
"strconv"
"flag"
"github.com/aristidebm/pomodoro/internal/components"
tea "github.com/charmbracelet/bubbletea"
)
var durationParser = regexp.MustCompile(`(\d+)(d|h|m|s)?`)
var path = flag.String("path", "", "path to playlist (.mp3)")
var duration = flag.String("duration", "25m", "session duration, example: 1d|24h|1444m|86400")
var color = flag.String("color", "", "html colors to use, example: #FFFFFF")
func main() {
flag.Parse()
match := durationParser.FindStringSubmatch(*duration)
if len(match) < 2 {
fmt.Printf("Alas, there's been an error")
os.Exit(1)
}
d, err := strconv.Atoi(match[1])
if err != nil {
fmt.Printf("Alas, there's been an error: %v", err)
os.Exit(1)
}
if len(match) > 2 {
switch match[2] {
case "m":
d = d * 60
case "h":
d = d * 60 * 60
case "d":
d = d * 24 * 60 * 60
default:
//
}
}
app, err := components.NewApp(int64(d), components.WithPlayList(*path), components.WithColor(*color))
if err != nil {
fmt.Printf("Alas, there's been an error: %v", err)
os.Exit(1)
}
p := tea.NewProgram(app, tea.WithAltScreen())
if _, err := p.Run(); err != nil {
fmt.Printf("Alas, there's been an error: %v", err)
os.Exit(1)
}
}