-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
option without value can prompt or use default #1618
Conversation
4905eaf
to
2cc8e6d
Compare
I'm wondering if it's appropriate to have |
2cc8e6d
to
b64fee0
Compare
I moved it into |
I think there's another issue about options where the value is optional, maybe this solution will help with that too. |
I was thinking of #549. |
Just found it and was about to comment it too haha. |
It seems like it should be a natural extension of this, since we now track if only the flag was passed. If it's only a flag, and there is a default, use the default instead of prompting. I don't think that should collide with any existing combination of settings, but that should be checked, along with how on/off flags currently work. It can be a separate PR. |
@davidism I've added the ability to use options with optional args via the However, this did not get rid of the additional parameter we added to An idea in mind is to instead of having |
Instead of the parser producing # define the sentinel value at the top of the module
flag_needs_value = object()
# return it when parsing
def match(...):
return _flag_needs_value
# check it when processing
def process(...):
if value is _flag_needs_value:
...
elif value is None:
... |
prompt_required
to options
I updated the PR description with the issues related to using a value instead of prompting. Also closed some existing PRs that will be handled by this. Let's make sure any tests they had are reflected here if applicable. |
Sounds good 👍 I'll be sure to add those tests and update the docs. Some clarifying questions:
|
|
9f1cc62
to
1e0536c
Compare
I've used the sentinel value idea, although was not too sure about the name or if it was appropriate to name it the same name as the attribute. I also noticed #1230 enforced that the option cannot be |
Will get to this after #1649. They're all related, might affect my answer to the question about Don't worry about rebasing in the mean time, I'll address that after the other things are merged. |
You may have already addressed this but I was attempting to implement something similar to the color option from git diff: --color[=<when>]
Show colored diff. --color (i.e. without =<when>) is the same as
--color=always. <when> can be one of always, never, or auto. It can
be changed by the color.ui and color.diff configuration settings. The color option has a flag value of The main difference I see is that the value must be separated from the option by The example in the docs don't seem to handle this. |
Working on rebasing this after #1649. |
1e0536c
to
44e668a
Compare
44e668a
to
e5eedda
Compare
use flag_value or prompt if an option is given without a value
e5eedda
to
d314f45
Compare
Resolves #549
Resolves #736
Resolves #764
Resolves #921
Resolves #1015
Add
prompt_required
attribute toOption
so that whenprompt_required=False
, the user will only be prompted for an input if the option is specified without a value. The attribute defaults toTrue
to maintain the current behavior of option prompts.is_flag=False
now means that providing the value to the option is optional. If the flag is provided without the value, it can be prompted for or useflag_value
.