-
Notifications
You must be signed in to change notification settings - Fork 16
/
main.go
84 lines (71 loc) · 2.05 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
77
78
79
80
81
82
83
84
package main
import (
"time"
shell "github.com/brianstrauch/cobra-shell"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"spotify/internal/back"
"spotify/internal/login"
"spotify/internal/next"
"spotify/internal/p"
"spotify/internal/pause"
"spotify/internal/play"
"spotify/internal/playlist"
"spotify/internal/queue"
"spotify/internal/repeat"
"spotify/internal/save"
"spotify/internal/shuffle"
"spotify/internal/status"
"spotify/internal/unsave"
"spotify/internal/update"
)
// version is a linker flag set by goreleaser
var version = "0.0.0"
func main() {
// TODO: https://github.com/spf13/viper/pull/1064
viper.AddConfigPath("$HOME")
viper.SetConfigName(".spotify-cli")
viper.SetConfigType("json")
_ = viper.SafeWriteConfig()
_ = viper.ReadInConfig()
root := &cobra.Command{
Use: "spotify",
Short: "Spotify for the terminal 🎵",
Version: version,
PersistentPreRunE: promptUpdate,
}
root.AddCommand(back.NewCommand())
root.AddCommand(login.NewCommand())
root.AddCommand(next.NewCommand())
root.AddCommand(p.NewCommand())
root.AddCommand(pause.NewCommand())
root.AddCommand(play.NewCommand())
root.AddCommand(playlist.NewCommand())
root.AddCommand(queue.NewCommand())
root.AddCommand(repeat.NewCommand())
root.AddCommand(save.NewCommand())
root.AddCommand(shell.New(root))
root.AddCommand(shuffle.NewCommand())
root.AddCommand(status.NewCommand())
root.AddCommand(unsave.NewCommand())
root.AddCommand(update.NewCommand())
root.SetHelpCommand(&cobra.Command{Hidden: true})
root.SetVersionTemplate("v{{.Version}}\n")
_ = root.Execute()
}
func promptUpdate(cmd *cobra.Command, _ []string) error {
if time.Now().Unix() < viper.GetInt64("prompt_update_timer") {
return nil
}
isUpdated, err := update.IsUpdated(cmd)
if err != nil {
return err
}
if !isUpdated {
cmd.Println("Use 'spotify update' to get the latest version.")
}
// Wait one day before the next prompt
const day int64 = 24 * 60 * 60
viper.Set("prompt_update_timer", time.Now().Unix()+day)
return viper.WriteConfig()
}