Fork me on GitHub
#tools-deps
<
2022-05-03
>
imre09:05:20

Is there any way to make clojure -A:aliases not execute clojure.main with :main-opts in case they are defined in one of the aliases?

imre09:05:37

; clojure -Sdeps '{:aliases {:foo {:main-opts ["-e" ":hello"]}}}' -A:foo
WARNING: Use of :main-opts with -A is deprecated. Use -M instead.
:hello

imre09:05:12

I'd like to force this command to bring up a repl instead, are there any switches that can do that for me?

imre09:05:44

I'd like to do this without having to alter the alias. Say, there's an alias in a project that's usually used with -M to execute something, but I want to repl into the environment set up by that alias instead

imre10:05:51

something akin to a --strict that doesn't support deprecated usages

borkdude10:05:18

I think this will be the behavior in the future, as -A with main opts has been long deprecated. @U064X3EF3 mentioned that this might happen with the switch to 1.11 but it didn't

borkdude10:05:45

as a workaround I sometimes use a subshell + -Scp

borkdude10:05:26

clj -Scp $(clojure -Spath -A:...)

imre10:05:31

Ah, thank you, that's useful!

imre10:05:12

I'm guessing this didn't happen due to not wanting to break users, there might still be many of them around

borkdude10:05:36

The warning has been in there for a long while now

imre10:05:07

yeah, I keep purging those from just about any project I encounter in the wild

practicalli-johnny10:05:59

Alternatively, avoid using -A execution flag at all. I use Rebel Readline as my terminal REPL, which uses a :main-opts to start the REPL process and terminal UI, so I can chain any aliases before the rebel alias and only the :main-opts from rebel is used. I get a much richer REPL UI experience too.. For example I can run rebel with kaocha to include the library and skip its :main-opts and just use the main-opts from :repl/rebel

clojure -M:env/dev:test/kaocha:repl/rebel
Aliases are defined in https://github.com/practicalli/clojure-deps-edn

imre11:05:04

Interesting, thanks for sharing

Alex Miller (Clojure team)12:05:49

I have been prepping a list of deprecations to remove, and that will happen in stages, but haven't started yet. The above will be one of the last things to change.

imre12:05:38

Would you consider an option to add something along the lines of a strict mode cli switch beforehand so as to provide a way to test whether stuff will continue working after deprecations?

Alex Miller (Clojure team)13:05:40

I'll think about it, but I am loathe to add options

imre13:05:11

Totally understandable

seancorfield17:05:47

@U08BJGV6E I've mostly taken to separating :main-opts into additional aliases, so I have clojure -M:test:runner for example but clj -A:test to start a REPL.

borkdude17:05:30

This is exactly what I'm using the -Scp workaround for

seancorfield17:05:32

(although, at this point, I've moved nearly all my actual test running into build.clj so clojure -T:build test tends to be how I run a test suite now)

seancorfield17:05:26

Aliases are designed to be composable so having a separation of concerns and the ability to combine them as needed is more idiomatic (you could argue this is a "feature").

imre18:05:33

Thanks for the tip, Sean. I also started doing that and perhaps this will nudge me to do more. It would help though if one could create an alias which is the merging of other aliases for brevity at the command line and to try and not break others' workflows

Alex Miller (Clojure team)18:05:10

I've been thinking about this area a lot recently

Alex Miller (Clojure team)18:05:34

so maybe an area of enhancement soon

imre18:05:23

sounds intriguing!