Skip to content

Instantly share code, notes, and snippets.

@jhrcek
Last active April 5, 2019 05:42
Show Gist options
  • Select an option

  • Save jhrcek/b73c5ef79f7cc0a474ead1df7f7eebbb to your computer and use it in GitHub Desktop.

Select an option

Save jhrcek/b73c5ef79f7cc0a474ead1df7f7eebbb to your computer and use it in GitHub Desktop.
optparse-applicative demo
import Options.Applicative (Parser, ParserInfo, command, execParser, fullDesc,
help, helper, info, progDesc, subparser, value)
main :: IO ()
main = execParser cliParser >>= print
demo :: Parser Int
demo = subparser
( command "a" (info (pure 1) (progDesc "A description"))
<> command "b" (info (pure 2) (progDesc "B description"))
)
cliParser :: ParserInfo Int
cliParser = info (helper <*> demo) fullDesc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment