コマンドラインコマンドとその引数を解析するためにマルチメソッドを使用しています。
(defmulti run (fn [command args] command))
(defmethod run :default
[& _]
...)
^{:args "[command]"}
(defmethod run "help"
[_ & [args]]
"Display command list or help for a given command"
...)
^{:args ""}
(defmethod run "version"
[_ & [args]]
"Print program's version"
...)
(defn -main
[& args]
(run (first args)
(next args)))
特定のメソッドのメタデータにアクセスしようとすると、clojure は以下を返しますnil
。
(meta ((methods run) "help"))