Skip to content
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

Support for custom commands #113

Open
tengstrand opened this issue Aug 20, 2021 · 4 comments
Open

Support for custom commands #113

tengstrand opened this issue Aug 20, 2021 · 4 comments
Assignees
Labels
improvement Not a bug but an improvement to overall user experience

Comments

@tengstrand
Copy link
Collaborator

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).

@tengstrand tengstrand added the improvement Not a bug but an improvement to overall user experience label Aug 20, 2021
@tengstrand tengstrand self-assigned this Aug 20, 2021
@seancorfield
Copy link
Sponsor Contributor

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.

@pithyless
Copy link

How does this feature request compare to eg. using deps.edn alias executables or perhaps babashka tasks?

@tengstrand
Copy link
Collaborator Author

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.

@seancorfield
Copy link
Sponsor Contributor

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
improvement Not a bug but an improvement to overall user experience
Projects
None yet
Development

No branches or pull requests

3 participants