4 Commits
0.0.4 ... 0.0.6

Author SHA1 Message Date
5b3b72e127 vbump 2020-01-31 22:30:42 +01:00
99ce77695c make = work as well 2020-01-31 22:26:37 +01:00
e55dc7556d version bump 2020-01-31 17:31:06 +01:00
14d25abc35 bugfix for printing none 2020-01-31 17:28:31 +01:00
4 changed files with 28 additions and 38 deletions

View File

@@ -3,7 +3,7 @@
A simple CLI library for Carp.
```clojure
(load "https://veitheller.de/git/carpentry/cli@0.0.2")
(load "https://veitheller.de/git/carpentry/cli@0.0.6")
(defn main []
(let [p (=> (CLI.new @"My super cool tool!")
@@ -18,7 +18,7 @@ A simple CLI library for Carp.
## Installation
```clojure
(load "https://veitheller.de/git/carpentry/cli@0.0.2")
(load "https://veitheller.de/git/carpentry/cli@0.0.6")
```
## Usage
@@ -43,8 +43,8 @@ manually.
Once youre 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.
the long flag name to the value. The values are not in the map if they are
unset.
<hr/>

View File

@@ -6,7 +6,7 @@
(doc CLI "is a simple CLI library for Carp.
```clojure
(load \"https://veitheller.de/git/carpentry/cli@0.0.2\")
(load \"https://veitheller.de/git/carpentry/cli@0.0.6\")
(defn main []
(let [p (=> (CLI.new @\"My super cool tool!\")
@@ -21,7 +21,7 @@
## Installation
```clojure
(load \"https://veitheller.de/git/carpentry/cli@0.0.2\")
(load \"https://veitheller.de/git/carpentry/cli@0.0.6\")
```
## Usage
@@ -88,7 +88,8 @@ unset.")
(match @t
(Integer i) (str i)
(Floating f) (str f)
(Str s) (str s)))
(Str s) (str s)
(None) @"none"))
(defn to-int [x]
(match x
@@ -330,17 +331,22 @@ mesage is empty, `--help` was requested. If you dont want to provide a
(for [i 1 (System.get-args-len)]
(let [x (System.get-arg i)]
(if (or (String.starts-with? x "--") (String.starts-with? x "-"))
(let [flag (Pattern.substitute #"^\-\-?" x "" 1)]
(let [flag (Pattern.substitute #"^\-\-?" x "" 1)
splt (String.split-by &flag &[\=])
k (if (> (Array.length &splt) 1) (Array.unsafe-nth &splt 0) &flag)
v (cond (> (Array.length &splt) 1) (Array.nth &splt 1)
(< i (System.get-args-len))
(do (set! i (Int.inc i)) (Maybe.Just @(System.get-arg i)))
(Maybe.Nothing))]
(cond
(CmdMap.contains? &values &flag)
(do
(set! i (Int.inc i))
(if (< i (System.get-args-len))
(CmdMap.put! &values &flag (System.get-arg i))
(CmdMap.contains? &values k)
(match v
(Maybe.Just val) (CmdMap.put! &values k &val)
(Maybe.Nothing)
(do
(set! res (Result.Error (fmt "No value for: %s" &flag)))
(break))))
(or (= &flag "help") (= &flag "h"))
(break)))
(or (= k "help") (= k "h"))
(do
(set! res (Result.Error @""))
(break))

View File

@@ -30,7 +30,7 @@
</h1>
<div class="module-description">
<p>is a simple CLI library for Carp.</p>
<pre><code class="language-clojure">(load &quot;https://veitheller.de/git/carpentry/cli@0.0.2&quot;)
<pre><code class="language-clojure">(load &quot;https://veitheller.de/git/carpentry/cli@0.0.6&quot;)
(defn main []
(let [p (=&gt; (CLI.new @&quot;My super cool tool!&quot;)
@@ -42,7 +42,7 @@
(Result.Error msg) (do (IO.errorln &amp;msg) (CLI.usage &amp;p)))))
</code></pre>
<h2>Installation</h2>
<pre><code class="language-clojure">(load &quot;https://veitheller.de/git/carpentry/cli@0.0.2&quot;)
<pre><code class="language-clojure">(load &quot;https://veitheller.de/git/carpentry/cli@0.0.6&quot;)
</code></pre>
<h2>Usage</h2>
<p><code>CLI</code> should be built using combinators, as in the example above. It has, as of
@@ -65,25 +65,6 @@ the long flag name to the value. The values are not in the map if they are
unset.</p>
</div>
<div class="binder">
<a class="anchor" href="#(defdynamic CLI.*gensym-counter* 1001)">
<h3 id="(defdynamic CLI.*gensym-counter* 1001)">
(defdynamic CLI.*gensym-counter* 1001)
</h3>
</a>
<div class="description">
dynamic
</div>
<p class="sig">
Dynamic
</p>
<span>
</span>
<p class="doc">
</p>
</div>
<div class="binder">
<a class="anchor" href="#Option">
<h3 id="Option">

View File

@@ -3,8 +3,11 @@
(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"])))]
(CLI.add &(CLI.str "thing" "t" "my thing" false @"hi" &[@"a" @"b" @"hi"]))
(CLI.add &(CLI.str "other" "o" "my thing" false)))]
(match (CLI.parse &p)
(Result.Success flags)
(println* &(str &(Map.get &flags "flag")) " " &(str &(Map.get &flags "thing")))
(println*
&(str &(Map.get &flags "flag")) " " &(str &(Map.get &flags "thing"))
" " &(str &(Map.get &flags "other")))
(Result.Error msg) (do (IO.errorln &msg) (CLI.usage &p)))))