Allow replacing commands with metavar when using parserOptionGroup
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 48/100
Research direction
Start by reading the existing parserOptionGroup implementation and pull request #486, then compare the duplicated usage output with the proposed metavar workaround in this issue. Determine how grouped options can display a single metavar without the dummy option or hidden modifiers; done means the concise usage output is preserved while the ATTRIBUTES option descriptions remain visible.
Written by the indexing model from the issue text.
Description
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?
- Dominant language
- Haskell
- Stars
- 957
- Forks
- 124
- PR merge metrics
- No merged PRs in 30d
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from pcapriotti/optparse-applicative
-
Difficulty 1/5 Under an hour Newbie friendliness 75/100
-
Difficulty 4/5 3-5 days Newbie friendliness 42/100
pcapriotti/optparse-applicative#524 · 2 comments ·
-
Nushell CompletionsOpen
Difficulty 4/5 3-5 days Newbie friendliness 48/100
-
Difficulty 4/5 3-5 days Newbie friendliness 48/100
pcapriotti/optparse-applicative#513 · 4 comments ·
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
pcapriotti/optparse-applicative#495 · 2 comments ·
All issues in pcapriotti/optparse-applicative
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
IntersectMBO/cardano-ledger#6276 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
OpenZeppelin/canton-contracts#92 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
hasura/graphql-engine#10954 ·
Maintainers usually reply within 1 day