Fork me on GitHub
#tools-deps
<
2022-12-04
>
Carsten Behring15:12:30

I came now several times to the question if and how clj aliases can be used to specify "init" type of code. So which should execute one time after Clojure is started. Specially if there is any form of support of having this specified in two aliases and it executes then one after the other. I am aware of "-e" options and the various ways to set the main-args and main-exec but it seem none of this is made for "init" code, which should run once and then give back control to Clojure.

Carsten Behring15:12:32

There is as well "user.clj", but this does not solve the problem that I want to "centralise" this init code and "switched it on" when needed

jjttjj16:12:07

You can use -e to call load-file in an alias

Carsten Behring16:12:03

How would it look like to use "-e" in an alias ? I have never seen this

Carsten Behring16:12:14

Maybe my question is too general. I am in the context of starting an nrepl, and would like to have an alias which contributes some code to be run after the nrepl is started... The nrepl I start in the same whay for every project (with an user wide clj alias), but for some projects I want that additional code is executed after (or before) repl is started.

Carsten Behring17:12:24

I checked it. It does indeed work if I only use one alias, namely the dev:repl the examples referes too. But I want combine 2 aliases, one starts nrepl and one runs cod, like this:

clj -M:repl/cider-refactor:dev/repl

Carsten Behring17:12:46

In this case, only the second is executed. The "-e" overrides whatever the first says to start. Switching order does not work neither, as JVM terminates after the "-e" code finishes.

Carsten Behring17:12:11

What would work, but I want to avoid, is a specific user.clj, which does both.

jjttjj17:12:28

Oh yeah only one main opts will get used. You could have the loaded file determine what to do based on some cli args it accepts

seancorfield17:12:32

@U7CAHM72M the repo that @U064UGEUQ linked to has code that starts nREPL/cider if it is in the classpath and runs other code which is what you'd have to do.

dergutemoritz10:12:30

@U7CAHM72M One way I've solved this in the past is to have a central user.clj which loads different namespaces based on JVM properties. You can then have aliases with different :jvm-opts setting these properties as these will be concatenated across all aliases. Maybe that's what you meant by your last comment anyway, tho 🙂