Skip to content

Commit

Permalink
Implement tracker commands
Browse files Browse the repository at this point in the history
  • Loading branch information
Ulrich Lissé committed Apr 5, 2019
1 parent 50749cd commit 7233dba
Showing 1 changed file with 53 additions and 20 deletions.
73 changes: 53 additions & 20 deletions cmd/tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package cmd

import (
"errors"
"fmt"
"github.com/cheynewallace/tabby"
"github.com/leanovate/mite-go/date"
"github.com/leanovate/mite-go/mite"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -31,7 +31,19 @@ var trackerStatusCommand = &cobra.Command{
Use: "status",
Short: "shows the status of the time tracker",
RunE: func(cmd *cobra.Command, args []string) (err error) {
panic("implement trackerStatusCommand")
tracking, err := deps.miteApi.Tracker()
if err != nil {
return err
}
if tracking == nil {
return nil
}

t := tabby.New()
t.AddHeader("id", "time", "state", "since")
t.AddLine(tracking.Id, tracking.Duration, "tracking", tracking.Since)
t.Print()

return nil
},
}
Expand All @@ -46,8 +58,45 @@ var trackerStartCommand = &cobra.Command{
return err
}
}
fmt.Printf("passed id: %s\n", trackerTimeEntryId)
panic("implement trackerStartCommand")

tracking, stopped, err := deps.miteApi.StartTracker(trackerTimeEntryId)
if err != nil {
return err
}

t := tabby.New()
t.AddHeader("id", "time", "state", "since")
t.AddLine(tracking.Id, tracking.Duration, "tracking", tracking.Since)
if stopped != nil {
t.AddLine(stopped.Id, stopped.Duration, "stopped")
}
t.Print()

return nil
},
}

var trackerStopCommand = &cobra.Command{
Use: "stop",
Short: "stops the time tracker for a time entry",
RunE: func(cmd *cobra.Command, args []string) (err error) {
if trackerTimeEntryId == "" {
trackerTimeEntryId, err = fetchLatestTimeEntryForToday()
if err != nil {
return err
}
}

stopped, err := deps.miteApi.StopTracker(trackerTimeEntryId)
if err != nil {
return err
}

t := tabby.New()
t.AddHeader("id", "time", "state")
t.AddLine(stopped.Id, stopped.Duration, "stopped")
t.Print()

return nil
},
}
Expand All @@ -70,19 +119,3 @@ func fetchLatestTimeEntryForToday() (string, error) {

return entries[0].Id, nil
}

var trackerStopCommand = &cobra.Command{
Use: "stop",
Short: "stops the time tracker for a time entry",
RunE: func(cmd *cobra.Command, args []string) (err error) {
if trackerTimeEntryId == "" {
trackerTimeEntryId, err = fetchLatestTimeEntryForToday()
if err != nil {
return err
}
}
fmt.Printf("passed id: %s\n", trackerTimeEntryId)
panic("implement trackerStopCommand")
return nil
},
}

0 comments on commit 7233dba

Please sign in to comment.