'Modify' function that allows adding tags
This commit is contained in:
parent
90dfd0f245
commit
3ada0ba277
10
main.go
10
main.go
@ -262,6 +262,16 @@ func initialize() {
|
|||||||
"ls [duration] [+tags] - The same as list",
|
"ls [duration] [+tags] - The same as list",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
opFuncs["modify"] = cmdModifyTimer
|
||||||
|
validOperations["modify"] = []string{
|
||||||
|
"modify [+tags] - Modify a timer",
|
||||||
|
}
|
||||||
|
|
||||||
|
opFuncs["mod"] = cmdModifyTimer
|
||||||
|
validOperations["mod"] = []string{
|
||||||
|
"mod [+tags] - Modify a timer",
|
||||||
|
}
|
||||||
|
|
||||||
opFuncs["remove"] = cmdDeleteTimer
|
opFuncs["remove"] = cmdDeleteTimer
|
||||||
validOperations["remove"] = []string{
|
validOperations["remove"] = []string{
|
||||||
"remove @id - See 'delete'",
|
"remove @id - See 'delete'",
|
||||||
|
@ -90,6 +90,41 @@ func cmdAddTimer(args []string) int {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func cmdModifyTimer(args []string) int {
|
||||||
|
// If no timer id is specified, edit the most recent one
|
||||||
|
modId := "@0"
|
||||||
|
tags, rem := pullTagsFromArgs(args)
|
||||||
|
for i := range rem {
|
||||||
|
if rem[i][0] == '@' {
|
||||||
|
modId = rem[i]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
timerId, err := strconv.Atoi(modId[1:])
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("error parsing timer id:", err.Error())
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
tmr, _, err := findTimerById(timerId)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err.Error())
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
if len(tags) <= 0 {
|
||||||
|
fmt.Println("Modify only supports adding tags at this time.")
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
for i := range tags {
|
||||||
|
tmr.AddTag(tags[i])
|
||||||
|
}
|
||||||
|
if err = gdb.SaveTimeEntry(tmr); err != nil {
|
||||||
|
fmt.Println("Error saving modified timer:", err.Error())
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
fmt.Println("Modified Timer:")
|
||||||
|
fmt.Println(" ", TimerToString(tmr))
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
func cmdContinueTimer(args []string) int {
|
func cmdContinueTimer(args []string) int {
|
||||||
// Get the last running timer and start a new one with the same tags
|
// Get the last running timer and start a new one with the same tags
|
||||||
te, err := getMostRecentTimeEntry()
|
te, err := getMostRecentTimeEntry()
|
||||||
@ -217,8 +252,8 @@ func cmdPrintList(args []string) int {
|
|||||||
useDefaultFilter := true
|
useDefaultFilter := true
|
||||||
var showIds bool
|
var showIds bool
|
||||||
var beg, end time.Time
|
var beg, end time.Time
|
||||||
searchTags := []string{}
|
tags, rem := pullTagsFromArgs(args)
|
||||||
for _, opt := range args {
|
for _, opt := range rem {
|
||||||
var tmpBeg, tmpEnd time.Time
|
var tmpBeg, tmpEnd time.Time
|
||||||
// Check for command modifiers
|
// Check for command modifiers
|
||||||
if strings.HasPrefix(opt, ":") {
|
if strings.HasPrefix(opt, ":") {
|
||||||
@ -245,12 +280,6 @@ func cmdPrintList(args []string) int {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find tags
|
|
||||||
if strings.HasPrefix(opt, "+") {
|
|
||||||
searchTags = append(searchTags, opt[1:])
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
// Do our best to figure out what timers the user wants to list
|
// Do our best to figure out what timers the user wants to list
|
||||||
var err error
|
var err error
|
||||||
if strings.Contains(opt, "-") {
|
if strings.Contains(opt, "-") {
|
||||||
@ -288,8 +317,8 @@ func cmdPrintList(args []string) int {
|
|||||||
return t.GetStart().After(beg) && t.GetEnd().Before(end)
|
return t.GetStart().After(beg) && t.GetEnd().Before(end)
|
||||||
}
|
}
|
||||||
tagFilter := func(t *gime.TimeEntry) bool {
|
tagFilter := func(t *gime.TimeEntry) bool {
|
||||||
for i := range searchTags {
|
for i := range tags {
|
||||||
if !t.HasTag(searchTags[i]) {
|
if !t.HasTag(tags[i]) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user