-
Notifications
You must be signed in to change notification settings - Fork 310
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
go-flags should detect invalid API usage/user error at init time, refuse to work. #159
Comments
I'm not fond of making things fatal inside a library. E.g. maybe you temporarily set the default value to |
So you think a flag that has a value that can't be changed is a really minor issue? I just want to confirm you understand what the issue is. It seems pretty significant to me, but it is rare.
And you might accidentally leave it that way, and not realize users of your binary will not be able to change the flag value.
Maybe a The issue is a potentially unusable flag that can be unnoticed (as has happened in the situation where I ran into this; the developer did not realize there was an issue, and as a user, I could not change the value of the flag at all). |
Of course, if you don't think this is an issue, you're welcome to close this. I only reported it because I wanted to make a suggestion of what I thought would be an improvement to this library, but given that I'm aware of this caveat by now, it doesn't affect me. |
Thanks for resolving this issue! That looks like a good solution. 👍 |
Just a note: this change broke my code. There was a way to change the default value: thru env vars. Anyways, I'm just going to change my defaults but I feel that one should consider all the angles when implementing breaking changes. |
This commit enables the developer to allow setting boolean values to `false`. There already was a piece of code which indirectly allowed this, but default could never be true for bools due to jessevdk#159. With this patch, a new setting `disable-type` is introduced on boolean options. If unset, the bool variables act as before. However, if set, the user can set (and reset) the bool varaible to either `true` or `false`. The setting has three possible values: `value`. `no` and `enable-disable`. When the setting is enabled, bool values will behave as follows: | *`disable-value`* | Syntax | | `value` | `--bool[=true|false]` | | `no` | `--[no-]bool` | | `enable-disable` | `--[enable|disable]-bool` | This allows for use cases such as: ```sh alias program='program --debug` program --no-debug ``` or ```sh ./program --enable-raytracing --disable-antialiasing ```
Originally reported in #80 (comment) (/cc @slimsag) but it's inside a closed issue, and didn't seem to get a response.
The issue is that if a user accidentally uses
default:"true"
on abool
flag, they will have a variable that is unfit to be a flag since it can only ever have the single value true, and there's no way to make it false.Since it's possible to detect such invalid usage at runtime, it'd be better to treat it as a fatal error rather than letting it go unnoticed.
On another note, while I agree with the rationale mentioned in #80 (comment) that ideally bool values should always start out false and adding them should toggle the value to true, it's also the case that sometimes it might be desirable to temporarily change the default value of a boolean value without having to change the CLI name/logic/API (/cc @renfredxh). I'm not completely sure it's a great idea, but it's worth considering.
The text was updated successfully, but these errors were encountered: