BSD-3-Clause licensed by Jens Petersen
Maintained by [email protected]
This version can be pinned in stack with:simple-cmd-args-0.1.8@sha256:c934e3ff34405907b46928d60e76d4488979f9d3c147a60b4d8d81be74498eaa,1463

Module documentation for 0.1.8

simple-cmd-args

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.

Usage

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

main =
  simpleCmdArgs Nothing "readme example" "Longer description..." $
  subcommands
    [ Subcommand "echo" "Print words" $
      putStrLn . unwords <$> some (strArg "STR...")
    , Subcommand "ls" "List directory" $
      ls <$> strArg "DIR"
    , Subcommand "mkdir" "Create directory" $
      mkdir <$> parentsOpt <*> strArg "DIR"
    ]
  where
    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

Examples

See the examples.

Hackage packages using this library: https://packdeps.haskellers.com/reverse/simple-cmd-args

Changes

Changelog

simple-cmd-args uses PVP Versioning.

0.1.8 (2022-08-03)

  • add *LongWith versions of *With and also *LongMods: allows defining options with only a long option and no short option

0.1.7 (2021-06-28)

  • re-export maybeReader, eitherReader, and ReadM

0.1.6 (2020-03-25)

  • subcommands now have –help option
  • output a warning if there are duplicate commands

0.1.5 (2020-02-06)

  • add Eq and Ord instances for Subcommand

0.1.4 (2019-10-29)

  • re-export many, some, str
  • re-export <$> and <*> on older ghc7

0.1.3 (2019-09-12)

  • re-export <|>

0.1.2 (2019-05-24)

  • add flagWith and flagWith’
  • re-export Parser, auto, optional

0.1.1 (2019-04-08)

  • add switchWith, strOptionWith, optionWith, optionalWith, strOptionalWith, argumentWith
  • export simpleCmdArgsWithMods

0.1.0.1

  • fix and improve haddock documentation

0.1.0

  • Initial release with subcommands and option Mod functions