Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/juhp/simple-cmd-args
See README for more info
https://github.com/juhp/simple-cmd-args
Last synced: 2 months ago
JSON representation
See README for more info
- Host: GitHub
- URL: https://github.com/juhp/simple-cmd-args
- Owner: juhp
- License: mit
- Created: 2019-01-06T11:24:23.000Z (almost 6 years ago)
- Default Branch: main
- Last Pushed: 2022-08-05T10:33:18.000Z (over 2 years ago)
- Last Synced: 2024-10-02T17:38:08.279Z (3 months ago)
- Language: Haskell
- Homepage:
- Size: 57.6 KB
- Stars: 3
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# simple-cmd-args
[![Hackage](https://img.shields.io/hackage/v/simple-cmd-args.svg)](https://hackage.haskell.org/package/simple-cmd-args)
[![BSD license](https://img.shields.io/badge/license-BSD-blue.svg)](LICENSE)
[![Stackage Lts](http://stackage.org/package/simple-cmd-args/badge/lts)](http://stackage.org/lts/package/simple-cmd-args)
[![Stackage Nightly](http://stackage.org/package/simple-cmd-args/badge/nightly)](http://stackage.org/nightly/package/simple-cmd-args)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](https://hackage.haskell.org/package/simple-cmd-args/docs/SimpleCmdArgs.html) for details of all the functions provided.
## Usage
```shellsession
$ cat readme.hs
```
```haskell
import SimpleCmdArgs
import Control.Applicative (some)
import System.Directorymain =
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_ putStrLnmkdir :: Bool -> FilePath -> IO ()
mkdir parents =
if parents then createDirectoryIfMissing True else createDirectory
```
```shellsession
$ ghc readme.hs
$ ./readme --help
readme exampleUsage: readme COMMAND
Longer description...Available options:
-h,--help Show this help textAvailable 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 directoryAvailable options:
-p,--parents Make missing directories
-h,--help Show this help text
```# Examples
See the [examples](https://github.com/juhp/simple-cmd-args/tree/main/examples).Hackage packages using this library: https://packdeps.haskellers.com/reverse/simple-cmd-args