Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
b5eb3a917b | |||
cb5c9f0bfe | |||
7bd0817c27 | |||
493d0016d5 | |||
aaf413ac04 |
@@ -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@master")
|
(load "https://veitheller.de/git/carpentry/cli@0.0.2")
|
||||||
|
|
||||||
(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@master")
|
(load "https://veitheller.de/git/carpentry/cli@0.0.2")
|
||||||
```
|
```
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
19
cli.carp
19
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.1\")
|
(load \"https://veitheller.de/git/carpentry/cli@0.0.2\")
|
||||||
|
|
||||||
(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.1\")
|
(load \"https://veitheller.de/git/carpentry/cli@0.0.2\")
|
||||||
```
|
```
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
@@ -78,6 +78,12 @@ optional arguments.")
|
|||||||
(Integer i) (Long.format s i)
|
(Integer i) (Long.format s i)
|
||||||
(Floating f) (Double.format s f)
|
(Floating f) (Double.format s f)
|
||||||
(Str s2) (String.format s &s2)))
|
(Str s2) (String.format s &s2)))
|
||||||
|
|
||||||
|
(defn str [t]
|
||||||
|
(match @t
|
||||||
|
(Integer i) (str i)
|
||||||
|
(Floating f) (str f)
|
||||||
|
(Str s) (str s)))
|
||||||
)
|
)
|
||||||
|
|
||||||
(hidden Tag)
|
(hidden Tag)
|
||||||
@@ -97,7 +103,7 @@ optional arguments.")
|
|||||||
)
|
)
|
||||||
|
|
||||||
(doc Option "is the option type. To construct an `Option`, please use
|
(doc Option "is the option type. To construct an `Option`, please use
|
||||||
[`int`](#int), [`float`](#float), or [`str](#str).")
|
[`int`](#int), [`float`](#float), or [`str`](#str).")
|
||||||
(deftype Option [
|
(deftype Option [
|
||||||
type- Tag
|
type- Tag
|
||||||
long String
|
long String
|
||||||
@@ -109,7 +115,7 @@ optional arguments.")
|
|||||||
])
|
])
|
||||||
|
|
||||||
(doc Parser "is the parser type. To construct a `Parser`, please use
|
(doc Parser "is the parser type. To construct a `Parser`, please use
|
||||||
[`new](#new).")
|
[`new`](#new).")
|
||||||
(deftype Parser [
|
(deftype Parser [
|
||||||
description String
|
description String
|
||||||
options (Array Option)
|
options (Array Option)
|
||||||
@@ -265,7 +271,7 @@ optional arguments.")
|
|||||||
(Option.long arg) (Option.short arg) (Option.description arg)))
|
(Option.long arg) (Option.short arg) (Option.description arg)))
|
||||||
(when @(Option.required? arg) (IO.print " REQUIRED"))
|
(when @(Option.required? arg) (IO.print " REQUIRED"))
|
||||||
(when (Maybe.just? (Option.default arg))
|
(when (Maybe.just? (Option.default arg))
|
||||||
(IO.print &(fmt " (default: %s)" &(Maybe.unsafe-from @(Option.default arg)))))
|
(IO.print &(fmt " (default: %s)" &(str &(Maybe.unsafe-from @(Option.default arg))))))
|
||||||
(match @(Option.options arg)
|
(match @(Option.options arg)
|
||||||
(Maybe.Just o)
|
(Maybe.Just o)
|
||||||
(IO.print &(fmt " (options: %s)" &(join ", " &(Array.copy-map &str &o))))
|
(IO.print &(fmt " (options: %s)" &(join ", " &(Array.copy-map &str &o))))
|
||||||
@@ -309,6 +315,7 @@ mesage is empty, `--help` was requested. If you don’t want to provide a
|
|||||||
(do
|
(do
|
||||||
(set! res (Result.Error (fmt "Unexpected argument: %s" x)))
|
(set! res (Result.Error (fmt "Unexpected argument: %s" x)))
|
||||||
(break)))))
|
(break)))))
|
||||||
|
(when (Result.success? &res)
|
||||||
(foreach [o options]
|
(foreach [o options]
|
||||||
(cond
|
(cond
|
||||||
(and @(Option.required? o)
|
(and @(Option.required? o)
|
||||||
@@ -328,7 +335,7 @@ mesage is empty, `--help` was requested. If you don’t want to provide a
|
|||||||
&(CmdMap.get &values (Option.long o))
|
&(CmdMap.get &values (Option.long o))
|
||||||
&(join ", " &(Array.copy-map &str &opts)))))
|
&(join ", " &(Array.copy-map &str &opts)))))
|
||||||
(break))))
|
(break))))
|
||||||
()))
|
())))
|
||||||
(match res
|
(match res
|
||||||
(Result.Success _) (Result.Success (CmdMap.to-map &values))
|
(Result.Success _) (Result.Success (CmdMap.to-map &values))
|
||||||
(Result.Error x) (Result.Error x))))
|
(Result.Error x) (Result.Error x))))
|
||||||
|
@@ -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.1")
|
<pre><code class="language-clojure">(load "https://veitheller.de/git/carpentry/cli@0.0.2")
|
||||||
|
|
||||||
(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.1")
|
<pre><code class="language-clojure">(load "https://veitheller.de/git/carpentry/cli@0.0.2")
|
||||||
</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
|
||||||
@@ -82,7 +82,7 @@ optional arguments.</p>
|
|||||||
</span>
|
</span>
|
||||||
<p class="doc">
|
<p class="doc">
|
||||||
<p>is the option type. To construct an <code>Option</code>, please use
|
<p>is the option type. To construct an <code>Option</code>, please use
|
||||||
<a href="#int"><code>int</code></a>, <a href="#float"><code>float</code></a>, or <a href="#str">`str</a>.</p>
|
<a href="#int"><code>int</code></a>, <a href="#float"><code>float</code></a>, or <a href="#str"><code>str</code></a>.</p>
|
||||||
|
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
@@ -103,7 +103,7 @@ optional arguments.</p>
|
|||||||
</span>
|
</span>
|
||||||
<p class="doc">
|
<p class="doc">
|
||||||
<p>is the parser type. To construct a <code>Parser</code>, please use
|
<p>is the parser type. To construct a <code>Parser</code>, please use
|
||||||
<a href="#new">`new</a>.</p>
|
<a href="#new"><code>new</code></a>.</p>
|
||||||
|
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
Reference in New Issue
Block a user