Automatically load methods for other leiningen.vcs systems.

This commit is contained in:
Phil Hagelberg 2014-05-23 20:58:25 -07:00
parent 47dc18aafa
commit ec45757459
2 changed files with 18 additions and 0 deletions

View file

@ -262,6 +262,17 @@ See [S3 wagon private](https://github.com/technomancy/s3-wagon-private) or
[lein-webdav](https://github.com/tobias/lein-webdav) for full examples of
plugins using this technique.
## VCS Methods
Leiningen ships with a `vcs` task which performs a handful of
release-related version control tasks via multimethods. Out of the box
it contains implementations for Git, but plugins can add support for
more systems by including a `leiningen.vcs.$SYSTEM` namespace. All
namespaces under the `leiningen.vcs.` prefix will be loaded when the
`vcs` task is invoked. These namespaces should simply define methods
for the `defmulti`s in `leiningen.vcs` that invoke the specific
version control system.
## Requiring Plugins
To use a plugin in your project, just add a `:plugins` key to your project.clj

View file

@ -1,5 +1,6 @@
(ns leiningen.vcs
(:require [clojure.java.io :as io]
[bultitude.core :as b]
[leiningen.core.eval :as eval]
[leiningen.core.main :as main]))
@ -46,9 +47,15 @@
(defn- not-found [subtask]
(partial #'main/task-not-found (str "vcs " subtask)))
(defn- load-methods []
(doseq [n (b/namespaces-on-classpath :prefix "leiningen.vcs.")]
(swap! supported-systems conj (keyword (last (.split (name n) "\\."))))
(require n)))
(defn ^{:subtasks [#'push #'tag]} vcs
"Interact with the version control system."
[project subtask & args]
(load-methods)
(let [subtasks (:subtasks (meta #'vcs) {})
[subtask-var] (filter #(= subtask (name (:name (meta %)))) subtasks)]
(apply (or subtask-var (not-found subtask)) project args)))