Pass arguments to f in change task through the reader.
This means that you can use non-strings as args in the change task, but it requires double-quoting when you do want strings.
This commit is contained in:
parent
dd7447544b
commit
b1a07d03ec
4 changed files with 18 additions and 14 deletions
|
@ -231,7 +231,7 @@ You can use the `lein-pprint` plugin to see the default value of `:release-tasks
|
||||||
```
|
```
|
||||||
$ lein pprint :release-tasks
|
$ lein pprint :release-tasks
|
||||||
[["vcs" "assert-committed"]
|
[["vcs" "assert-committed"]
|
||||||
["change" "version" "leiningen.release/bump-version" "release"]
|
["change" "version" "leiningen.release/bump-version" "\"release\""]
|
||||||
["vcs" "commit"]
|
["vcs" "commit"]
|
||||||
["vcs" "tag"]
|
["vcs" "tag"]
|
||||||
["deploy"]
|
["deploy"]
|
||||||
|
@ -247,7 +247,7 @@ want to automatically bump the version in `project.clj`:
|
||||||
```clojure
|
```clojure
|
||||||
:release-tasks [["vcs" "assert-committed"]
|
:release-tasks [["vcs" "assert-committed"]
|
||||||
["change" "version"
|
["change" "version"
|
||||||
"leiningen.release/bump-version" "release"]
|
"leiningen.release/bump-version" "\"release\""]
|
||||||
["vcs" "commit"]
|
["vcs" "commit"]
|
||||||
["vcs" "tag"]
|
["vcs" "tag"]
|
||||||
["deploy"]]
|
["deploy"]]
|
||||||
|
|
|
@ -189,7 +189,7 @@
|
||||||
;; If these change, be sure to update release docstring and DEPLOY.md
|
;; If these change, be sure to update release docstring and DEPLOY.md
|
||||||
:release-tasks ^:top-displace [["vcs" "assert-committed"]
|
:release-tasks ^:top-displace [["vcs" "assert-committed"]
|
||||||
["change" "version"
|
["change" "version"
|
||||||
"leiningen.release/bump-version" "release"]
|
"leiningen.release/bump-version" "\"release\""]
|
||||||
["vcs" "commit"]
|
["vcs" "commit"]
|
||||||
["vcs" "tag"]
|
["vcs" "tag"]
|
||||||
["deploy"]
|
["deploy"]
|
||||||
|
|
|
@ -32,8 +32,7 @@
|
||||||
(= "set" f) (constantly (first args))
|
(= "set" f) (constantly (first args))
|
||||||
(string? f) (or (utils/require-resolve (symbol f))
|
(string? f) (or (utils/require-resolve (symbol f))
|
||||||
(fail-argument! (str "Unable to resolve " f)))
|
(fail-argument! (str "Unable to resolve " f)))
|
||||||
:else (fail-argument!
|
:else (fail-argument! (str f " is not a function.")))]
|
||||||
(str "Expected " f " to implement or reference an IFn")))]
|
|
||||||
#(apply f % args)))
|
#(apply f % args)))
|
||||||
|
|
||||||
;;; Maven convention helpers
|
;;; Maven convention helpers
|
||||||
|
@ -147,12 +146,15 @@
|
||||||
;;; Public API
|
;;; Public API
|
||||||
|
|
||||||
(defn change-string
|
(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]
|
[project-str key-or-path f & args]
|
||||||
(let [f (collapse-fn f args)
|
(let [f (collapse-fn f args)
|
||||||
path (normalize-path key-or-path)
|
path (normalize-path key-or-path)
|
||||||
proj (parse-project project-str)]
|
proj (parse-project project-str)]
|
||||||
(sj/str-pt
|
(sj/str-pt
|
||||||
;; TODO: support 'magic' keys within nested scope also
|
|
||||||
(condp = path
|
(condp = path
|
||||||
[:version] (update-version proj f)
|
[:version] (update-version proj f)
|
||||||
[:name] (update-name 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:
|
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
|
When called programmatically, you may pass a coll of keywords for the
|
||||||
first arg or an actual function for the second.
|
first arg or an actual function for the second.
|
||||||
|
|
||||||
Note that this task reads the project.clj file from disk rather than
|
All the arguments to f are passed through the reader, so double quoting is
|
||||||
honoring the project map, so profile merging or `update-in` invocations
|
necessory to use strings. Note that this task reads the project.clj file
|
||||||
will not effect it."
|
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]
|
[project key-or-path f & args]
|
||||||
;; cannot work with project map, want to preserve formatting, comments, etc
|
;; cannot work with project map, want to preserve formatting, comments, etc
|
||||||
(let [project-file (io/file (:root project) "project.clj")
|
(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))))
|
(spit project-file (apply change-string source key-or-path f args))))
|
||||||
|
|
|
@ -32,7 +32,7 @@
|
||||||
a map of the version incremented in the level argument. Add qualifier unless
|
a map of the version incremented in the level argument. Add qualifier unless
|
||||||
releasing non-snapshot."
|
releasing non-snapshot."
|
||||||
[{:keys [major minor patch qualifier]} level]
|
[{:keys [major minor patch qualifier]} level]
|
||||||
(case level
|
(case (keyword (name level))
|
||||||
:major {:major (inc major) :minor 0 :patch 0 :qualifier "SNAPSHOT"}
|
:major {:major (inc major) :minor 0 :patch 0 :qualifier "SNAPSHOT"}
|
||||||
:minor {:major major :minor (inc minor) :patch 0 :qualifier "SNAPSHOT"}
|
:minor {:major major :minor (inc minor) :patch 0 :qualifier "SNAPSHOT"}
|
||||||
:patch {:major major :minor minor :patch (inc patch) :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\"]
|
:release-tasks [[\"vcs\" \"assert-committed\"]
|
||||||
[\"change\" \"version\"
|
[\"change\" \"version\"
|
||||||
\"leiningen.release/bump-version\" \"release\"]
|
\"leiningen.release/bump-version\" \"\\\"release\\\"\"]
|
||||||
[\"vcs\" \"commit\"]
|
[\"vcs\" \"commit\"]
|
||||||
[\"vcs\" \"tag\"]
|
[\"vcs\" \"tag\"]
|
||||||
[\"deploy\"]
|
[\"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,
|
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
|
:minor, or :patch to indicate which semantic versioning level to bump. If none
|
||||||
is given, it defaults to :patch."
|
is given, it defaults to :patch."
|
||||||
([project] (release *level*))
|
([project] (release project (str *level*)))
|
||||||
([project level]
|
([project level]
|
||||||
(binding [*level* (read-string level)]
|
(binding [*level* (read-string level)]
|
||||||
(doseq [task (:release-tasks project)]
|
(doseq [task (:release-tasks project)]
|
||||||
|
|
Loading…
Reference in a new issue