I believe that all functionality is implemented
This commit is contained in:
@@ -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{})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user