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

@@ -7,20 +7,16 @@ package cmd
import (
"fmt"
"git.bullercodeworks.com/brian/gime/cli"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
// toggleCmd represents the toggle command
var toggleCmd = &cobra.Command{
Use: "toggle",
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: opToggle,
Short: "Toggle the most recent timer on and off",
RunE: opToggle,
}
func init() {
@@ -28,6 +24,37 @@ func init() {
}
func opToggle(cmd *cobra.Command, args []string) error {
fmt.Println("toggle 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
}
wrk, err := p.GetMostRecentTimer()
if err != nil {
fmt.Print("{\"icon\":\"time\",\"state\":\"Critical\", \"text\": \"Error loading timer entry\"}")
return nil
}
var startArgs []string
if wrk.Finished {
// Start a new timer with the same data
for _, v := range wrk.Contexts {
startArgs = append(startArgs, "@"+v)
}
for _, v := range wrk.Projects {
startArgs = append(startArgs, "+"+v)
}
if viper.GetBool("copytags") {
for k, v := range wrk.AdditionalTags {
startArgs = append(startArgs, k+":"+v)
}
}
return opStart(cmd, startArgs)
} else {
// Stop the active timer
return opStop(cmd, []string{})
}
}