I believe that all functionality is implemented

This commit is contained in:
2022-01-21 08:40:44 -06:00
parent 54c91f0d3c
commit 45d13e7052
12 changed files with 333 additions and 72 deletions

View File

@@ -6,21 +6,19 @@ package cmd
import (
"fmt"
"time"
"git.bullercodeworks.com/brian/gime/cli"
"git.bullercodeworks.com/brian/gime/util"
"git.bullercodeworks.com/brian/go-timertxt"
"github.com/spf13/cobra"
)
// switchCmd represents the switch command
var switchCmd = &cobra.Command{
Use: "switch",
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: opSwitch,
Short: "Stop the current timer and start a new one copying the last one's parameters",
RunE: opSwitch,
}
func init() {
@@ -28,6 +26,31 @@ func init() {
}
func opSwitch(cmd *cobra.Command, args []string) error {
fmt.Println("switch called")
return nil
var err error
p := cli.Program{}
err = p.Initialize()
if err != nil {
return err
}
if err = p.LoadTimerList(); err != nil {
return err
}
var timerIds []int
end := time.Now()
// Stop all running timers and start a new one with the given args
for _, v := range *p.TimerList.GetActiveTimers() {
timerIds = append(timerIds, v.Id)
}
fmt.Print("Stopping ", timerIds, "\n")
for _, v := range timerIds {
var stopped *timertxt.Timer
if stopped, err = p.TimerList.GetTimer(v); err != nil {
fmt.Println(err.Error())
continue
}
stopped.FinishDate = end
stopped.Finished = true
fmt.Println("Stopped Timer:", util.TimerToFriendlyString(stopped))
}
return opStart(cmd, args)
}