optparse-applicative-dex

Extra functions for working with optparse-applicative

Stackage Nightly 2025-09-09:1.0.1
Latest on Hackage:1.0.1

See all snapshots optparse-applicative-dex appears in

ISC licensed by Dino Morelli
Maintained by [email protected]
This version can be pinned in stack with:optparse-applicative-dex-1.0.1@sha256:de325edef3720c65591cb34eafe313822a7db1249fa027d4487415f2ffbd8653,1251

Module documentation for 1.0.1

optparse-applicative-dex

Synopsis

Extra functions for working with optparse-applicative

Description

optparse-applicative is a fantastic library

My usage of it has often used the same features wrapped in a parseOpts function along with a version helper.

This package abstracts that code into a re-usable library, minimizing pasting between projects.

In most CLI projects I almost always want:

  • A header consisting of the program name and a short description
  • A helper parser to provide -h, –help
  • A version helper to respond to a –version option with shorter output than -h, –help
  • Some additional usage info below the generated switch usage

The parseOpts’ and parseOptsWithWidth functions in this library take a parser and arguments for header, footer and the app version as generated by cabal and do all these things automatically.

A simple example:

{- # LANGUAGE OverloadedStrings #-}

import Options.Applicative.Dex
import Paths_your_app (version)

data Options = Options { optA :: String , optB :: Bool }
  deriving Show

parser :: Parser Options
parser = Options
  <$> option str ( short 'a' <> metavar "STR" <> help "The a option, a string" )
  <*> switch ( short 'b' <> help "The b option, a switch")

main :: IO ()
main = do
  opts <- parseOpts' parser "header-info" "footer-info" version
  print opts

Getting source

Source code is available from codeberg at the optparse-applicative-dex project page.

Contact

Dino Morelli [email protected]

Changes

1.0.1 (2025-09-05)

  • Fixed build dependency issue with Stackage nightly snapshot

1.0.0 (2025-09-05)

  • Initial release