First of all, thank you for optparse-applicative! I've been using it for many years and it's one of the reasons I come back to Haskell every now and then.
Recently parserOptionGroup was added which allows grouping options. When used alone though, the options are shown twice. In niv, which has a few options (simplified below), it eats up a lot of real estate:
Usage: <interactive> update [PACKAGE]
[
(--attribute KEY=VAL |
--string-attribute KEY=VAL | --owner ARG |
--repo ARG | --branch ARG | --rev ARG)]
Update dependencies
ATTRIBUTES
--attribute KEY=VAL ...
--string-attribute KEY=VAL
...
--owner ARG ...
--repo ARG ...
--branch ARG ...
--rev ARG ...
Available options:
-h,--help Show this help text
I've come up with a mixture of a dummy option and hidden modifiers which show a metavar instead, which I think makes the output easier to understand:
Usage: <interactive> update [PACKAGE] [ATTRIBUTES]
Update dependencies
ATTRIBUTES
--attribute KEY=VAL ...
--string-attribute KEY=VAL
...
--owner ARG ...
--repo ARG ...
--branch ARG ...
--rev ARG ...
Available options:
-h,--help Show this help text
The implementation looks like this:
parsePackageSpec' :: Opts.Parser ParsedPackageSpec
parsePackageSpec' = groupOptions "ATTRIBUTES" $ ParsedPackageSpec <$> Opts.some attribute
where
groupOptions :: String -> Opts.Parser a -> Opts.Parser a
groupOptions mv x = Opts.option empty (Opts.metavar mv) <|> Opts.parserOptionGroup mv x
attribute = Opts.strOption ... Opts.hidden
...
Am I missing something obvious with parserOptionGroup? Is there a simpler way to achieve this?
First of all, thank you for
optparse-applicative! I've been using it for many years and it's one of the reasons I come back to Haskell every now and then.Recently
parserOptionGroupwas added which allows grouping options. When used alone though, the options are shown twice. Inniv, which has a few options (simplified below), it eats up a lot of real estate:I've come up with a mixture of a dummy option and
hiddenmodifiers which show a metavar instead, which I think makes the output easier to understand:The implementation looks like this:
Am I missing something obvious with
parserOptionGroup? Is there a simpler way to achieve this?