(coerce s f)
Coerce string s
using f
. Does not coerce when s
is not a string.
f
may be a keyword (:boolean
, :int
, :double
, :symbol
,
:keyword
) or a function. When f
return nil
, this is
interpreted as a parse failure and throws.
Coerce string `s` using `f`. Does not coerce when `s` is not a string. `f` may be a keyword (`:boolean`, `:int`, `:double`, `:symbol`, `:keyword`) or a function. When `f` return `nil`, this is interpreted as a parse failure and throws.
(coerce-vals m mapping)
Coerce vals of map m
using mapping
, a map of keys to functions.
Uses coerce
to coerce values.
Coerce vals of map `m` using `mapping`, a map of keys to functions. Uses `coerce` to coerce values.
(parse-args args)
(parse-args args opts)
Parse the command line arguments args
, a seq of strings.
Expected format: ["cmd_1" ... "cmd_n" ":k_1" "v_1" .. ":k_n" "v_n"]
.
Instead of a leading :
either --
or -
may be used as well.
Return value: a map of :cmds
and :opts
Supported options:
:coerce
: a map of keys to coercion functions that will be applied to parsed :opts
. See coerce-vals
.:aliases
: a map of short names to long names.Examples:
(parse-args ["foo" ":bar" "1])
;; => {:cmds ["foo"] :opts {:bar "1"}}
(parse-args [":b" "1] {:aliases {:b :bar} :coerce {:bar parse-long}})
;; => {:cmds [] :opts {:bar 1}}
Parse the command line arguments `args`, a seq of strings. Expected format: `["cmd_1" ... "cmd_n" ":k_1" "v_1" .. ":k_n" "v_n"]`. Instead of a leading `:` either `--` or `-` may be used as well. Return value: a map of `:cmds` and `:opts` Supported options: - `:coerce`: a map of keys to coercion functions that will be applied to parsed `:opts`. See `coerce-vals`. - `:aliases`: a map of short names to long names. Examples: ``` clojure (parse-args ["foo" ":bar" "1]) ;; => {:cmds ["foo"] :opts {:bar "1"}} (parse-args [":b" "1] {:aliases {:b :bar} :coerce {:bar parse-long}}) ;; => {:cmds [] :opts {:bar 1}} ```
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close