diff options
author | scgilardi <scgilardi@gmail.com> | 2008-12-10 01:31:13 +0000 |
---|---|---|
committer | scgilardi <scgilardi@gmail.com> | 2008-12-10 01:31:13 +0000 |
commit | 60b48644f49063132a93145538feca1543abe4e8 (patch) | |
tree | 0de1bfa2878ac5ce175f68412471ad36008545f3 /src/clojure/contrib | |
parent | bbdd1573060fa63bbfca13124aa4a97d07c7ad01 (diff) |
repl_ln: handle leading -i and --init args like clojure.main
Diffstat (limited to 'src/clojure/contrib')
-rw-r--r-- | src/clojure/contrib/repl_ln.clj | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/src/clojure/contrib/repl_ln.clj b/src/clojure/contrib/repl_ln.clj index 032456d5..82084c4c 100644 --- a/src/clojure/contrib/repl_ln.clj +++ b/src/clojure/contrib/repl_ln.clj @@ -144,15 +144,36 @@ (var-set Compiler/LINE (.getLineNumber *in*)) (read eof)))))) +(defn- process-inits + "Processes initial pairs of args of the form: + + -i filepath, or + --init filepath + + by loading the referenced files. Returns a seq of the remaining args." + [args] + (loop [[init filename & more :as args] args] + (if (#{"-i" "--init"} init) + (do + (clojure.main/load-script filename) + (recur more)) + args))) + +(defn- process-command-line + "Args are strings passed in from the command line. Loads any requested + init files and binds *command-line-args* to a seq of the remaining args" + [args] + (set! *command-line-args* (process-inits args))) + (defn- -main - "Main entry point, starts a repl and sets up *command-line-args* and - enters user namespace" + "Main entry point, starts a repl enters the user namespace and processes + command line args." [& args] (repl :init (fn [] (println "Clojure") - (set! *command-line-args* args) - (in-ns 'user)))) + (in-ns 'user) + (process-command-line args)))) ;; Public |