tools-deps

Discuss tools.deps.alpha, tools.build, and the clj/clojure command-line scripts! See also #depstar #clj-new
borkdude 2020-10-30T21:04:51.158200Z

clojure -A:foo and clojure -M:foo without main-opts do the same thing: invoke a REPL with alias foo merged in -- right? Should -M:foo give a warning when you forget to supply main-opts in deps.edn maybe?

borkdude 2020-10-30T21:05:30.158600Z

or should -A not invoke a REPL since that's a clojure main invocation?

seancorfield 2020-10-30T21:15:32.159200Z

-A is for REPL invocation, according to the docs.

borkdude 2020-10-30T21:16:37.159800Z

so -A and -M overlap there I guess

seancorfield 2020-10-30T21:17:16.160300Z

I suspect that's a bit of a grey area given that :main-opts ["-r"] works to run a REPL, yes?

borkdude 2020-10-30T21:17:42.160800Z

well, I invoked an alias with -M while I forgot to provide :main-opts in deps.edn, so it invoked a REPL for me

borkdude 2020-10-30T21:17:57.161100Z

that's what prompted these maybe too far fetched thoughts

seancorfield 2020-10-30T21:18:51.161800Z

Yeah, I would sort of expect -M to at least give a warning if no :main-opts are provided. @alexmiller?

seancorfield 2020-10-30T21:19:54.162100Z

(! 651)-> fgrep :repl deps.edn 
  :repl {:main-opts ["-r"]}
(! 652)-> clj -M:repl
Clojure 1.10.1
user=> ^D
(! 653)-> clj -A:repl
WARNING: Use of :main-opts with -A is deprecated. Use -M instead.
Clojure 1.10.1
user=> ^D

seancorfield 2020-10-30T21:20:22.162700Z

(so, yeah, you can specify -r explicitly as a :main-opts item)

seancorfield 2020-10-30T21:21:49.163200Z

And the corollary:

(! 656)-> fgrep :dummy deps.edn 
  :dummy {}
(! 657)-> clj -M:dummy
Clojure 1.10.1
user=> ^D
(! 658)-> clj -A:dummy
Clojure 1.10.1
user=> ^D

alexmiller 2020-10-30T21:22:20.163600Z

you can supply main-opts on the command line, so -M does necessarily have to have :main-opts

alexmiller 2020-10-30T21:22:56.164Z

clj -M:my-alias-with-just-deps -m my.ns

seancorfield 2020-10-30T21:23:09.164400Z

Yes, but that's not the case we're discussing here.

alexmiller 2020-10-30T21:23:26.164600Z

well, what is?

seancorfield 2020-10-30T21:23:50.165300Z

See the two console examples I pasted. No command-line main-opts there.

alexmiller 2020-10-30T21:23:56.165500Z

-M invokes clojure.main. clojure.main does not require opts.

seancorfield 2020-10-30T21:25:23.166700Z

Fair enough. The "implicit" -r option 🙂

seancorfield 2020-10-30T21:26:11.167400Z

Why draw the distinction in the docs then that -A is for REPL execution?

borkdude 2020-10-30T21:26:30.168Z

because -M might not invoke a REPL when main-opts are given

alexmiller 2020-10-30T21:26:45.168400Z

really, it can be used to supply aliases for anything but it's only useful with REPL (because -M can be used for main and -X can be used for functions)

alexmiller 2020-10-30T21:27:18.169200Z

(and for allowing legacy stuff to continue working)

seancorfield 2020-10-30T21:27:20.169300Z

I guess this will become less confusing once -A stops executing :main-opts

alexmiller 2020-10-30T21:27:33.169500Z

yes

seancorfield 2020-10-30T21:28:16.170700Z

I'm curious how you plan to distinguish between -A for a REPL and -M executing clojure.main which might pick up other main opts?

borkdude 2020-10-30T21:28:19.170900Z

I would maybe prefer -M to trigger a warning when there is no :main-opts [] when you want to explicitly pass 0 arguments to main (i.e. invoke a REPL)

seancorfield 2020-10-30T21:29:13.171700Z

@borkdude I don't think that is going in the right direction...

alexmiller 2020-10-30T21:30:07.172300Z

what do I need to distinguish?

seancorfield 2020-10-30T21:30:35.172900Z

It seems that the only way to avoid continued confusion is to have clojure.main without arguments not start a REPL -- and require -r for that? 🙂

alexmiller 2020-10-30T21:30:55.173100Z

I don't follow

seancorfield 2020-10-30T21:31:02.173200Z

I mean: how is -A going to start a REPL without running clojure.main?

borkdude 2020-10-30T21:31:19.173500Z

