Fork me on GitHub
#tools-deps
<
2018-12-01
>
pesterhazy17:12:57

Looks like clj main-opts don't compose. For example, I tried to define two aliases that both set main-opts: https://github.com/pesterhazy/advent2018/blob/e0f8fba23339052eb112958fed712da97c7c270b/deps.edn#L3

pesterhazy18:12:06

Unfortunately with clj -A:nrepl:in-ns, the -e (...) argument for the second alias overrides the -e (...) of the first

pesterhazy18:12:42

Is this intended behavior? Is there another way for an alias to execute code?

pesterhazy18:12:55

Note that clj -A:nrep -e (...) does work

dominicm18:12:52

Non composition is expected.

pesterhazy18:12:52

Those are two enhancements to clj that would make aliases more useful then: avoiding the need for Corfield Commas, and being able to stack side effects (like starting an nREPL server) on top of each other

alexmiller21:12:16

You can stack effects with -m - main args are appended to the end. But, there are other things going on in your example above (no support for -e aliases, ordering of -A vs other aliases, etc)

dominicm11:12:14

https://clojure.org/reference/deps_and_cli > If multiple -M alias maps are activated, only the last one will be used

pesterhazy11:12:54

so in this case it's better to use -M:alias1:alias2 than -A:alias1:alias2?

dominicm11:12:04

The former would have no meaning

dominicm11:12:24

Well, the former is equivalent to -M:alias2

pesterhazy11:12:34

Ok, I'll give that a try

dominicm11:12:32

I opened an nrepl issue to start a discussion about how this might work. I've not come up with anything good.

pesterhazy11:12:58

@U09LZR36F can you link to the issue?

dominicm12:12:35

I should update it to mention the actual problem statement

dominicm12:12:55

I did think about a main Hopper

dominicm12:12:47

A simple version could be put together in an afternoon

alexmiller14:12:24

sorry, I meant you could stack effects from last alias + command line, not across aliases. I think making ordering do stuff beyond that is too fragile

alexmiller14:12:39

the order of “last” should be unambiguous (but is currently not, and that’s a bug (https://dev.clojure.org/jira/browse/TDEPS-100 which may be irritating to fix)

alexmiller14:12:18

at some point, you are putting too much on CLJ and should recognize that you are writing a program and push this complexity into a Clojure program I think

alexmiller14:12:34

but I’m willing to consider that I’m wrong on that :)

dominicm15:12:36

It's a little bit complicated, because I think mains have been pushed as a common interface. But they don't compose exactly. But anything you want to do, can be done with jvm opts and a custom main.

pesterhazy21:12:21

clojure -Sdeps '{:aliases {:a1 {:main-opts ["-e" "(println,:a1)"]} :a2 {:main-opts ["-e" "(println,:a2)"]}}}' -Srepro -M:a1:a2
will print out only :a2

dominicm21:12:15

Best bet is a custom main, and use jvm opts to compose.

pesterhazy21:12:18

Also you can only ever specify one -m/--main option

pesterhazy21:12:09

To me, those two facts combined diminish the usefulness of aliases, because you often need to produce a side effect to make an alias effective

pesterhazy21:12:42

As an example, to start an nREPL server, you need to call nREPL's start-server function

dominicm21:12:46

Yep! This is a limitation from Clojure itself, inherited from Java. I've given this some thought, and I don't know what multiple mains look like. In parallel presumably?

pesterhazy21:12:48

So one person in the team uses nREPL so they, so they run,e e.g. clojure -M:nrepl

pesterhazy21:12:19

That to me is how composition of aliases would help - in different situations you can enable different sets of features

pesterhazy21:12:27

Using :main-opts with ["-e" "(do (require ...) (start-server))]" is a little crude but works-ish - except for the fact that main-opts don't compose

dominicm21:12:28

You can call functions, as long as they exit, but nrepl main doesn't, else it would be fairly useless as a main

pesterhazy21:12:32

If not through aliases, I'm not sure how I would accomplish the same thing

dominicm21:12:41

Edge has a workaround for this already, it looks at the system properties, and loads things based on flags there.

pesterhazy21:12:04

do jvm opts compose?

dominicm21:12:44

Yep! That's what I was trying to get across 😊

pesterhazy21:12:53

Gotcha. It seems a little arbitrary though that jvm-opts get concatenated, whereas main-opts are replaced

dominicm21:12:21

Jvm opts naturally concatenate in the underlying system. I think they're unordered. Main opts is talking about clojure's main-opts though. You wouldn't be able to do what you want with nrepl and other mains even if concatenation happened.

pesterhazy21:12:35

is the problem with concatenating main-opts that the ordering of different aliases is not well defined?

pesterhazy21:12:11

@U09LZR36F I guess your idea is to use an alias like

{:jvm-opts ["-Dclojure.run.foo=foo.core"]}
and then have a main that scans through system properties and calls those in some order?

dominicm22:12:46

@U06F82LES somrthing like that, yeah

dominicm22:12:50

@U06F82LES nrepl.main blocks forever. So rebel would not run afterwards.

pesterhazy22:12:51

nrepl.server/start-server doesn't block

dominicm22:12:54

You're thinking of clojure mains opts, I'm thinking of plain mains. My mistake.

dominicm22:12:15

I don't think you can pass -e and -m anyway.

alexmiller00:12:03

Something that we have discussed is a “start” option that would invoke an arbitrary function

pesterhazy18:12:29

Corfieldization is a fun exercise but a clearer way to achieve this effect would be great

dominicm18:12:58

The comma thing is a bug afaik

seancorfield20:12:33

I'm sure that if someone can come up with patches to the clojure shell script that eliminate Corfield, lots of people will be very happy. Me included.

dominicm21:12:19

Fixing it is difficult I would guess. You have to figure out how to generate properly escaped strings from edn.

seancorfield21:12:15

Mainly you need to be able to round-trip arbitrary strings from bash to file to bash again.

dpsutton21:12:54

Will the corfield comma work in a powershell implementation of clj?

alexmiller21:12:17

Sean’s description is pretty good, happy to have someone figure that out

alexmiller21:12:38

I suspect powershell is prob easier

dottedmag21:12:29

At least it's bash, not an arbitrary POSIX shell.

alexmiller21:12:16

One issue is with nested quotes, another is needing to write the second half in bash (first half is in Clojure)

dottedmag21:12:09

@alexmiller if you can give me an example of what needs to be done, I'll try to stretch my shell muscles.

alexmiller22:12:50

Sorry, boarding a flight but there is a ticket in TDEPS

seancorfield22:12:45

(there may be others but that's the first one I found)

seancorfield22:12:15

@dottedmag ^ yup, that seems to be the whole issue.

pesterhazy23:12:34

I’ll take a look as well