https://github.com/hellerve/cli
A composable CLI library for zepto
https://github.com/hellerve/cli
Last synced: 4 days ago
JSON representation
A composable CLI library for zepto
- Host: GitHub
- URL: https://github.com/hellerve/cli
- Owner: hellerve
- Created: 2016-02-08T09:26:33.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2020-01-29T16:54:50.000Z (about 6 years ago)
- Last Synced: 2025-07-06T04:50:06.345Z (9 months ago)
- Size: 32.2 KB
- Stars: 0
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# cli
A simple CLI library for Carp.
```clojure
(load "https://veitheller.de/git/carpentry/cli@master")
(defn main []
(let [p (=> (CLI.new @"My super cool tool!")
(CLI.add &(CLI.int "flag" "f" "my flag" true))
(CLI.add &(CLI.str "thing" "t" "my thing" false @"hi" &[@"a" @"b" @"hi"])))]
(match (CLI.parse &p)
(Result.Success flags)
(println* &(str &(Map.get &flags "flag")) " " &(str &(Map.get &flags "thing")))
(Result.Error msg) (do (IO.errorln &msg) (CLI.usage &p)))))
```
## Installation
```clojure
(load "https://veitheller.de/git/carpentry/cli@master")
```
## Usage
`CLI` should be built using combinators, as in the example above. It has, as of
now, three option types: integrals (longs), floating point numbers (doubles),
and strings. They can be built using `CLI.int`, `CLI.float`, and `CLI.str`,
respectively. Their structure is always the same:
```clojure
(CLI.int )
; or
(CLI.int )
; or
(CLI.int )
```
You’ll have to set a default if you want to specify options, although you can
set it to `(Maybe.Nothing)` if you want to make sure that it has to be set
manually.
Once you’re done building your flag structure, you can run `CLI.parse`. It
will not abort the program on error, instead it will tell you what went wrong
in a `Result.Error`. If it succeeds, the `Result.Success` contains a `Map` from
the long flag name to the value (the values are `Maybe`s, since they might be
optional arguments.
Have fun!