2 Commits
0.0.3 ... 0.0.4

Author SHA1 Message Date
10ba753ee3 cli: better to-map 2020-01-31 10:43:42 +01:00
0b185aa3b9 cli: add morphers 2020-01-30 16:43:58 +01:00
2 changed files with 60 additions and 6 deletions

View File

@@ -46,8 +46,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.")
(defmodule CLI
(hidden Type)
(private Type)
@@ -55,11 +55,16 @@ optional arguments.")
(Integer [Long])
(Floating [Double])
(Str [String])
(None [])
)
(defmodule Type
(defn = [a b]
(match @a
(None)
(match @b
(None) true
_ false)
(Integer i)
(match @b
(Integer j) (= i j)
@@ -84,6 +89,33 @@ optional arguments.")
(Integer i) (str i)
(Floating f) (str f)
(Str s) (str s)))
(defn to-int [x]
(match x
(Integer l) (Long.to-int l)
_ 0))
(defn to-long [x]
(match x
(Integer l) l
_ 0l))
(defn to-str [x]
(match x
(Str s) s
_ @""))
(defn to-float [x]
(match x
(Floating d) (Double.to-float d)
_ 0.0f))
(defn to-double [x]
(match x
(Floating d) d
_ 0.0))
(defn zero [] (None))
)
(hidden Tag)
@@ -203,7 +235,10 @@ optional arguments.")
(defn to-map [m]
(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)))
)

View File

@@ -61,10 +61,29 @@ manually.</p>
<p>Once youre 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
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
optional arguments.</p>
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">
@@ -197,7 +216,7 @@ optional arguments.</p>
defn
</div>
<p class="sig">
(λ [(Ref Parser)] (Result (Map String (Maybe Type)) String))
(λ [(Ref Parser)] (Result (Map String Type) String))
</p>
<pre class="args">
(parse p)