Likewise. Windows 10 laptop with Powershell clj
installed. If you provide detailed instructions to attempt to repro, I'll try it...
with a main.clj like:
(ns main)
(defn -main
[& args]
(prn args))
running clj -i main.clj -m main -C:dev
should output ("-C:dev")
, but for windows users I expect it would output ("-C:", "dev")
.
This isn't quite the same, but I assume it's close enough.This is based on https://github.com/juxt/pack.alpha/issues/40#issuecomment-513471544 where the trace arguments is done like this https://github.com/juxt/pack.alpha/commit/417fc0ff0bc620a0dfaf5ce907436d5987e2fb59
PS C:\Users\seanc\clojure\dom> clj -m example.main -C:dev
(-C: dev)
PS C:\Users\seanc\clojure\dom> clj -m example.main '-C:dev'
(-C:dev)
I guess I'm not surprised that Windows needs the argument quoted really, given some of the weirdness of invoking PS scripts.
I guess the weird thing for me is that clj
works properly here? e.g. for clj -C:dev -m example.bar
out of curiosity, is this isolated to -C:
?
I'm still uncertain whether this is a powershell issue or a clj issue. I'm leaning towards the latter due to the fact that clj -C:dev
is parsed correctly (I'm assuming at least!)
It's to do with how main opts are passed through the running program.
PS doesn't know what you're doing so it parses the arguments for you -- the '
around it defeat that.
If you try to specify deps on the cmd line for clj
on PS, you need to triple up the double quotes around the version as I recall... it's definitely annoying.
Just so I'm certain though, clj -C:dev
results in the expected arguments going to the tdeps classpath calculator?
But clj -C :dev
is also valid.
For sure, but isn't what is written in most documentation.
I'm still confused as to why PS decides to parse arguments in [main-opt]
but not to clj
itself.
Right. But that's how it works on windows
It parses them in both cases
clj -C :dev
does not work on Mac / Linux but it does work on Windows
If you need -C:dev
passed into your code, you need '-C:dev'
it does work on mac/linux 🙂
are you saying that when using clj on windows, you always put the space between, e.g. clj -C :dev
?
When I type clj -C :dev
on Linux it doesn't work
I get Missing required argument for "-C ALIASES" on Linux
On windows it behaves exactly like clj -C:dev
Another Windows PS weirdness with quoting
PS C:\Users\seanc\clojure\dom> clj -Sdeps '{:deps {seancorfield/next.jdbc {:mvn/version """1.0.2"""}}}'
Downloading: seancorfield/next.jdbc/1.0.2/next.jdbc-1.0.2.pom from <https://repo.clojars.org/>
Downloading: seancorfield/next.jdbc/1.0.2/next.jdbc-1.0.2.jar from <https://repo.clojars.org/>
Clojure 1.10.1
user=> ^Z
PS C:\Users\seanc\clojure\dom> clj -Sdeps '{:deps {seancorfield/next.jdbc {:mvn/version "1.0.2"}}}'
Error while parsing option "--config-data {:deps {seancorfield/next.jdbc {:mvn/version 1.0.2}}}": java.lang.NumberFormatException: Invalid number: 1.0.2
PS C:\Users\seanc\clojure\dom>
Crazy CR/LF fixed!
I think it used to work on Linux. I agree it doesn't now. It's weird because it's just tools.cli in use.
No, not for the shell script itself (`clj`)
ah, there's preparsing. I see.
Just so I am 100% certain I understand. Is there something in clojure.ps1 that converts -A: foo
into -A :foo
? Or in windows is it just expected that users will type something different?
I didn't say -A: foo
is treated like -A :foo
.
I think there are several things at play here. clj
allows for the leading :
to be omitted on an alias.
(on all platforms)
So clj -Cdev
and clj -C:dev
are treated the same -- by clj
.
Windows PS parses -C:dev
as -C: dev
and then ignores the the :
after -C
so clj
sees -C dev
Ah!
so to match tdeps behavior in pack I need to also ignore the trailing :
somehow. :thinking_face:
That isn't tdeps behavior, per se.
I suspect that is PS script behavior.
if it was general PS script behavior, then it would also happen in the argument passed to pack.
But I thought you said that -C:aot
was being passed to pack as -C: aot
separately?
And the println
example shows that -C:dev
is parsed -- by PS -- as -C: dev
two separate args
It is being passed to pack separately. Did I misunderstand you, I thought you meant that it was general PS script behavior, do you mean that it's clojure ps script behavior?
I think it's PS behavior.
elseif ($arg.StartsWith('-R')) {
$aliases, $params = $params
if ($aliases) {
$ResolveAliases += ":$aliases"
}
}
The use of "StartsWith" makes this interesting 🙂But it doesn't matter with clj
because a) the leading :
can be omitted on aliases because that's what clj
does on all platforms and b) the trailing :
doesn't matter in the PS script for clj
.
Right. The clj
script only cares about the leading character.
I wonder if this works on windows: -Ranything foo
My point is that Windows users of clj
need to get used to "weird" quoting and already have to triple-quote versions in -Sdeps
for example.
PS C:\Users\seanc\clojure\dom> clj -Cand_anything_you_want dev
Error building classpath. Specified aliases are undeclared: [:dev]
PS C:\Users\seanc\clojure\dom>
cool, it works
Here's the difference between the -Sdeps
case and the -C:
case
clj -A:pack -m pack.main -C:foobar
^ works on win ^ does not work on win
The syntax works in one place, and not the other.@dominicm Because that cmd line is actually passed in as
clj -A: pack -m pack.main -C: foobar
It's absolutely consistent.
@seancorfield I know, but then clojure.ps1 massages it to -A:pack -m pack.main -C: foobar
So the massaging happens in one place but not the other. Which makes perfect sense now I've read the source.
No, it doesn't.
The PS script knows that the arguments are parsed and passed in separately.
PS C:\Users\seanc\clojure\dom> clj -Cand_anything_you_want:dev
Error building classpath. Specified aliases are undeclared: [:dev]
PS C:\Users\seanc\clojure\dom>
isn't that what this code does?
elseif ($arg.StartsWith('-R')) {
$aliases, $params = $params
if ($aliases) {
$ResolveAliases += ":$aliases"
}
}
If $arg
(`-R:`) starts with "-R", then get the next param "foobar" and add to the arguments, :foobar
The cmd line is parsed to clj -Cand_anything_you_want: dev
by Windows/PS.
The clj
shell script checks the first two chars (`-C`) and ignores the rest.
The shell script gets the next argument as the params for that.
So the issue is that tools.cli
does not accept -A: aot
as being the same as -A:aot
and so it parses it "incorrectly"...
So... as I said... Windows requires extra quoting to override the PS parsing... so that strings are passed into tools.cli
(in pack
) as-is.
Communicating on the internet is hard 😄 I am confident I understand the behavior now, and I think you do too. I guess my wording isn't communicating what I'm trying to say very well.
(and it's no surprise because you already have to say """1.0.2"""
to get "1.0.2"
in -Sdeps
on Windows)
on ps
My suggestion: tell Windows users of pack
to wrap options in '
quotes '
that makes copy/paste harder. I was actually thinking of implementing the ps1 code above at the java-level. By aliasing -R:
to -R
.
cmd users do not have this problem, though they have other ones
Any cmd user trying to run clj
is going to have even worse problems @carkh
We're not talking about lein
/`boot` here. Just clj
.
there is the unofficial command line, works great
I guess that's not my full reason. My full reason is that -Sdeps is an escaping issue with the shell, and if pack took a -Sdeps flag, it would work the same as clj's does. In this case, clj is "fixing" the options to make -R:foo
behave like it does on Linux, I'd like pack to look & feel like clj does.