From ebb07300af6def0a8338d5e28c63a7496279aa72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Boros?= Date: Thu, 4 Nov 2021 22:34:53 +0100 Subject: [PATCH] fix: multiple small issues fix (#35) * fix: print dirty version if version is invalid When someone tries to build minutes without providing the necessary build flags, using version flag will result in an error. This commit resolves the issue by printing "dirty build" in these cases. * fix: ensure config file is not necessary The config file was necessary to use minutes, though it should not be. In fact, minutes should be able to run without any configuration file. * docs: add more generic source and target options * test: remove race condition detection Timewarrior tests has race conditions and that was introduced keeping this in mind. Since it was a conscious decision, it makes no sense to check for race conditions. Signed-off-by: Gabor Boros --- Makefile | 2 +- cmd/root.go | 22 ++++++++++++++++++---- www/docs/configuration.md | 6 +++--- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index a9a57ae..792ee2d 100644 --- a/Makefile +++ b/Makefile @@ -29,7 +29,7 @@ lint: format ## Run linters on the project gosec -quiet ./... test: deps ## Run tests - go test -race -cover -covermode=atomic -coverprofile .coverage.out ./... + go test -cover -covermode=atomic -coverprofile .coverage.out ./... bench: deps ## Run benchmarks # ^$ filters out every unit test, so only benchmarks will run diff --git a/cmd/root.go b/cmd/root.go index c9e135c..7dbff57 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -99,10 +99,12 @@ func initConfig() { viper.SetEnvPrefix(envPrefix) viper.AutomaticEnv() - if err := viper.ReadInConfig(); err == nil { - fmt.Println("Using config file:", viper.ConfigFileUsed(), configFile) + if err := viper.ReadInConfig(); err != nil { + if _, ok := err.(viper.ConfigFileNotFoundError); !ok { + cobra.CheckErr(err) + } } else { - cobra.CheckErr(err) + fmt.Println("Using config file:", viper.ConfigFileUsed(), configFile) } // Bind flags to config value @@ -174,6 +176,14 @@ func validateFlags() { source := viper.GetString("source") target := viper.GetString("target") + if source == "" { + cobra.CheckErr("sync source must be set") + } + + if target == "" { + cobra.CheckErr("sync target must be set") + } + if source == target { cobra.CheckErr("sync source cannot match the target") } @@ -347,7 +357,11 @@ func runRootCmd(_ *cobra.Command, _ []string) { var err error if viper.GetBool("version") { - fmt.Printf("%s version %s, commit %s (%s)\n", program, version, commit[:7], date) + if version == "" || len(commit) < 7 || date == "" { + fmt.Println("dirty build") + } else { + fmt.Printf("%s version %s, commit %s (%s)\n", program, version, commit[:7], date) + } os.Exit(0) } diff --git a/www/docs/configuration.md b/www/docs/configuration.md index 7f8cf5a..5b1d598 100644 --- a/www/docs/configuration.md +++ b/www/docs/configuration.md @@ -36,17 +36,17 @@ On Linux/Unix systems, the following locations are checked for the configuration | dry-run | bool | Fetch entries from source, print the fetched entries, but do not upload them | dry-run = true | | | end | string | Set the end date for fetching entries (must match the `date-format`) | end = "2021-10-01" | | | filter-client | string | Regex of the client name to filter for | filter-client = '^ACME Inc\.?(orporation)$' | | -| filter-project | string | Regex of the project name to filter for | filter-project = '.*(website).*' | | +| filter-project | string | Regex of the project name to filter for | filter-project = '._(website)._' | | | force-billed-duration | bool | Treat the total spent time as billable time | force-billed-duration = true | | | round-to-closest-minute | bool | Round time to closest minute, even if the closest minute is 0 (zero) | round-to-closest-minute = true | | -| source | string | Set the fetch source name | source = "tempo" | `clockify`, `tempo` | +| source | string | Set the fetch source name | source = "tempo" | Check the list of available sources | | source-user | string | Set the fetch source user ID | source-user = "gabor-boros" | | | start | string | Set the start date for fetching entries (must match the `date-format`) | start = "2021-10-01" | | | table-column-config | [[]table.ColumnConfig][column config documentation] | Customize columns based on the underlying column config struct[^1] | table-column-config = { summary = { widthmax = 40 } } | | | table-hide-column | []string | Hide the specified columns of the printed overview table | table-hide-column = ["start", "end"] | `summary`, `project`, `client`, `start`, `end` | | table-sort-by | []string | Sort the specified rows of the printed table by the given column; each sort option can have a `-` (hyphen) prefix to indicate descending sort | table-sort-by = ["start", "task"] | `task`, `summary`, `project`, `client`, `start`, `end`, `billable`, `unbillable` | | table-truncate-column | map[string]int | Truncate text in the given column to contain no more than `x` characters, where `x` is set by `int` | table-truncate-column = { summary = 30 } | | -| target | string | Set the upload target name | target = "tempo" | `tempo` | +| target | string | Set the upload target name | target = "tempo" | Check the list of available targets | | target-user | string | Set the upload target user ID | target = "gabor-boros" | | | tags-as-tasks | bool | Treat tags matching the value of `tags-as-tasks-regex` as tasks | tags-as-tasks = true | | | tags-as-tasks-regex | string | Regex of the task pattern | tags-as-tasks-regex = '[A-Z]{2,7}-\d{1,6}' | |