ArgParse.jl
ArgParse.jl copied to clipboard
Easily generating negated flags
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
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.