cli: fix printing of types and do not override previous errors
This commit is contained in:
47
cli.carp
47
cli.carp
@@ -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)
|
||||||
@@ -309,26 +315,27 @@ 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)))))
|
||||||
(foreach [o options]
|
(when (Result.success? &res)
|
||||||
(cond
|
(foreach [o options]
|
||||||
(and @(Option.required? o)
|
(cond
|
||||||
(not (CmdMap.set? &values (Option.long o))))
|
(and @(Option.required? o)
|
||||||
(do
|
(not (CmdMap.set? &values (Option.long o))))
|
||||||
(set! res (Result.Error (fmt "Required option missing: --%s" (Option.long o))))
|
(do
|
||||||
(break))
|
(set! res (Result.Error (fmt "Required option missing: --%s" (Option.long o))))
|
||||||
(Maybe.just? (Option.options o))
|
(break))
|
||||||
(let-do [opts (Maybe.unsafe-from @(Option.options o))]
|
(Maybe.just? (Option.options o))
|
||||||
(when (not (CmdMap.in? &values (Option.long o) &opts))
|
(let-do [opts (Maybe.unsafe-from @(Option.options o))]
|
||||||
(do
|
(when (not (CmdMap.in? &values (Option.long o) &opts))
|
||||||
(set! res
|
(do
|
||||||
(Result.Error
|
(set! res
|
||||||
(fmt
|
(Result.Error
|
||||||
"Option %s received an invalid option %s (Options are %s)"
|
(fmt
|
||||||
(Option.long o)
|
"Option %s received an invalid option %s (Options are %s)"
|
||||||
&(CmdMap.get &values (Option.long o))
|
(Option.long o)
|
||||||
&(join ", " &(Array.copy-map &str &opts)))))
|
&(CmdMap.get &values (Option.long o))
|
||||||
(break))))
|
&(join ", " &(Array.copy-map &str &opts)))))
|
||||||
()))
|
(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))))
|
||||||
|
Reference in New Issue
Block a user