never mind

alexmiller 2020-10-30T21:31:33.173600Z

it already does this

alexmiller 2020-10-30T21:31:43.173800Z

it invokes clojure.main

alexmiller 2020-10-30T21:31:47.174Z

that's an implementation detail

alexmiller 2020-10-30T21:32:28.174200Z

clj without -M or -X will start a repl, you let me figure out how to do that :)

alexmiller 2020-10-30T21:33:56.174800Z

yes?

seancorfield 2020-10-30T21:34:43.175500Z

I guess you could always have a new entry point for a REPL and have -A invoke that...?

alexmiller 2020-10-30T21:35:16.176100Z

I don't understand what problem is bothering you

seancorfield 2020-10-30T21:35:16.176200Z

(or rather "have the absence of -M and -X invoke that")

alexmiller 2020-10-30T21:35:41.176700Z

the absence of -M or -X means: invoke a repl

alexmiller 2020-10-30T21:36:09.177100Z

in other words, the default behavior of clj is: invoke a repl

seancorfield 2020-10-30T21:36:09.177200Z

(! 659)-> clj -A:dummy -r
WARNING: When invoking clojure.main, use -M
Clojure 1.10.1
user=> ^D

alexmiller 2020-10-30T21:36:53.177900Z

ok, you're outside the bounds of documented behavior

alexmiller 2020-10-30T21:37:13.178300Z

that's legacy support

seancorfield 2020-10-30T21:37:19.178500Z

-r is a documented main-opt that causes clojure.main to start a REPL, isn't it?

alexmiller 2020-10-30T21:37:46.179200Z

yes, but when we stop accepting main opts outside of -M, that's no longer a thing

alexmiller 2020-10-30T21:38:10.180Z

there may be some other set of accepted arguments in the repl case that have nothing to do with clojure.main

seancorfield 2020-10-30T21:38:13.180100Z

OK, so there will need to be a change in the behavior of clojure.main at some point to "fix" this?

alexmiller 2020-10-30T21:38:18.180300Z

no

seancorfield 2020-10-30T21:38:29.180800Z

clojure.main's help says

-r, --repl          Run a repl

alexmiller 2020-10-30T21:38:29.180900Z

"clj starting a repl" is distinct from clojure.main

alexmiller 2020-10-30T21:39:01.181200Z

yes, the mechanism clj currently uses to start a repl is clojure.main

alexmiller 2020-10-30T21:39:07.181400Z

but that's an implementation detail

seancorfield 2020-10-30T21:39:40.182300Z

So there will be a non-`clojure.main` entry point that clj can use to start a REPL?

seancorfield 2020-10-30T21:39:53.182800Z

(otherwise this confusion is going to continue)

alexmiller 2020-10-30T21:40:05.183100Z

what I'm saying is - I am promising clj will start a repl. the end.

alexmiller 2020-10-30T21:40:34.183400Z

and I'm promising that clj -M will run clojure.main

alexmiller 2020-10-30T21:40:55.184100Z

and that clj -X will invoke a function with a map

seancorfield 2020-10-30T21:41:05.184500Z

but you're not promising that clojure.main will not support -r at some future point :rolling_on_the_floor_laughing:

alexmiller 2020-10-30T21:41:32.184900Z

there are no plans to make clojure.main do anything different than what it does now

alexmiller 2020-10-30T21:42:52.185900Z

in the before times, clj always ran clojure.main. that is no longer the model

alexmiller 2020-10-30T21:43:22.186500Z

the new model is: • by default, run a repl • with -M, run clojure.main • with -X, execute a function with a map

alexmiller 2020-10-30T21:43:40.186800Z

and "run a repl" does not say anything about clojure.main

alexmiller 2020-10-30T21:45:29.188300Z

if you want to explicitly run clojure.main to run a repl, then clj -M or clj -M -r will do that

seancorfield 2020-10-30T21:45:44.188600Z

The confusion arises because the docs talk about "using -A (for REPL invocation)" when it still runs :main-opts!

alexmiller 2020-10-30T21:46:17.189200Z

well, we're in a bridge period between the two models

seancorfield 2020-10-30T21:46:31.189500Z

The sooner -A stops running :main-opts the better...

seancorfield 2020-10-30T21:46:58.190100Z

(mind you, even in that future world, I think @borkdude’s confusion will still be present, yes?)

alexmiller 2020-10-30T21:47:40.190800Z

if the confusion is that you can use clojure.main to run a repl, then yes

alexmiller 2020-10-30T21:48:40.191600Z

but it's easy to reason about if we are properly conveying that -M == run clojure.main

