Allow replacing commands with metavar when using parserOptionGroup

Open
#523 1 comment 1 reaction 0 assignees View on GitHub

@tbidne is already working on this.

Since Aug 19, 2026.

  • #525 by @tbidne — open

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
48/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Quiet
Tech stack
haskell
Domain
cli

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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from pcapriotti/optparse-applicative

All issues in pcapriotti/optparse-applicative

Similar issues

More Haskell issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.