Dev a few more operations
* Archive * Config * Pull out filter generation (from list) for reuse
This commit is contained in:
77
cmd/list.go
77
cmd/list.go
@@ -6,7 +6,6 @@ package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"git.bullercodeworks.com/brian/gime/cli"
|
||||
@@ -26,12 +25,6 @@ var listCmd = &cobra.Command{
|
||||
func init() {
|
||||
rootCmd.AddCommand(listCmd)
|
||||
|
||||
// Here you will define your flags and configuration settings.
|
||||
|
||||
// Cobra supports Persistent Flags which will work for this command
|
||||
// and all subcommands, e.g.:
|
||||
// listCmd.PersistentFlags().String("foo", "", "A help for foo")
|
||||
|
||||
// Local Flags
|
||||
listCmd.Flags().BoolP("all", "a", false, "Include done.txt timers")
|
||||
listCmd.Flags().BoolP("done", "d", false, "Only done.txt timers")
|
||||
@@ -68,75 +61,19 @@ func opListTimers(cmd *cobra.Command, args []string) error {
|
||||
return err
|
||||
}
|
||||
}
|
||||
start := time.Time{}
|
||||
end := time.Now()
|
||||
var contextFilters []string
|
||||
var projectFilters []string
|
||||
|
||||
var allFilters []func(timertxt.Timer) bool
|
||||
|
||||
if len(args) > 0 {
|
||||
contextFilters, args = util.GetContextsFromSlice(args)
|
||||
projectFilters, args = util.GetProjectsFromSlice(args)
|
||||
}
|
||||
if len(args) > 0 {
|
||||
if start, err = util.ParseFuzzyTime(args[0]); err != nil {
|
||||
y, m, d := time.Now().Date()
|
||||
start = time.Date(y, m, d, 0, 0, 0, 0, time.Now().Location())
|
||||
} else {
|
||||
args = args[1:]
|
||||
}
|
||||
if len(args) > 0 {
|
||||
if end, err = util.ParseFuzzyTime(args[0]); err != nil {
|
||||
y, m, d := time.Now().Date()
|
||||
end = time.Date(y, m, d, 23, 59, 59, 0, time.Now().Location())
|
||||
} else {
|
||||
args = args[1:]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
list := timertxt.NewTimerList()
|
||||
if !onlyArchive {
|
||||
list = p.TimerList.GetTimersInRange(start, end)
|
||||
list = p.TimerList
|
||||
if includeArchive {
|
||||
*list = append(*list, (*p.DoneList.GetTimersInRange(start, end))...)
|
||||
for _, tmr := range p.DoneList.GetTimerSlice() {
|
||||
list.AddTimer(tmr)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
list = p.DoneList.GetTimersInRange(start, end)
|
||||
list = p.DoneList
|
||||
}
|
||||
if len(contextFilters) > 0 {
|
||||
allFilters = append(allFilters, func(t timertxt.Timer) bool {
|
||||
for _, v := range contextFilters {
|
||||
v = strings.TrimPrefix(v, "@")
|
||||
if !t.HasContext(v) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
})
|
||||
}
|
||||
if len(projectFilters) > 0 {
|
||||
allFilters = append(allFilters, func(t timertxt.Timer) bool {
|
||||
for _, v := range projectFilters {
|
||||
v = strings.TrimPrefix(v, "+")
|
||||
if !t.HasProject(v) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
})
|
||||
}
|
||||
doFilters := func(t *timertxt.Timer) bool {
|
||||
for _, v := range allFilters {
|
||||
if !v(*t) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
// If we made it all the way down here, it matches
|
||||
return true
|
||||
}
|
||||
list = list.Filter(doFilters)
|
||||
filter := util.BuildFilterFromArgs(args)
|
||||
list = list.Filter(filter)
|
||||
|
||||
dayTotals := make(map[string]time.Duration)
|
||||
for _, v := range *list {
|
||||
|
||||
Reference in New Issue
Block a user