pcapriotti / pcapriotti/optparse-applicative

Allow replacing commands with metavar when using parserOptionGroup

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

Nobody has claimed this yet.

Dominant language
Haskell
Stars
959
Forks
123
Avg merge
3d 19h
Merged PRs (30d)
1

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?

Contributor guide

No contributing guide indexed for this repository

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.

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.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.