simple-cmd-args: Simple command args parsing and execution

[ bsd3, library, system ] [ Propose Tags ]

This is a small wrapper over optparse-applicative which allows combining args parsers directly with IO commands. For subcommands this can avoid type boilerplate. It also provides some compact aliases for options with their Mod's.

[Skip to Readme]


Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees


Versions [RSS] 0.1.0,, 0.1.1, 0.1.2, 0.1.3, 0.1.4, 0.1.5, 0.1.6, 0.1.7, 0.1.8
Change log
Dependencies base (>=4 && <5), optparse-applicative (>=0.14.1), semigroups [details]
License BSD-3-Clause
Copyright 2019-2020 Jens Petersen
Author Jens Petersen
Category System
Home page
Bug tracker
Source repo head: git clone
Uploaded by JensPetersen at 2020-03-25T17:48:52Z
Distributions Fedora:0.1.8, LTSHaskell:0.1.8, NixOS:0.1.8, Stackage:0.1.8
Downloads 4907 total (43 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2020-03-25 [all 1 reports]

Readme for simple-cmd-args-0.1.6

[back to package description]


Hackage BSD license Stackage Lts Stackage Nightly Build status

A thin layer over optparse-applicative that avoids type plumbing for subcommands by using Parser (IO ()).


import SimpleCmdArgs
import Control.Applicative (some)
import System.Directory

main =
  simpleCmdArgs Nothing "example-tool" "Longer description..." $
    [ Subcommand "echo" "Print words" $
      putStrLn . unwords <$> some (strArg "STR...")
    , Subcommand "ls" "List directory" $
      ls <$> strArg "DIR"
    , Subcommand "mkdir" "Create directory" $
      mkdir <$> parentsOpt <*> strArg "DIR"
    parentsOpt = switchWith 'p' "parents" "Make missing directories"

ls :: FilePath -> IO ()
ls dir =
  listDirectory dir >>= mapM_ putStrLn

mkdir :: Bool -> FilePath -> IO ()
mkdir parents =
  if parents then createDirectoryIfMissing True else createDirectory

See more examples.