pcapriotti / pcapriotti/optparse-applicative

Is it possible to automatically show in help which values are valid for an option?

Open
#467 4 comments 0 reactions 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

Given an option of a sum type (Foo in this example):

module Main where

import Options.Applicative

data Opts = Opts
    { flag :: Foo
    , ok :: Bool
    }
    deriving (Show)

data Foo = Bar | Baz | Quux deriving (Read, Show)

opts :: Parser Opts
opts =
    Opts
        <$> option auto (help "how to do it" <> long "flag" <> value Bar <> showDefault)
        <*> option auto (help "is it ok" <> long "ok" <> value True <> showDefault)

main :: IO ()
main = do
    opts' <- execParser (info (opts <**> helper) fullDesc)
    print opts'

This is the help output currently:

Usage: optest [--flag ARG] [--ok ARG]

Available options:
  --flag ARG               how to do it (default: Bar)
  --ok ARG                 is it ok (default: True)
  -h,--help                Show this help text

Instead of --flag ARG how to do it (default: Bar) I would like something like --flag ARG how to do it (default: Bar, allowed values: Foo, Bar, Baz). Can optparse-applicative do 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 with the example's opts parser and trace how option auto, help, value, and showDefault are rendered by execParser. Compare the current help output with the requested allowed-values text, then identify the existing help-generation tests or entry points that would need coverage; done means the behavior is specified and verified for sum-type options.

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
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.