Skip to content

Commit

Permalink
Default timetrace list records to the current date
Browse files Browse the repository at this point in the history
  • Loading branch information
aligator committed Jun 13, 2021
1 parent e4cbb0c commit 196087c
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions cli/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cli
import (
"strconv"
"strings"
"time"

"github.com/dominikbraun/timetrace/core"
"github.com/dominikbraun/timetrace/out"
Expand Down Expand Up @@ -62,12 +63,18 @@ func listRecordsCommand(t *core.Timetrace) *cobra.Command {
listRecords := &cobra.Command{
Use: "records {<YYYY-MM-DD>|today|yesterday}",
Short: "List all records from a date",
Args: cobra.ExactArgs(1),
Args: cobra.MaximumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
date, err := t.Formatter().ParseDate(args[0])
if err != nil {
out.Err("failed to parse date: %s", err.Error())
return
var date time.Time
if len(args) == 0 {
date = time.Now()
} else {
var err error
date, err = t.Formatter().ParseDate(args[0])
if err != nil {
out.Err("failed to parse date: %s", err.Error())
return
}
}

records, err := t.ListRecords(date)
Expand Down

0 comments on commit 196087c

Please sign in to comment.