From 28d31100a0175d404a1edea134944cf1cc74c7d5 Mon Sep 17 00:00:00 2001 From: Andrew Red Date: Wed, 20 Oct 2021 01:00:02 +0300 Subject: [PATCH] - added new config period.timeframe, period.every --- README.md | 6 ++++++ config.yaml.example | 4 ++++ main.go | 22 +++++++++++++++++----- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index a8b83bb..53cd71e 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,10 @@ tracker: - type: toggl token: "token-from-toggl" +period: + timeframe: 2w + every: 1d + # places to sync time entries with sync: - type: jira @@ -40,6 +44,8 @@ sync: - DEV ``` +- `timeframe` - look for timeframe in the past for new entries +- `every` - for `--service` mode, how often to repeat sync - `projects` it's a list of project keys in Jira. ## Run the app diff --git a/config.yaml.example b/config.yaml.example index 70be071..404ba71 100644 --- a/config.yaml.example +++ b/config.yaml.example @@ -2,6 +2,10 @@ tracker: - type: toggl token: "token-from-toggl" +period: + timeframe: 2w + every: 1d + # places to sync time entries with sync: - type: jira diff --git a/main.go b/main.go index a17526b..262545e 100644 --- a/main.go +++ b/main.go @@ -49,8 +49,7 @@ func main() { Usage: "Sync time entries from timers with task trackers", Flags: []cli.Flag{ cli.StringFlag{ - Name: "period", - Value: "1d", + Name: "period", }, cli.BoolFlag{ Name: "service", @@ -58,13 +57,26 @@ func main() { }, Action: func(c *cli.Context) error { service := c.Bool("service") - duration, err := utils.ParseDuration(c.String("period")) + t := viper.GetString("period.timeframe") + p := c.String("period") + if p != "" { + t = p + } + lookupTimeframe, err := utils.ParseDuration(t) + if err != nil { + log.Fatal(err) + } + e := viper.GetString("period.every") + if e == "" { + e = t + } + every, err := utils.ParseDuration(e) if err != nil { log.Fatal(err) } end := time.Now() - start := end.Add(-duration) + start := end.Add(-lookupTimeframe) tr := viper.Get("tracker").([]interface{}) trackerSvc, err := trackers.NewTogglTracker((tr[0]).(map[interface{}]interface{})) @@ -84,7 +96,7 @@ func main() { log.Fatal(err) } if service { - ticker := time.NewTicker(duration) + ticker := time.NewTicker(every) quit := make(chan error, 1) go func() { for {