I believe that all functionality is implemented
This commit is contained in:
58
cmd/stop.go
58
cmd/stop.go
@@ -6,21 +6,20 @@ package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"git.bullercodeworks.com/brian/gime/cli"
|
||||
"git.bullercodeworks.com/brian/gime/util"
|
||||
"git.bullercodeworks.com/brian/go-timertxt"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
// stopCmd represents the stop command
|
||||
var stopCmd = &cobra.Command{
|
||||
Use: "stop",
|
||||
Short: "A brief description of your command",
|
||||
Long: `A longer description that spans multiple lines and likely contains examples
|
||||
and usage of using your command. For example:
|
||||
|
||||
Cobra is a CLI library for Go that empowers applications.
|
||||
This application is a tool to generate the needed files
|
||||
to quickly create a Cobra application.`,
|
||||
RunE: opStop,
|
||||
Short: "Stop a timer",
|
||||
RunE: opStop,
|
||||
}
|
||||
|
||||
func init() {
|
||||
@@ -28,6 +27,47 @@ func init() {
|
||||
}
|
||||
|
||||
func opStop(cmd *cobra.Command, args []string) error {
|
||||
fmt.Println("stop called")
|
||||
var err error
|
||||
p := cli.Program{}
|
||||
err = p.Initialize()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err = p.LoadTimerList(); err != nil {
|
||||
return err
|
||||
}
|
||||
var wrk time.Time
|
||||
end := time.Now()
|
||||
id := -1
|
||||
|
||||
if len(args) > 0 {
|
||||
if wrk, err = util.ParseFuzzyTime(args[0]); err != nil {
|
||||
id, err = strconv.Atoi(args[0])
|
||||
} else {
|
||||
end = wrk
|
||||
args = args[1:]
|
||||
}
|
||||
}
|
||||
fmt.Println("Stopping at : " + end.Format(time.RFC3339))
|
||||
var timerIds []int
|
||||
if id == -1 {
|
||||
for _, v := range *p.TimerList.GetActiveTimers() {
|
||||
timerIds = append(timerIds, v.Id)
|
||||
}
|
||||
} else {
|
||||
timerIds = append(timerIds, id)
|
||||
}
|
||||
for _, v := range timerIds {
|
||||
var stopped *timertxt.Timer
|
||||
if stopped, err = p.TimerList.GetTimer(v); err != nil {
|
||||
fmt.Println(err.Error())
|
||||
}
|
||||
stopped.FinishDate = end
|
||||
stopped.Finished = true
|
||||
fmt.Println("Stopped Timer:", util.TimerToFriendlyString(stopped))
|
||||
}
|
||||
if err = p.WriteTimerList(); err != nil {
|
||||
return fmt.Errorf("Error writing timer list: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user