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

Easily generating negated flags #35

Open
c42f opened this issue Oct 14, 2016 · 1 comment
Open

Easily generating negated flags #35

c42f opened this issue Oct 14, 2016 · 1 comment

Comments

@c42f
Copy link

c42f commented Oct 14, 2016

Hi, is there any plan to support autogeneration of the negation of a boolean flag? That is, if I want to accept both --foo and --no-foo to enable and disable foo, I could write something like

s = ArgParseSettings()

@add_arg_table s begin
    "--foo"
        action = :store_true
    "--no-foo"
        dest_name = "foo"
        action = :store_false
end

But it would be nice to have a shorthand. Here's how python click does it, for example: http://click.pocoo.org/5/options/#boolean-flags

CC @janzill

@carlobaldassi
Copy link
Owner

It's a nice feature to have but not entirely straightforward to implement. I'll keep it in my todo list (and will accept pull requests if someone volunteers to do it of course).

As for how to implement it, the python click way is nice, but I'm not sure of what syntax to use in case one wants to have multiple choices (e.g. both a short and a long option, like "-f", "--foo"). It would be better IMO to have a separator after which the negated versions are provided, for example:

@add_arg_table s begin
    "-f", "-foo" / "-n", "--no-foo"
        action = :store_true
end

This requires a bit of work on the parsing, but it's probably doable. The harder part would then be to figure out what to do for the add_arg_table function.

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

No branches or pull requests

2 participants