simple-cmd-args

Simple command args parsing and execution

https://github.com/juhp/simple-cmd-args

Version on this page:0.1.6
LTS Haskell 22.43:0.1.8
Stackage Nightly 2024-12-04:0.1.8
Latest on Hackage:0.1.8

See all snapshots simple-cmd-args appears in

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

Module documentation for 0.1.6

simple-cmd-args

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 ()).

Usage

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

main =
  simpleCmdArgs Nothing "example-tool" "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

See more examples.

Changes

Changelog

simple-cmd-args uses PVP Versioning.

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)

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

0.1.3 (2019-09-12)

  • export <|>

0.1.2 (2019-05-24)

  • add flagWith and flagWith’
  • 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