Skip to content

Instantly share code, notes, and snippets.

@lancepantz
Created September 10, 2010 23:33
Show Gist options
  • Save lancepantz/574555 to your computer and use it in GitHub Desktop.
Save lancepantz/574555 to your computer and use it in GitHub Desktop.
(defn get-env []
(or (first (:env *opts*))
(get *config* "env")))
(defn create [port f & commands]
(let [commands (apply hash-map commands)]
(server-socket/create-server port
(fn [ins outs]
(binding [*in* (LineNumberingPushbackReader. (InputStreamReader. ins))
*out* (OutputStreamWriter. outs)
*err* (PrintWriter. #^OutputStream outs true)
*ins* ins
*outs* (PrintStream. outs)]
(try
(let [form (read), vars (read)]
(clojure.main/with-bindings
(set! *command-line-args* (:args vars))
(set! *warn-on-reflection* (:warn-on-reflection *project*))
(binding [*vars* vars
*pwd* (:pwd vars)
*shell-env* (:shellenv vars)
*opts* (:opts vars)
*script* (:script vars)
*env* (get-env)]
(println "project:" *project*)
(print "\n")
(println "config:" *config*)
(print "\n")
(println "opts" *opts*)
(print "\n")
(println "env0:" (get-env))
(if (keyword? form)
(when-let [command (or (commands form) (default-commands form))]
(command))
(f form)))))
(catch Throwable e
(print-stacktrace e)
(when (fatal? e) (System/exit 1))))))
0 (InetAddress/getByName "localhost"))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment