Add 'Add' Function
This commit is contained in:
parent
acc6d135e5
commit
0e7eea999f
11
main.go
11
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",
|
||||
}
|
||||
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user