Fork me on GitHub
#tools-deps
<
2023-05-25
>
Eduardo Lopes21:05:59

Is there a similar feature in Clojure CLI to Leiningen :injections? I'm using clj -e but I'm wondering if init-opt can be achievable from deps.edn

seancorfield21:05:39

-e can be put in :main-opts in deps.edn but the specifics depend on exactly what you already have...

seancorfield21:05:56

Is this just to start a REPL?

seancorfield21:05:20

(~/clojure/repl)-(!2009)-> cat deps.edn
{:aliases
  {:repl
   {:main-opts ["-e" "(ns foo.bar)" "-r"]}}}

Thu May 25 14:09:54
(~/clojure/repl)-(!2010)-> clj -M:repl
foo.bar=>
☝️:skin-tone-2: does that help?

Eduardo Lopes21:05:36

Actually is a curiosity based on how githooks works, since we need to manually run git config core.hooksPath dir I can solve this on leiningen projects adding an injection like :injections [(require '[clojure.java.shell :refer [sh]]) (sh ....)] I'm assuming that any lein anything I run will setup githooks for me. So adding this to a specific alias may not solve 100%

Eduardo Lopes21:05:33

Maybe adding as injections is not the best solution but I always try to "translate" from leiningen to clojure cli what I'm doing

seancorfield21:05:58

With the CLI, you need an alias for this, or supply it on the command line. But you may be better off writing build.clj for the tasks you want to do since then you can run commands easily and compose things since "it's just code".

seancorfield21:05:34

I don't really understand your use case tho' -- you only need to run git config once for a given project, yes?

Eduardo Lopes21:05:30

Yes, was just an idea to avoid manually doing this each time you download and be part of an “invisible” process

Eduardo Lopes21:05:07

I think using makefile is better for this also, is just a brainstorming

seancorfield21:05:16

If you're interacting with git, I'd definitely suggest looking at tools.build since it has git functionality in its API. And then just do stuff via clojure -T:build <something> (like lein <something>) and it can do whatever you need...

seancorfield21:05:02

We have pretty much all our dev/test/CI tooling built around tools.build and build.clj at work -- and I use that approach with most of my OSS projects on GitHub too.

dpsutton21:05:13

if it’s just once you could do something like clj -X:dev dev/install-git-hooks and code it up yourself

Eduardo Lopes22:05:56

Yes, both solutions seems better by adding to a makefile. Another use case I remembered was a project using midje, when we executed eastwood and kibit the tests were running, since they load the files. The way to avoid this (don't know if it's the best solution either) was an injection :injections [(require 'clojure.test) (alter-var-root #'clojure.test/*load-tests* (constantly false))] in a linter profile, this could be 100% achievable with an alias on Clojure CLI. The difference is that leiningen allows an injection on the defproject root, which may solve some better use cases than the ones I'm bringing here 😅

Eduardo Lopes22:05:51

But thanks! I've learned a little more about clj cli with this conversation gratitude