You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Given an option of a sum type (Foo in this example):
moduleMainwhereimportOptions.ApplicativedataOpts=Opts{flag::Foo
, ok::Bool}deriving (Show)
dataFoo=Bar | Baz | Quuxderiving (Read, Show)
opts::ParserOpts
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?
The text was updated successfully, but these errors were encountered:
Interesting question. We don't support this natively at the moment, but I think it would be a simple addition to write.
With a Bounded instance on your type, one could imagine something like:
option auto (help "how to do it"<> long "flag"<> value Bar<> showDefault <> boundedPossibilities)
Seeing as all showDefault does is organise the parens and default text to tack onto the end of the help text for the option, you can do it yourself with the help text.
With a Bounded instance on your type, one could imagine something like:
I think you'd want Enum as well.
Seeing as all showDefault does is organise the parens and default text to tack onto the end of the help text for the option, you can do it yourself with the help text.
Is there a way to add to the help text with a Mod, instead of replacing it altogether?
Given an option of a sum type (
Foo
in this example):This is the help output currently:
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?The text was updated successfully, but these errors were encountered: