I believe that all functionality is implemented
This commit is contained in:
51
cmd/start.go
51
cmd/start.go
@@ -6,21 +6,19 @@ package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"git.bullercodeworks.com/brian/gime/cli"
|
||||
"git.bullercodeworks.com/brian/gime/util"
|
||||
"git.bullercodeworks.com/brian/go-timertxt"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
// startCmd represents the start command
|
||||
var startCmd = &cobra.Command{
|
||||
Use: "start",
|
||||
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: opStart,
|
||||
Short: "Start a timer",
|
||||
RunE: opStart,
|
||||
}
|
||||
|
||||
func init() {
|
||||
@@ -28,6 +26,41 @@ func init() {
|
||||
}
|
||||
|
||||
func opStart(cmd *cobra.Command, args []string) error {
|
||||
fmt.Println("start called")
|
||||
var err error
|
||||
p := cli.Program{}
|
||||
err = p.Initialize()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err = p.LoadTimerList(); err != nil {
|
||||
return err
|
||||
}
|
||||
var contexts, projects, strTags []string
|
||||
t := timertxt.NewTimer()
|
||||
if len(args) > 0 {
|
||||
if start, err := util.ParseFuzzyTime(args[0]); err == nil {
|
||||
t.StartDate = start
|
||||
args = args[1:]
|
||||
}
|
||||
}
|
||||
contexts, args = util.GetContextsFromSlice(args)
|
||||
projects, args = util.GetProjectsFromSlice(args)
|
||||
strTags, args = util.GetAdditionalTagsFromSlice(args)
|
||||
for _, v := range contexts {
|
||||
t.Contexts = append(t.Contexts, strings.TrimPrefix(v, "@"))
|
||||
}
|
||||
for _, v := range projects {
|
||||
t.Projects = append(t.Projects, strings.TrimPrefix(v, "+"))
|
||||
}
|
||||
for _, v := range strTags {
|
||||
tgPts := strings.Split(v, ":")
|
||||
t.AdditionalTags[tgPts[0]] = tgPts[1]
|
||||
}
|
||||
|
||||
p.TimerList.AddTimer(t)
|
||||
if err := p.WriteTimerList(); err != nil {
|
||||
return fmt.Errorf("Error writing timer list: %w", err)
|
||||
}
|
||||
fmt.Println("Started: ", util.TimerToString(t))
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user