Welcome! Please see the About page for a little more info on how this works.

0 votes
in Clojure by

I'd like to run clojure -M -e "(compile 'foo.bar)" --some --args where foo.bar contains some code like so:

(require (slurp (first *command-line-args*)))

Which will dynamically include the additional namespaces based on some complex list of namespaces or something, .

But, --some in the example above is "lost" and clojure.main tries to read that as a path, as there's no way to "skip" main-opts right now. I've been cheating by passing in /dev/null which seems to work. Traditionally something like -- is used to solve this problem.

I had a poke at the source for clojure.main, and it does seem there's a "nil" option, but it's not documented and I can't figure out how to activate it!

1 Answer

0 votes

I think this is outside the scope of what clojure.main is trying to support. You have lots of options to solve this by writing a .clj file, or a main, etc.

edited by
The problem with writing  a main or a .clj file is that any requires of the script will not be compiled.  This problem also affects a .clj file loaded via `-i`.  But also, aren't `*command-line-args*` expressly there for init opts to read arguments?

~~There does seem to be a bug in clojure.main here: https://github.com/clojure/clojure/blob/30a36cbe0ef936e57ddba238b7fa6d58ee1cbdce/src/clj/clojure/main.clj#L558 as this opt can never be triggered.~~  I realize now why that's there.  It's a shame there's not an adjacent `"--"` as that would be perfect.