Archive by context/project
This commit is contained in:
parent
b0d4cfe017
commit
cc75725d66
65
timer_ops.go
65
timer_ops.go
@ -239,19 +239,60 @@ func (a *AppState) opArchiveTimer(args []string) int {
|
|||||||
var id int
|
var id int
|
||||||
var timer *timertxt.Timer
|
var timer *timertxt.Timer
|
||||||
var err error
|
var err error
|
||||||
if id, err = strconv.Atoi(v); err != nil {
|
if strings.HasPrefix(v, "@") {
|
||||||
fmt.Printf("Invalid id given: %s\n", v)
|
// We're archiving by context
|
||||||
return 1
|
v = strings.TrimPrefix(v, "@")
|
||||||
|
fmt.Println("Archiving by context:", v)
|
||||||
|
timers := a.TimerList.GetTimersWithContext(v)
|
||||||
|
fmt.Println("Found timers: ", len(*timers))
|
||||||
|
for _, tmr := range *timers {
|
||||||
|
if tmr.Finished {
|
||||||
|
if err = a.archiveTimer(tmr.Id); err != nil {
|
||||||
|
fmt.Printf("Error archiving timer %d\n", tmr.Id)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
fmt.Println(a.getDoneTimerString(tmr))
|
||||||
|
} else {
|
||||||
|
fmt.Println("Refusing to archive running timer:", tmr.Id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if strings.HasPrefix(v, "+") {
|
||||||
|
// We're archiving by projcet
|
||||||
|
v = strings.TrimPrefix(v, "+")
|
||||||
|
fmt.Println("Archiving by project:", v)
|
||||||
|
timers := a.TimerList.GetTimersWithProject(v)
|
||||||
|
fmt.Println("Found timers: ", len(*timers))
|
||||||
|
for _, tmr := range *timers {
|
||||||
|
if tmr.Finished {
|
||||||
|
if err = a.archiveTimer(tmr.Id); err != nil {
|
||||||
|
fmt.Printf("Error archiving timer %d\n", tmr.Id)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
fmt.Println(a.getDoneTimerString(tmr))
|
||||||
|
} else {
|
||||||
|
fmt.Println("Refusing to archive running timer:", tmr.Id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// I guess we're archiving by timer id
|
||||||
|
if id, err = strconv.Atoi(v); err != nil {
|
||||||
|
fmt.Printf("Invalid id given: %s\n", v)
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
if timer, err = a.TimerList.GetTimer(id); err != nil {
|
||||||
|
fmt.Printf("Error getting timer %d\n", id)
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
if timer.Finished {
|
||||||
|
if err = a.archiveTimer(id); err != nil {
|
||||||
|
fmt.Printf("Error archiving timer %d\n", id)
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
fmt.Println(a.getDoneTimerString(*timer))
|
||||||
|
} else {
|
||||||
|
fmt.Println("Refusing to archive running timer:", timer.Id)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if timer, err = a.TimerList.GetTimer(id); err != nil {
|
|
||||||
fmt.Printf("Error getting timer %d\n", id)
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
if err = a.archiveTimer(id); err != nil {
|
|
||||||
fmt.Printf("Error archiving timer %d\n", id)
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
fmt.Println(a.getDoneTimerString(*timer))
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for _, v := range *a.TimerList {
|
for _, v := range *a.TimerList {
|
||||||
|
Loading…
Reference in New Issue
Block a user