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
Extra documentation: tricks and traps with options with optional values #1315
Comments
Hi @shadowspawn I would like to help out with this, is it alright? |
@heyjiawei happy to have someone else involved. Would you like to make a start on writing the page, or are you wanting to provide feedback/help with something I write? |
If you have started on this I could help provide feedback. I can also start writing a section on this. Could you elaborate on the following points:
|
I had a typo there, "when also" should be "when use" (fixed in original post now). If there is an option with an optional value
In the last example, the user might be intending
Suppose there is a plain flag
Before Commander v5,
I was thinking of showing some example code to restore the old behaviour, but when I tried it was trickier than I expected to do it well, so I added configuration to build into Commander to switch the behaviour. #1326 |
(I have been thinking about documenting complications with optional values for a long time, but have not started writing it down yet.) |
Ah I see. Here is a rough draft (sorry its not complete but do comment!): Tricks and traps with options with optional valuesThere potential challenges using options with optional values. They seem quite attractive and the README used to use them more than options with require values! In practice, they are a bit tricky and aren't a free choice. Parsing ambiguity when also option as boolean flag but also operands and subcommands
For example, the user might be intending Conflict between short flag with value, and combined short flags with optional values.
In this example, it is ambiguous as to whether the user is trying to use optional options as boolean options, or pass the value
If you wish to use optional options as boolean options, you need explicity list them as options
Possible workarounds// TODO |
I'm not quite sure what's the conflict here. From your example:
It seems like this can be misleading instead of conflicting for users. I assume users may expect either:
I think this is clearer if we show an example of combined short flags with optional values, using the servings type code example above. What do you think @shadowspawn ?
Are we pointing out this difference? Or are we adding a short explanation on why things became like that? @shadowspawn |
Great comments and questions. I'll write up a long reply when I have a bit more time. |
Very good point. This is not a conflict. This is not an error. But this will trip up some users the first time they encounter it, when it works differently than they expected (they won't notice when it does work the way they expected!). The high level issue that that the end user will sometimes need to adjust the command-line to get the result they want, effectively so Commander understands what they intend. |
I am not sure it will be clearer, but it is certainly the situation that is more likely to trip people up! I agree use an example of combined short flags with optional values. |
I like the |
I was mainly giving you the back context in that comment. Hmmm, what do I want to say... Like with the other issue, the (current) behaviour is not wrong or a conflict. But this may trip up some users. So again we want to help people understand enough to adjust the command-line if needed to get the result they want The addition in this case is the new behaviour may be an issue for people upgrading from old versions of Commander, who are relying on the "other" (old) behaviour . So I want to cover that there is (will be) a routine to prioritise combining flags over combining flag-and-value. Ask again if that does not make enough sense! |
@shadowspawn I've created a PR for this #1332 , perhaps you can take a look |
(Will do.) |
Released in Commander v6.2.0 |
We could add a separate page, outside the README, going into details about potential challenges using options with optional values. They seem quite attractive and the README used to use them more than options with require values! In practice, they are a bit tricky and aren't a free choice.
The text was updated successfully, but these errors were encountered: