New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Alternative to lein run
that can pass CLI options as-is
#374
Comments
What about something like this: (deftask run
"Resolves a function and applies it to arguments."
[a argv ARG [str] "The argument vector."
m main SYM sym "The symbol to resolve to obtain the -main fn."]
(with-pass-thru _
(require (symbol (namespace main)))
(eval `(~main ~@argv)))) Example usage:
|
That's a little too verbose for me. I pass a lot of arguments to |
What does Boot currently do with |
@seancorfield AFAIK boot uses |
Does it? Seems redundant since |
At least it's like that in the docs. https://github.com/boot-clj/boot#build-from-the-command-line see third code example. |
"The -- args below are optional" -- my emphasis there. Right now |
Boot doesn't actually do anything with boot -- show -e -- repl -h # okay: -- ignored but not when used as an argument: boot -- show -- -e repl -h # error: -e is not a task |
Currently we're using |
Interesting. And then use
|
Another option to consider in the meantime: (deftask run
[e expr EXPR edn "The expression to evaluate."]
(with-pass-thru _ (eval expr))) example:
and: (task-options!
run {:expr '(-main foo bar baz)}) |
You could get more fancy from there, requiring namespaces, adding options for cleanup, etc. |
What I'm currently going with (similar to above): (require 'namespace.core)
(require '[clojure.string :as s])
(deftask run
"Runs namespace with the given arguments"
[a args ARGS str "The arguments to pass the program"]
(apply namespace.core/-main (s/split args #" "))) Which can then be executed as |
Thanks @lachy-xe and @micha. I'm still using my hack, but I'll probably rewrite it to one of your suggestions. |
@alexander-yakushev I think I found a solution! How does this look to you? # note the spaces around the brackets!
$ boot -v watch [ run -x arg1 arg2 ] deploy In the command line above # brackets can be nested!
# - they're passed to the task as arguments
# - they must be balanced
$ boot -v watch [ run -x arg1 [ arg2 ] ] deploy The |
The # pass -w as an argument, not an option
$ boot -v watch [ run -x -- -w arg1 arg2 ] deploy And you can still use $ boot -v -- watch -- [ run -x -- -w arg1 arg2 ] -- deploy |
Feel free to reopen if this isn't a good solution :) |
It looks nice! How can I test it? |
+1, I like this. So just for clarification, could I define a (deftask run
[]
(let [[x y z] *args*]
(prn :x x :y y :z z))) Then, on the command line:
would result in this?
|
@daveyarwood yep! @alexander-yakushev this feature is in master branch now, if you want to build it. i'll try to release something on clojars though. |
I've seen this page which suggests that
lein run
translates to simply requiring and running the necessary function from the main namespace. I did that, but I also need to pass all the CLI arguments to-main
method. Parsing the args on Boot side is not an option because I want to distribute the application later as an uberjar. At the same time, there is no easy way to deliver CLI args from Boot to-main
without Boot processing them first. In the end, I had to add this hack to mybuild.boot
:And subsequently make a task like this:
Could we have something a little less hacky for this?
The text was updated successfully, but these errors were encountered: