Skip to content

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

Description

@wolverian

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?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions