feat(times): Add since option (fix #4)

This commit is contained in:
Noah 2024-04-07 13:50:23 -05:00
parent e5b3edb460
commit c5b82d5dbe
4 changed files with 16 additions and 2 deletions

1
go.mod
View File

@ -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
)

2
go.sum
View File

@ -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=

View File

@ -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.")

View File

@ -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),