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

This is a package candidate release! Here you can preview how this package release will appear once published to the main package index (which can be accomplished via the 'maintain' link below). Please note that once a package has been published to the main package index it cannot be undone! Please consult the package uploading documentation for more information.

[maintain] [Publish]

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]


Versions 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, 0.1.8
Change log
Dependencies base (>=4 && <5), optparse-applicative (>=0.14.1), semigroups [details]
License BSD-3-Clause
Copyright 2019-2022 Jens Petersen
Author Jens Petersen
Category System
Home page
Bug tracker
Source repo head: git clone
Uploaded by JensPetersen at 2022-08-03T16:01:01Z


[Index] [Quick Jump]


Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Readme for simple-cmd-args-0.1.8

[back to package description]


Hackage BSD license Stackage Lts Stackage Nightly

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

Various wrapper functions are also provided for common option/arg idioms.

See the library's documentation for details of all the functions provided.


$ cat readme.hs
import SimpleCmdArgs
import Control.Applicative (some)
import System.Directory

main =
  simpleCmdArgs Nothing "readme example" "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
$ ghc readme.hs
$ ./readme --help
readme example

Usage: readme COMMAND
  Longer description...

Available options:
  -h,--help                Show this help text

Available commands:
  echo                     Print words
  ls                       List directory
  mkdir                    Create directory
$ ./readme echo hello world
hello world
$ ./readme mkdir -h
Usage: readme mkdir [-p|--parents] DIR
  Create directory

Available options:
  -p,--parents             Make missing directories
  -h,--help                Show this help text


See the examples.

Hackage packages using this library: