dominikbraun / timetrace

A simple CLI for tracking your working time.
Apache License 2.0
679 stars 75 forks source link

Bug: start command does not allow flag -b #117

Closed FelixTheodor closed 3 years ago

FelixTheodor commented 3 years ago

The start command returns an error if you try to set billable on true:

> ./timetrace start test -b true
❗ accepts 1 arg(s), received 2

I think this can be fixed by deleting one line, therefore I already created a PR for it. Please check if you can confirm the bug (maybe I miss something) and close the PR if its not reproduceable.

dominikbraun commented 3 years ago

Not sure whether this is really a bug. AFAIK, boolean flags either have to be passed as --billable (or -b) or, if you want to enable/disable it explicitly, as --billable=true (or -b=true).

@aligator PTAL

aligator commented 3 years ago

@FelixTheodor Thanks for the PR, but actually @dominikbraun is right. With your solution it only works because the short-boolean-flag only looks for "existence" of the flag. So ./timetrace start test -b true works just because the -b exists and not because true is set. You can check that using your branch:
running ./timetrace start test -b false still creates a billable=true record.

--> Cobra supports no booleans like -b false or --billable false (In contrary to non boolean flags where this is possible but also treated by cobra.ExactArgs correctly.)
Only using an = is possible.

But in the end just pass -b (without true) to enable it or do not pass it at all to disable it.

FelixTheodor commented 3 years ago

Ah, I see! Thanks for the explanation, @aligator @dominikbraun