Created
December 19, 2010 22:48
-
-
Save amalloy/747785 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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