seancorfield 2020-10-30T21:48:45.191800Z

Argh, I'm being bitten by caching here 😞

seancorfield 2020-10-30T21:49:01.192100Z

(! 665)-> clj -Sforce -A
Missing required argument for "-A ALIASES"
(! 666)-> clj -Sforce -A -r
Missing required argument for "-A ALIASES"

seancorfield 2020-10-30T21:49:08.192300Z

^ That makes more sense.

seancorfield 2020-10-30T21:49:46.192900Z

-M and -X can be invoked without an alias, -A cannot.

alexmiller 2020-10-30T21:49:49.193Z

what does that have to do with caching? -A always requires an alias

seancorfield 2020-10-30T21:50:26.193500Z

Because this happened before I added -Sforce:

(! 662)-> clj -A
Clojure 1.10.1
user=> 
(! 663)-> clj -A -r
WARNING: When invoking clojure.main, use -M
Clojure 1.10.1
user=> ^D

seancorfield 2020-10-30T21:50:59.194Z

(note the command history numbers there!)

alexmiller 2020-10-30T21:51:10.194400Z

oh, well that's just a bug then

seancorfield 2020-10-30T21:54:46.195Z

Here's the repro for that bug:

(! 674)-> clj -Sforce -A
Missing required argument for "-A ALIASES"
(! 675)-> clj -A
Clojure 1.10.1
user=> 

alexmiller 2020-10-30T21:55:38.196100Z

fixed

1
borkdude 2020-10-30T21:56:09.196800Z

So the point earlier was: invoking -M with an alias that doesn't have :main-opts assumes that :main-opts is implicitly []. My question was: should this be less implicit, to avoid people ending up in a REPL when invoking -M with an alias that wasn't intended for -M at all

alexmiller 2020-10-30T21:57:16.197200Z

no, because :main-opts is not required

borkdude 2020-10-30T21:57:28.197400Z

ok

seancorfield 2020-10-30T21:58:17.199Z

@borkdude in the following :test has no :main-opts -- which of these would you expect to get warnings on and why?

(! 676)-> clj -Sforce -M:test -r
Clojure 1.10.1
user=> ^D
(! 677)-> clj -Sforce -A:test -r
WARNING: When invoking clojure.main, use -M
Clojure 1.10.1
user=> ^D
(! 678)-> clj -Sforce -M:test 
Clojure 1.10.1
user=> ^D
(! 679)-> clj -Sforce -A:test 
Clojure 1.10.1
user=> ^D

alexmiller 2020-10-30T21:58:20.199100Z

we could do something like - if you supplied -M but did not supply either :main-opts or main-opts on the command line, then either warn or error at that point

alexmiller 2020-10-30T21:58:51.200300Z

but honestly that's difficult to check right now due to where that knowledge of different parts of that is

borkdude 2020-10-30T21:58:53.200500Z

yes, that's exactly the case I was referring to

seancorfield 2020-10-30T21:58:54.200600Z

So -M wouldn't silently start a REPL unless you said -M -r ? I think that would be reasonable.

seancorfield 2020-10-30T21:59:08.201100Z

(if it could be checked)

alexmiller 2020-10-30T21:59:23.201500Z

and then -M means run clojure.main except for this one case where it fails

borkdude 2020-10-30T21:59:42.202Z

yeah, I guess it's not worth changing

seancorfield 2020-10-30T21:59:57.202300Z

(I'd be against an error there but I think a warning to remind folks might be worthwhile)

borkdude 2020-10-30T22:00:59.203800Z

main opts can be supplied on the command line, so not providing arguments means the same as :main-opts [], but you can also do that with -A which is the preferred way of invoking a REPL maybe

alexmiller 2020-10-30T22:01:11.204500Z

@seancorfield 1.10.1.735 if you want to check the -A thing

seancorfield 2020-10-30T22:01:17.204600Z

But I suspect there's no point trying to second-guess what folks will find confusing until after we have a CLI version where -A no longer uses :main-opts

seancorfield 2020-10-30T22:01:31.204900Z

@alexmiller Thanks for the swift fix!

alexmiller 2020-10-30T22:01:53.205Z

yes

seancorfield 2020-10-30T22:03:45.205500Z

(! 680)-> clj -Sforce -A
-A requires an alias
(! 681)-> clj -A
-A requires an alias
confirmed fixed!

alexmiller 2020-10-30T22:04:13.206100Z

I did not take the time to try on Windows, but it might already catch this case due to the different parsing. I'll check that before we get to a stable release

alexmiller 2020-10-30T22:04:46.206500Z

I'm shutting down, have a good Halloween weekend y'all

4