diff options
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/cetus/apod.go | 13 | ||||
-rw-r--r-- | cmd/cetus/bpod.go | 13 | ||||
-rw-r--r-- | cmd/cetus/main.go | 9 |
3 files changed, 33 insertions, 2 deletions
diff --git a/cmd/cetus/apod.go b/cmd/cetus/apod.go index b99d899..cb5abae 100644 --- a/cmd/cetus/apod.go +++ b/cmd/cetus/apod.go @@ -7,6 +7,7 @@ import ( "framagit.org/andinus/cetus/pkg/apod" "framagit.org/andinus/cetus/pkg/background" + "framagit.org/andinus/indus/notification" ) func execAPOD() { @@ -77,6 +78,18 @@ func execAPOD() { apod.Print(res) } + // Send a desktop notification if notify flag was passed + if *apodNotify { + n := notification.Notif{} + n.Title = res.Title + n.Message = fmt.Sprintf("%s\n\n%s", + res.Date, + res.Explanation) + + err = n.Notify() + chkErr(err) + } + // Proceed only if the command was set because if it was fetch // then it's already finished & should exit now. if os.Args[1] == "fetch" { diff --git a/cmd/cetus/bpod.go b/cmd/cetus/bpod.go index f308d47..cf0a4bb 100644 --- a/cmd/cetus/bpod.go +++ b/cmd/cetus/bpod.go @@ -8,6 +8,7 @@ import ( "framagit.org/andinus/cetus/pkg/background" "framagit.org/andinus/cetus/pkg/bpod" + "framagit.org/andinus/indus/notification" ) func execBPOD() { @@ -107,6 +108,18 @@ func execBPOD() { bpod.Print(res) } + // Send a desktop notification if notify flag was passed + if *bpodNotify { + n := notification.Notif{} + n.Title = res.Title + n.Message = fmt.Sprintf("%s\n\n%s", + res.StartDate, + res.Copyright) + + err = n.Notify() + chkErr(err) + } + // Proceed only if the command was set because if it was fetch // then it's already finished & should exit now. if os.Args[1] == "fetch" { diff --git a/cmd/cetus/main.go b/cmd/cetus/main.go index b039f7a..0ff6b44 100644 --- a/cmd/cetus/main.go +++ b/cmd/cetus/main.go @@ -22,6 +22,9 @@ var ( bpodPathOnly *bool bpodQuiet *bool bpodDump *bool + + apodNotify *bool + bpodNotify *bool ) func main() { @@ -52,6 +55,8 @@ func main() { rand.Seed(time.Now().Unix()) apodCmd := flag.NewFlagSet("apod", flag.ExitOnError) + bpodCmd := flag.NewFlagSet("bpod", flag.ExitOnError) + defDate := time.Now().UTC().Format("2006-01-02") // Flags to parse for apod service. @@ -62,8 +67,7 @@ func main() { apodPathOnly = apodCmd.Bool("path-only", false, "Print only the path") apodQuiet = apodCmd.Bool("quiet", false, "Stay quiet") apodDump = apodCmd.Bool("dump", false, "Dump received response") - - bpodCmd := flag.NewFlagSet("bpod", flag.ExitOnError) + apodNotify = apodCmd.Bool("notify", false, "Send a desktop notification with background information") // Flags to parse for bpod service. bpodAPI = bpodCmd.String("api", "https://www.bing.com/HPImageArchive.aspx", "BPOD API") @@ -71,6 +75,7 @@ func main() { bpodPathOnly = bpodCmd.Bool("path-only", false, "Print only the path") bpodQuiet = bpodCmd.Bool("quiet", false, "Stay quiet") bpodDump = bpodCmd.Bool("dump", false, "Dump received response") + bpodNotify = bpodCmd.Bool("notify", false, "Send a desktop notification with background information") // Switching on commands will cause more repetition than // switching on service. If we switch on commands then switch |