From 5ab14a24678deb637e9dcaf0bf1eefece65d4a33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=83=9E=E3=83=AA=E3=82=A6=E3=82=B9?= Date: Thu, 15 Oct 2020 21:56:13 +0100 Subject: [PATCH] Implemented tracking command --- README.md | 6 ++++++ z/tracking.go | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 z/tracking.go diff --git a/README.md b/README.md index 89c64d8..75c4492 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,12 @@ Example: zeit track --project project --task task --begin -0:15 ``` +### Check currently tracking + +``` +zeit tracking +``` + ### Finish tracking ``` diff --git a/z/tracking.go b/z/tracking.go new file mode 100644 index 0000000..2e41a9d --- /dev/null +++ b/z/tracking.go @@ -0,0 +1,47 @@ +package z + +import ( + "os" + "fmt" + "github.com/spf13/cobra" +) + +var trackingCmd = &cobra.Command{ + Use: "tracking", + Short: "Currently tracking activity", + Long: "Show currently tracking activity.", + Run: func(cmd *cobra.Command, args []string) { + user := GetCurrentUser() + + runningEntryId, err := database.GetRunningEntryId(user) + if err != nil { + fmt.Printf("△ %+v\n", err) + os.Exit(1) + } + + if runningEntryId == "" { + fmt.Printf("□ not running\n") + os.Exit(1) + } + + runningEntry, err := database.GetEntry(user, runningEntryId) + if err != nil { + fmt.Printf("△ %+v\n", err) + os.Exit(1) + } + + fmt.Printf(runningEntry.GetOutputForTrack(true, true)) + return + }, +} + +func init() { + rootCmd.AddCommand(trackingCmd) + + var err error + database, err = InitDatabase() + if err != nil { + fmt.Printf("△ %+v\n", err) + os.Exit(1) + } +}