diff --git a/main.go b/main.go index 5c16277..bd08978 100644 --- a/main.go +++ b/main.go @@ -33,7 +33,6 @@ func main() { if len(os.Args) > 1 { parms = os.Args[1:] - parms[0] = matchParameter(parms[0]) } else { // If no parameters were passed, just print the status parms = append(parms, "status") @@ -204,6 +203,12 @@ func initialize() { validOperations = make(map[string][]string) opFuncs = make(map[string]func([]string) int) + opFuncs["add"] = cmdAddTimer + validOperations["add"] = []string{ + "add [duration] [+tags] - Add a timer for the given duration", + " with the given tags", + } + opFuncs["cont"] = cmdContinueTimer validOperations["cont"] = []string{ "cont [time] - Continue the last stopped timer", @@ -269,7 +274,7 @@ func initialize() { opFuncs["start"] = cmdStartTimer validOperations["start"] = []string{ - "start [time] [tags ...] - Start a timer with the given tags (space separated)", + "start [time] [+tags] - Start a timer with the given tags (space separated)", " If the first sub-argument given looks like a time,", " the timer will be started then (past or future).", " If a timer is already running it'll be stopped", @@ -284,7 +289,7 @@ func initialize() { opFuncs["switch"] = cmdSwitchTimer validOperations["switch"] = []string{ - "switch [tags ...] - Stop all currently running timers and start a new", + "switch [+tags] - Stop all currently running timers and start a new", " one with the given tags", } diff --git a/timer_operations.go b/timer_operations.go index e730796..58c59e1 100644 --- a/timer_operations.go +++ b/timer_operations.go @@ -42,6 +42,54 @@ func cmdStartTimer(args []string) int { return 0 } +func cmdAddTimer(args []string) int { + var err error + var entry *gime.TimeEntry + // By default we start the timer now + tags, rem := pullTagsFromArgs(args) + var beg, end time.Time + for _, opt := range rem { + var tmpBeg, tmpEnd time.Time + if strings.Contains(opt, "-") { + pts := strings.Split(opt, "-") + if len(pts[0]) > 0 { + // This should be the starting date + tmpBeg, err = parseFuzzyTime(pts[0]) + if err != nil { + continue + } + } + if len(pts[1]) > 0 { + // This should be the ending date + tmpEnd, err = parseFuzzyTime(pts[1]) + if err != nil { + continue + } + } + } + if !tmpBeg.IsZero() || !tmpEnd.IsZero() { + beg, end = tmpBeg, tmpEnd + } + } + if end.IsZero() { + end = time.Now() + } + tc := new(gime.TagCollection) + for i := range tags { + tc.Push(tags[i]) + } + if entry, err = gime.CreateTimeEntry(beg, end, tc); err != nil { + fmt.Println(err) + return 1 + } + if err = gdb.SaveTimeEntry(entry); err != nil { + fmt.Println(err) + return 1 + } + fmt.Println("Added Time Entry:", TimerToString(entry)) + return 0 +} + func cmdContinueTimer(args []string) int { // Get the last running timer and start a new one with the same tags te, err := getMostRecentTimeEntry()