Skip to content
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

Support for boolean flag pairs #141

Open
tomasaschan opened this issue Jun 4, 2020 · 3 comments
Open

Support for boolean flag pairs #141

tomasaschan opened this issue Jun 4, 2020 · 3 comments

Comments

@tomasaschan
Copy link

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 the debug_trace flag as determined by the specified flags.

It would be awesome if argh supported this!

@neithere
Copy link
Owner

Looks like a good idea for a decorator.

@integratebio
Copy link

integratebio commented Oct 31, 2021

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.

@neithere neithere added the needs-design needs design decision label Feb 7, 2023
@neithere
Copy link
Owner

neithere commented Feb 7, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants