Popularity
3.4
Growing
Activity
0.0
Stable
3
4
0
Monthly Downloads: 46
Programming language: Haskell
License: BSD 3-clause "New" or "Revised" License
Latest version: v0.1.6
Add another 'simple' Package
README
simple-cmd-args
A thin layer over optparse-applicative that avoids type plumbing for
subcommands by using Parser (IO ())
.
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
See more examples.
*Note that all licence references and agreements mentioned in the simple-cmd-args README section above
are relevant to that project's source code only.