diff --git a/doc/DEPLOY.md b/doc/DEPLOY.md index d334a797..fa58b84e 100644 --- a/doc/DEPLOY.md +++ b/doc/DEPLOY.md @@ -231,7 +231,7 @@ You can use the `lein-pprint` plugin to see the default value of `:release-tasks ``` $ lein pprint :release-tasks [["vcs" "assert-committed"] - ["change" "version" "leiningen.release/bump-version" "release"] + ["change" "version" "leiningen.release/bump-version" "\"release\""] ["vcs" "commit"] ["vcs" "tag"] ["deploy"] @@ -247,7 +247,7 @@ want to automatically bump the version in `project.clj`: ```clojure :release-tasks [["vcs" "assert-committed"] ["change" "version" - "leiningen.release/bump-version" "release"] + "leiningen.release/bump-version" "\"release\""] ["vcs" "commit"] ["vcs" "tag"] ["deploy"]] diff --git a/leiningen-core/src/leiningen/core/project.clj b/leiningen-core/src/leiningen/core/project.clj index 5ff160fe..8da9b89d 100644 --- a/leiningen-core/src/leiningen/core/project.clj +++ b/leiningen-core/src/leiningen/core/project.clj @@ -189,7 +189,7 @@ ;; If these change, be sure to update release docstring and DEPLOY.md :release-tasks ^:top-displace [["vcs" "assert-committed"] ["change" "version" - "leiningen.release/bump-version" "release"] + "leiningen.release/bump-version" "\"release\""] ["vcs" "commit"] ["vcs" "tag"] ["deploy"] diff --git a/src/leiningen/change.clj b/src/leiningen/change.clj index 3d2342dd..2688e299 100644 --- a/src/leiningen/change.clj +++ b/src/leiningen/change.clj @@ -32,8 +32,7 @@ (= "set" f) (constantly (first args)) (string? f) (or (utils/require-resolve (symbol f)) (fail-argument! (str "Unable to resolve " f))) - :else (fail-argument! - (str "Expected " f " to implement or reference an IFn")))] + :else (fail-argument! (str f " is not a function.")))] #(apply f % args))) ;;; Maven convention helpers @@ -147,12 +146,15 @@ ;;; Public API (defn change-string + "Programmatic functional access to project.clj-rewriting. + +See the `change` task function which handles reading and writing from disk as +well as turning string args into Clojure data; this function handles the rest." [project-str key-or-path f & args] (let [f (collapse-fn f args) path (normalize-path key-or-path) proj (parse-project project-str)] (sj/str-pt - ;; TODO: support 'magic' keys within nested scope also (condp = path [:version] (update-version proj f) [:name] (update-name proj f) @@ -173,16 +175,18 @@ as its first argument and the remaining task aruments as the rest. This will append \"-SNAPSHOT\" to the current version: - $ lein change version str \"-SNAPSHOT\" + $ lein change version str '\"-SNAPSHOT\"' When called programmatically, you may pass a coll of keywords for the first arg or an actual function for the second. -Note that this task reads the project.clj file from disk rather than -honoring the project map, so profile merging or `update-in` invocations -will not effect it." +All the arguments to f are passed through the reader, so double quoting is +necessory to use strings. Note that this task reads the project.clj file +from disk rather than honoring the project map, so profile merging or +`update-in` invocations will not effect it." [project key-or-path f & args] ;; cannot work with project map, want to preserve formatting, comments, etc (let [project-file (io/file (:root project) "project.clj") - source (slurp project-file)] + source (slurp project-file) + args (map read-string args)] (spit project-file (apply change-string source key-or-path f args)))) diff --git a/src/leiningen/release.clj b/src/leiningen/release.clj index 78e0b86b..46cd009f 100644 --- a/src/leiningen/release.clj +++ b/src/leiningen/release.clj @@ -32,7 +32,7 @@ a map of the version incremented in the level argument. Add qualifier unless releasing non-snapshot." [{:keys [major minor patch qualifier]} level] - (case level + (case (keyword (name level)) :major {:major (inc major) :minor 0 :patch 0 :qualifier "SNAPSHOT"} :minor {:major major :minor (inc minor) :patch 0 :qualifier "SNAPSHOT"} :patch {:major major :minor minor :patch (inc patch) :qualifier "SNAPSHOT"} @@ -57,7 +57,7 @@ The default list of release tasks is as follows: :release-tasks [[\"vcs\" \"assert-committed\"] [\"change\" \"version\" - \"leiningen.release/bump-version\" \"release\"] + \"leiningen.release/bump-version\" \"\\\"release\\\"\"] [\"vcs\" \"commit\"] [\"vcs\" \"tag\"] [\"deploy\"] @@ -83,7 +83,7 @@ is a task name and the rest are arguments to that task. The release task takes a single argument which should be one of :major, :minor, or :patch to indicate which semantic versioning level to bump. If none is given, it defaults to :patch." - ([project] (release *level*)) + ([project] (release project (str *level*))) ([project level] (binding [*level* (read-string level)] (doseq [task (:release-tasks project)]