Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
5b3b72e127 | |||
99ce77695c |
@@ -3,7 +3,7 @@
|
|||||||
A simple CLI library for Carp.
|
A simple CLI library for Carp.
|
||||||
|
|
||||||
```clojure
|
```clojure
|
||||||
(load "https://veitheller.de/git/carpentry/cli@0.0.5")
|
(load "https://veitheller.de/git/carpentry/cli@0.0.6")
|
||||||
|
|
||||||
(defn main []
|
(defn main []
|
||||||
(let [p (=> (CLI.new @"My super cool tool!")
|
(let [p (=> (CLI.new @"My super cool tool!")
|
||||||
@@ -18,7 +18,7 @@ A simple CLI library for Carp.
|
|||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
```clojure
|
```clojure
|
||||||
(load "https://veitheller.de/git/carpentry/cli@0.0.5")
|
(load "https://veitheller.de/git/carpentry/cli@0.0.6")
|
||||||
```
|
```
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
25
cli.carp
25
cli.carp
@@ -6,7 +6,7 @@
|
|||||||
(doc CLI "is a simple CLI library for Carp.
|
(doc CLI "is a simple CLI library for Carp.
|
||||||
|
|
||||||
```clojure
|
```clojure
|
||||||
(load \"https://veitheller.de/git/carpentry/cli@0.0.5\")
|
(load \"https://veitheller.de/git/carpentry/cli@0.0.6\")
|
||||||
|
|
||||||
(defn main []
|
(defn main []
|
||||||
(let [p (=> (CLI.new @\"My super cool tool!\")
|
(let [p (=> (CLI.new @\"My super cool tool!\")
|
||||||
@@ -21,7 +21,7 @@
|
|||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
```clojure
|
```clojure
|
||||||
(load \"https://veitheller.de/git/carpentry/cli@0.0.5\")
|
(load \"https://veitheller.de/git/carpentry/cli@0.0.6\")
|
||||||
```
|
```
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
@@ -331,17 +331,22 @@ mesage is empty, `--help` was requested. If you don’t want to provide a
|
|||||||
(for [i 1 (System.get-args-len)]
|
(for [i 1 (System.get-args-len)]
|
||||||
(let [x (System.get-arg i)]
|
(let [x (System.get-arg i)]
|
||||||
(if (or (String.starts-with? x "--") (String.starts-with? x "-"))
|
(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
|
(cond
|
||||||
(CmdMap.contains? &values &flag)
|
(CmdMap.contains? &values k)
|
||||||
(do
|
(match v
|
||||||
(set! i (Int.inc i))
|
(Maybe.Just val) (CmdMap.put! &values k &val)
|
||||||
(if (< i (System.get-args-len))
|
(Maybe.Nothing)
|
||||||
(CmdMap.put! &values &flag (System.get-arg i))
|
|
||||||
(do
|
(do
|
||||||
(set! res (Result.Error (fmt "No value for: %s" &flag)))
|
(set! res (Result.Error (fmt "No value for: %s" &flag)))
|
||||||
(break))))
|
(break)))
|
||||||
(or (= &flag "help") (= &flag "h"))
|
(or (= k "help") (= k "h"))
|
||||||
(do
|
(do
|
||||||
(set! res (Result.Error @""))
|
(set! res (Result.Error @""))
|
||||||
(break))
|
(break))
|
||||||
|
@@ -30,7 +30,7 @@
|
|||||||
</h1>
|
</h1>
|
||||||
<div class="module-description">
|
<div class="module-description">
|
||||||
<p>is a simple CLI library for Carp.</p>
|
<p>is a simple CLI library for Carp.</p>
|
||||||
<pre><code class="language-clojure">(load "https://veitheller.de/git/carpentry/cli@0.0.5")
|
<pre><code class="language-clojure">(load "https://veitheller.de/git/carpentry/cli@0.0.6")
|
||||||
|
|
||||||
(defn main []
|
(defn main []
|
||||||
(let [p (=> (CLI.new @"My super cool tool!")
|
(let [p (=> (CLI.new @"My super cool tool!")
|
||||||
@@ -42,7 +42,7 @@
|
|||||||
(Result.Error msg) (do (IO.errorln &msg) (CLI.usage &p)))))
|
(Result.Error msg) (do (IO.errorln &msg) (CLI.usage &p)))))
|
||||||
</code></pre>
|
</code></pre>
|
||||||
<h2>Installation</h2>
|
<h2>Installation</h2>
|
||||||
<pre><code class="language-clojure">(load "https://veitheller.de/git/carpentry/cli@0.0.5")
|
<pre><code class="language-clojure">(load "https://veitheller.de/git/carpentry/cli@0.0.6")
|
||||||
</code></pre>
|
</code></pre>
|
||||||
<h2>Usage</h2>
|
<h2>Usage</h2>
|
||||||
<p><code>CLI</code> should be built using combinators, as in the example above. It has, as of
|
<p><code>CLI</code> should be built using combinators, as in the example above. It has, as of
|
||||||
|
Reference in New Issue
Block a user