diff --git a/go.mod b/go.mod index 678d6d0..9a5c822 100644 --- a/go.mod +++ b/go.mod @@ -8,6 +8,7 @@ require ( github.com/charmbracelet/bubbles v0.18.0 github.com/charmbracelet/bubbletea v0.25.0 github.com/charmbracelet/lipgloss v0.9.1 + github.com/karrick/tparse v2.4.2+incompatible github.com/yuin/gopher-lua v1.1.1 ) diff --git a/go.sum b/go.sum index 778902e..37b9f88 100644 --- a/go.sum +++ b/go.sum @@ -26,6 +26,8 @@ github.com/go-fed/httpsig v1.1.0 h1:9M+hb0jkEICD8/cAiNqEB66R87tTINszBRTjwjQzWcI= github.com/go-fed/httpsig v1.1.0/go.mod h1:RCMrTZvN1bJYtofsG4rd5NaO5obxQ5xBkdiS7xsT7bM= github.com/hashicorp/go-version v1.6.0 h1:feTTfFNnjP967rlCxM/I9g701jU+RN74YKx2mOkIeek= github.com/hashicorp/go-version v1.6.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= +github.com/karrick/tparse v2.4.2+incompatible h1:+cW306qKAzrASC5XieHkgN7/vPaGKIuK62Q7nI7DIRc= +github.com/karrick/tparse v2.4.2+incompatible/go.mod h1:ASPA+vrIcN1uEW6BZg8vfWbzm69ODPSYZPU6qJyfdK0= github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY= github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0= github.com/mattn/go-isatty v0.0.18 h1:DOKFKCQ7FNG2L1rbrmstDN4QVRdS89Nkh85u68Uwp98= diff --git a/main.go b/main.go index 1572921..37af61d 100644 --- a/main.go +++ b/main.go @@ -12,6 +12,7 @@ import ( // Arguments is a place to store arguments / options / flags passed from the command line. type Arguments struct { Times struct { + since *string } Summary struct { } @@ -40,7 +41,11 @@ func main() { }) Times := parser.NewCommand("times", "Get a user's tracked times.") - Times.Flag("t", "today", &argparse.Options{}) + arguments.Times.since = Times.String("d", "since", &argparse.Options{ + Required: false, + Help: "Get all time logs since this time. Format: 3d / 1w / 2mo", + Default: "1w", + }) Summary := parser.NewCommand("summary", "Display a summary of a user's activity.") Feed := parser.NewCommand("feed", "Display the user's activity feed.") diff --git a/times.go b/times.go index 394a2cb..d829768 100644 --- a/times.go +++ b/times.go @@ -9,6 +9,7 @@ import ( "github.com/charmbracelet/bubbles/table" tea "github.com/charmbracelet/bubbletea" "github.com/charmbracelet/lipgloss" + "github.com/karrick/tparse" "code.gitea.io/sdk/gitea" ) @@ -26,7 +27,12 @@ func times() { } }() - since := time.Now().AddDate(0, -6, 0) + since, err := tparse.AddDuration(time.Now(), "-"+*arguments.Times.since) + if err != nil { + fmt.Printf("Failed to parse time string '%s'\n", *arguments.Times.since) + os.Exit(1) + } + times := getTimeLogs(since, func(repo gitea.Repository, took time.Duration) { p.Send(IndicatorInfo{ info: fmt.Sprintf("%s / %s", repo.Owner.UserName, repo.Name),