Skip to content

Commit 5b1f4ba

Browse files
technomancystuarthalloway
authored andcommitted
Add support for running -main namespaces from clojure.main.
Signed-off-by: Stephen C. Gilardi <[email protected]> Signed-off-by: Stuart Halloway <[email protected]>
1 parent c1b9d42 commit 5b1f4ba

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/clj/clojure/main.clj

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,14 @@
258258
(prn)
259259
(System/exit 0))
260260

261+
(defn- main-opt
262+
"Run the -main function from a given namespace with arguments taken from
263+
the command line."
264+
[[_ main-ns & args] inits]
265+
(with-bindings
266+
(initialize args inits)
267+
(apply (ns-resolve (doto (symbol main-ns) require) '-main) args)))
268+
261269
(defn- script-opt
262270
"Run a script from a file, resource, or standard in with args and inits"
263271
[[path & args] inits]
@@ -284,6 +292,8 @@
284292
(or
285293
({"-r" repl-opt
286294
"--repl" repl-opt
295+
"-m" main-opt
296+
"--main" main-opt
287297
nil null-opt
288298
"-h" help-opt
289299
"--help" help-opt
@@ -322,6 +332,7 @@ java -cp clojure.jar clojure.main -i init.clj script.clj args...")
322332
main options:
323333
-r, --repl Run a repl
324334
path Run a script from from a file or resource
335+
-m, --main Run the -main function from a given namespace
325336
- Run a script from standard input
326337
-h, -?, --help Print this help message and exit
327338

0 commit comments

Comments
 (0)