Implemented tracking command

This commit is contained in:
マリウス 2020-10-15 21:56:13 +01:00
parent ce8d2766ff
commit 5ab14a2467
No known key found for this signature in database
GPG key ID: C228EF0A530AF06F
2 changed files with 53 additions and 0 deletions

View file

@ -25,6 +25,12 @@ Example:
zeit track --project project --task task --begin -0:15
```
### Check currently tracking
```
zeit tracking
```
### Finish tracking
```

47
z/tracking.go Normal file
View file

@ -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)
}
}