polylith
polylith copied to clipboard
Support for custom commands
Is your feature request related to a problem? Please describe.
Add support for custom commands that could be executed by the poly
tool.
Describe the solution you'd like
The code for the different custom commands could be added to the poly
alias in the root deps.edn
file. The commands could be specified in workspace.edn
, e.g.:
{
:commands {"ls" com.mycompany.customcode.ls-command}
...
}
The function will take the internal workspace structure as input, like this:
(defn ls-command [workspace]
(let [args (-> workspace :user-input :args)
(apply sh args)))
It would be good also if these commands could support autocomplete, see issue #106.
Additional context
With this in place combined with support for autocomplete, the existing AOT compiled poly
command (or a native version of it, see issue #100) would be less attractive to use, because they would not support custom commands and even the native version would be outperformed in terms of startup time by the shell
command (which executes instantly).
I think this is the way to go, because then we could use the infrastructure that tools.deps.alpha
supports, where code can easily be added and executed as compiled code.
This would also allow people to contribute with new functionality to the poly
tool, and it would be good if it could list the available custom commands out there and give som guidance in how to "install" them (how to add them to the :poly
alias).
I think this is a great idea. I like that you'd register commands in workspace.edn
and just make the code available (however you wanted) on the classpath when invoking poly
.
How does this feature request compare to eg. using deps.edn alias executables or perhaps babashka tasks?
I think issue #106 (add shell
command) will change the way people work with the poly
tool during development in the future. You will start the built in shell
by executing clojure -M:poly shell
(or the shorter clojure -M:poly
, or as a tool clojure -Tpoly
) and then execute all the poly commands from there, to get instant feedback, support for autocomplete, and access to custom commands (issue #113) which can be "intelligent" and use information from the workspace, earlier typed in values, and support for autocomplete. It will be easy to "add" the source code needed for the new commands in the :poly
alias in ./deps.edn
(in any way you want, as long as it's supported by tools.deps) and then configure which commands to include in workspace.edn
. The goal is to support a really tight integration, where you easily can write your own commands in Clojure (and include commands written by others), configure how the autocomplete should work, and then only pay for the compilation hit once, when you start the shell
.
This is how I work today -- I initially wrote an interactive wrapper for poly
so I could start it up once and then just run create
, info
, test
, etc in a "Polylith REPL" and then I switched to the experimental interactive command that Joakim added. Really looking forward to the finished shell
command version!