cli: better to-map
This commit is contained in:
16
cli.carp
16
cli.carp
@@ -46,8 +46,8 @@ manually.
|
|||||||
Once you’re done building your flag structure, you can run `CLI.parse`. It
|
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
|
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
|
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
|
the long flag name to the value. The values are not in the map if they are
|
||||||
optional arguments.")
|
unset.")
|
||||||
(defmodule CLI
|
(defmodule CLI
|
||||||
(hidden Type)
|
(hidden Type)
|
||||||
(private Type)
|
(private Type)
|
||||||
@@ -55,11 +55,16 @@ optional arguments.")
|
|||||||
(Integer [Long])
|
(Integer [Long])
|
||||||
(Floating [Double])
|
(Floating [Double])
|
||||||
(Str [String])
|
(Str [String])
|
||||||
|
(None [])
|
||||||
)
|
)
|
||||||
|
|
||||||
(defmodule Type
|
(defmodule Type
|
||||||
(defn = [a b]
|
(defn = [a b]
|
||||||
(match @a
|
(match @a
|
||||||
|
(None)
|
||||||
|
(match @b
|
||||||
|
(None) true
|
||||||
|
_ false)
|
||||||
(Integer i)
|
(Integer i)
|
||||||
(match @b
|
(match @b
|
||||||
(Integer j) (= i j)
|
(Integer j) (= i j)
|
||||||
@@ -109,6 +114,8 @@ optional arguments.")
|
|||||||
(match x
|
(match x
|
||||||
(Floating d) d
|
(Floating d) d
|
||||||
_ 0.0))
|
_ 0.0))
|
||||||
|
|
||||||
|
(defn zero [] (None))
|
||||||
)
|
)
|
||||||
|
|
||||||
(hidden Tag)
|
(hidden Tag)
|
||||||
@@ -228,7 +235,10 @@ optional arguments.")
|
|||||||
|
|
||||||
(defn to-map [m]
|
(defn to-map [m]
|
||||||
(Array.reduce
|
(Array.reduce
|
||||||
&(fn [a v] (Map.put a (Pair.a (Pair.a v)) (Pair.b (Pair.b v))))
|
&(fn [a v]
|
||||||
|
(match @(Pair.b (Pair.b v))
|
||||||
|
(Maybe.Just e) (Map.put a (Pair.a (Pair.a v)) &e)
|
||||||
|
(Maybe.Nothing) a))
|
||||||
{}
|
{}
|
||||||
(values m)))
|
(values m)))
|
||||||
)
|
)
|
||||||
|
@@ -61,10 +61,29 @@ manually.</p>
|
|||||||
<p>Once you’re done building your flag structure, you can run <code>CLI.parse</code>. It
|
<p>Once you’re done building your flag structure, you can run <code>CLI.parse</code>. It
|
||||||
will not abort the program on error, instead it will tell you what went wrong
|
will not abort the program on error, instead it will tell you what went wrong
|
||||||
in a <code>Result.Error</code>. If it succeeds, the <code>Result.Success</code> contains a <code>Map</code> from
|
in a <code>Result.Error</code>. If it succeeds, the <code>Result.Success</code> contains a <code>Map</code> from
|
||||||
the long flag name to the value (the values are <code>Maybe</code>s, since they might be
|
the long flag name to the value. The values are not in the map if they are
|
||||||
optional arguments.</p>
|
unset.</p>
|
||||||
|
|
||||||
</div>
|
</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">
|
<div class="binder">
|
||||||
<a class="anchor" href="#Option">
|
<a class="anchor" href="#Option">
|
||||||
<h3 id="Option">
|
<h3 id="Option">
|
||||||
@@ -197,7 +216,7 @@ optional arguments.</p>
|
|||||||
defn
|
defn
|
||||||
</div>
|
</div>
|
||||||
<p class="sig">
|
<p class="sig">
|
||||||
(λ [(Ref Parser)] (Result (Map String (Maybe Type)) String))
|
(λ [(Ref Parser)] (Result (Map String Type) String))
|
||||||
</p>
|
</p>
|
||||||
<pre class="args">
|
<pre class="args">
|
||||||
(parse p)
|
(parse p)
|
||||||
|
Reference in New Issue
Block a user