Repository navigation
Flags mimic bool - #228
Flags mimic bool#228sakateka wants to merge 3 commits into
Conversation
|
Hello. I guess I'm not sure what you're referring to. Can you show me an example? |
|
A good example is the lsof utility My example, I want to implement the |
|
The problem with this is how do you differentiate between an optional parameter to a flag, and a positional argument? This works for lsof because it does not support positional arguments. eg. |
|
Yes, it's a problem. As an option, the user should be aware of the problem and start the app like this |
|
There's also the issue of ambiguity with combined short flags, eg. I don't think there's any way to support this that's reasonable, sorry :( |
|
No problems) |
|
I remembered the second part of my plan. ) |
|
I didn't quite understand what problem that solved? |
|
If the flag have the default value (or not even), the variable will always be set to the default value or to the value provided by the user. |
|
I agree with @sakateka. |
|
pflag has this functionality https://github.com/spf13/pflag#setting-no-option-default-values-for-flags |
Details alecthomas#228 (comment) (cherry picked from commit ef6e7c1)
* Add tests and fix edge cases (cherry picked from commit bd4c463) * Write example of app and short help flags (cherry picked from commit ff0d2a1) * OverrideDefaultFromEnvar is deprecated (cherry picked from commit de569dc) * add IsSetByUser Details alecthomas#228 (comment) (cherry picked from commit ef6e7c1) --------- Co-authored-by: Emilien Kenler <emilien@kkvesper.jp> Co-authored-by: Benjamin Kane <bbkane@users.noreply.github.com> Co-authored-by: Wataru Ashihara <wataash0607@gmail.com> Co-authored-by: Sergey Kacheev <skacheev@yandex-team.ru>
Hi!
I have an idea how to add flags similar to Booleans, but taking optional values.
I also figured out how to make
isSetByUserposible for users.I implemented this idea and use it in my application.
But when implementing I did not understand how to set the default value correctly and used a dirty hack :-)
If these flags are interesting, I can try to make the proper setting of default values.