Open tomasaschan opened 4 years ago
Looks like a good idea for a decorator.
I set up argh like this:
def function(test=True):
return
import argh
parser = argh.ArghParser()
parser.add_commands([function])
The default of function
's boolean argument test
is set at True. So on the command line, if I would like to disable this boolean argument. How do I do it?
If I run
python script.py function
The default value (True) is taken.
If I run
python script.py function --test False
I get this error: error: unrecognized arguments: --test False
.
I think argh
should provide (automatic) prefixes for boolean arguments e.g. --no-test
or --disable-test
if test
's default is set at True.
python script.py function --disable-test
As far as I know, such functionality does not exist already in argh. But it would be of common use. For example, argh
of javascript has this functionality: https://www.npmjs.com/package/argh. I think it would be really great to have this functionality for python's argh.
I think it would make sense to make this configurable to avoid breaking changes and confusion. Not sure on which level and how exactly such configuration would take place.
A lot of CLIs with boolean flags have two versions of a flag, e.g.
bq --help
shows options like--[no]debug_trace
, which allows the user to explicitly set either a true or a false value (or leave it to the CLI to use the default, if no flag is specified).The CLI should error if a user specifies both
--nodebug_trace
and--debug_trace
in the same invocation, and otherwise choose the value for thedebug_trace
flag as determined by the specified flags.It would be awesome if
argh
supported this!