You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm looking for an equivalent to python's argparse nargs='?' option, where:
One argument will be consumed from the command line if possible, and produced as a single item. If no command-line argument is present, the value from default will be produced. Note that for optional arguments, there is an additional case - the option string is present but not followed by a command-line argument. In this case the value from const will be produced. Some examples to illustrate this:
The attached code is an example of the desired behavior when using argparse. The main feature that I'm looking is defining some constant value (or behavior) when a "bare" flag is provided, e.g:
python app.py --foo
in this case, I want foo to contain some value, but still allowing the user to provide their own value:
python app.py --foo some_user_provided_value
I hope that it makes sense...
I wasn't able to find a way to implement this using typer, would appreciate any help. thanks!
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
First Check
Commit to Help
Example Code
Description
I'm looking for an equivalent to python's argparse
nargs='?'
option, where:(from python's argparse docs)
The attached code is an example of the desired behavior when using
argparse
. The main feature that I'm looking is defining some constant value (or behavior) when a "bare" flag is provided, e.g:in this case, I want
foo
to contain some value, but still allowing the user to provide their own value:I hope that it makes sense...
I wasn't able to find a way to implement this using typer, would appreciate any help. thanks!
Operating System
Linux
Operating System Details
No response
Typer Version
0.15.1
Python Version
3.10.14
Additional Context
No response
Beta Was this translation helpful? Give feedback.
All reactions