@hackage / simple-cmd-args

Simple command args parsing and execution

Latest0.1.8

About

Metadata

  • Last updated , by JensPetersen
  • License BSD-3-Clause
  • Categories Systems Programming
  • Maintained by: juhpetersen@gmail.com

  • Lottery factor: 0

Links

Installation

Tested Compilers

  1. 9.2.4
  2. 9.0.2
  3. 8.10.7
  4. 8.8.4
  5. 8.6.5
  6. 8.4.4
  7. 8.2.2
  8. 8.0.2
  9. 7.10.3

Readme

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