Skip to content

Commit

Permalink
fix: multiple small issues fix (#35)
Browse files Browse the repository at this point in the history
* 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 <gabor.brs@gmail.com>
  • Loading branch information
gabor-boros committed Nov 4, 2021
1 parent d343fe3 commit ebb0730
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -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
Expand Down
22 changes: 18 additions & 4 deletions cmd/root.go
Expand Up @@ -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
Expand Down Expand Up @@ -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")
}
Expand Down Expand Up @@ -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)
}

Expand Down
6 changes: 3 additions & 3 deletions www/docs/configuration.md
Expand Up @@ -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}' | |
Expand Down

0 comments on commit ebb0730

Please sign in to comment.