Skip to content

Instantly share code, notes, and snippets.

@amalloy
Created December 19, 2010 22:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amalloy/747785 to your computer and use it in GitHub Desktop.
Save amalloy/747785 to your computer and use it in GitHub Desktop.
(defn getopt-map
"Turn an option seq into a map of keyword=>[values] pairs. If
=> (getopt-map (getopt-seq nil \"ab:c::d\" (into-array String [\"-ab\" \"10\"])))
{:b [\"10\"], :a [nil]}
=> (getopt-map (getopt-seq nil \"ab:c::d\" (into-array String [\"-ab\" \"10\" \"-b\" \"1\"])))
{:b [\"10\" \"1\"], :a [nil]}"
[[opt-seq non-opts]]
(assoc
(reduce
(fn [m [opt arg]]
(update-in m [opt]
(fnil conj []) arg))
{} opt-seq)
:getopt/more non-opts))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment