Permalink
Browse files

only bind *command-line-args* in the run task, setting them to everyt…

…hing after the script name. add cake/*args* which stores the literal ARGV passed from the client script
  • Loading branch information...
1 parent f5a9e75 commit a5ddc8aea340e446c50190efc523d68b77796193 @ninjudd committed Jan 12, 2011
Showing with 16 additions and 14 deletions.
  1. +1 −0 bake/cake.clj
  2. +1 −1 bin/cake
  3. +4 −0 src/cake/file.clj
  4. +1 −1 src/cake/server.clj
  5. +1 −1 src/cake/tasks/deps.clj
  6. +4 −7 src/cake/tasks/eval.clj
  7. +2 −2 tasks.clj
  8. +2 −2 test/helpers.clj
View
1 bake/cake.clj
@@ -8,6 +8,7 @@
(def ^{:dynamic true} *context* (comment context))
(def ^{:dynamic true} *script* nil)
(def ^{:dynamic true} *opts* nil)
+(def ^{:dynamic true} *args* nil)
(def ^{:dynamic true} *pwd* nil)
(def ^{:dynamic true} *env* nil)
(def ^{:dynamic true} *vars* nil)
View
2 bin/cake
@@ -167,8 +167,8 @@ def parse_opts!
$opts = {}
ARGV[1..-1].each do |opt|
case opt
+ when "--" then break # stop parsing options
when /^@([-\w]+)$/ then add_opt!(:context, $1)
- when /^--$/ then break # Other REs will match, so check first.
when /^-(\w+)$/ then $1.split('').each {|c| add_opt!(c, '')}
when /^--?([-\w]+)=(.+)$/ then add_opt!($1, *$2.split(','))
when /^--?([-\w]+)$/ then add_opt!($1, "")
View
4 src/cake/file.clj
@@ -29,6 +29,10 @@
(defn global-file [& path]
(apply file *global-root* path))
+(defmacro with-root [root & forms]
+ `(binding [*root* ~root]
+ ~@forms))
+
(use 'uncle.core)
(defn cp [from to & opts]
View
2 src/cake/server.clj
@@ -56,12 +56,12 @@
(let [form (read), vars (read)]
(clojure.main/with-bindings
(reload)
- (set! *command-line-args* (:args vars))
(set! *warn-on-reflection* (:warn-on-reflection *project*))
(binding [*vars* vars
*pwd* (:pwd vars)
*env* (:env vars)
*opts* (:opts vars)
+ *args* (:args vars)
*script* (:script vars)]
(with-context (current-context)
(if (keyword? form)
View
2 src/cake/tasks/deps.clj
@@ -60,7 +60,7 @@
(defn install-subprojects []
(doseq [type [:dependencies :dev-dependencies], [dep opts] (*project* type)]
(when-let [path (subproject-path dep)]
- (binding [*root* path]
+ (with-root path
(cake-exec "install")))))
(defn extract-native [jars dest]
View
11 src/cake/tasks/eval.clj
@@ -1,7 +1,7 @@
(ns cake.tasks.eval
(:use cake
[cake.core :only [deftask bake]]
- [cake.file :only [file]]
+ [cake.file :only [with-root file]]
[bake.repl :only [repl]]))
(defn- read-form [string]
@@ -32,12 +32,9 @@
(deftask run #{compile}
"Execute a script in the project jvm."
{[script] :run}
- (bake [script (str
- (let [fscript (java.io.File. script)]
- (if (.isAbsolute fscript)
- fscript
- (file *pwd* script))))]
- (binding [*command-line-args* (-> *opts* :run rest)]
+ (bake [script (with-root *pwd* (str (file script)))
+ args (rest (drop-while (partial not= script) *args*))]
+ (binding [*command-line-args* args]
(load-file script))))
(deftask repl #{compile}
View
4 tasks.clj
@@ -53,14 +53,14 @@
snapshot? (snapshot? version)
version (if snapshot? (snapshot-timestamp version) version)
jar (format "jars/cake-%s.jar" version)]
- (binding [*root* (file "releases")]
+ (with-root (file "releases")
(git "pull"))
(ant Copy {:file (uberjarfile) :tofile (file "releases" jar)})
(spit (file "releases/current") version)
(when-not snapshot?
(ant Copy {:file (file "bin" "cake") :tofile (file "releases" "cake")})
(spit (file "releases/stable") version))
- (binding [*root* (file "releases")]
+ (with-root (file "releases")
(git "add" jar "cake" "current" "stable")
(git "commit" "--allow-empty" "-m" (format "'release cake %s'" (:version *project*)))
(git "push"))
View
4 test/helpers.clj
@@ -1,11 +1,11 @@
(ns helpers
(:use cake
- [cake.file :only [file]]
+ [cake.file :only [file with-root]]
[uncle.core :only [in-project]]
[clojure.java.shell :only [sh with-sh-dir]]))
(defn in-test-project [f]
- (binding [*root* (file "examples/test")]
+ (with-root (file "examples/test")
(in-project *outs* (f))))
(defn cake [& args]

0 comments on commit a5ddc8a

Please sign in to comment.