clj-on-windows

For those interested in making clj on Windows https://dev.clojure.org/jira/browse/TDEPS-67. Also see https://github.com/littleli/scoop-clojure.
Rowan Barnard 2021-03-31T04:18:39.028700Z

Hi guys, I'm having problems with a command on Powershell in Windows, I am using Sean Corfield's deps file with his :new alias to create a new project with the Luminus template but here is the code I entered and the output I get:

clojure -X:new :template luminus :name Rowan/guestbook :output '"mywebapp"' :args '["+h2" "+http-kit"]'
Downloading: luminus/lein-template/maven-metadata.xml from clojars
Unrecognized options: +h2, +http-kit
Supported options are: +sqlite, +hoplon, +kee-frame, +immutant, +datomic, +site, +undertow, +h2, +auth-jwe, +reitit, +reagent, +jetty, +cljs, +graphql, +service, +sassc, +oauth, +swagger, +servlet, +auth, +war, +http-kit, +expanded, +cucumber, +aleph, +mongodb, +basic, +postgres, +boot, +mysql, +re-frame, +kibit, +shadow-cljs
Sean says that command is working fine for him on Mac and Linux via WSL so just wondering if anyone might know why it's not working on Windows?

seancorfield 2021-03-31T04:56:10.029800Z

I think it's a quoting issue, around how :args gets passed through the underlying template, but I don't know the ins and outs of Windows' quoting quirks so I couldn't help Rowan...

borkdude 2021-03-31T07:00:31.032100Z

Is it too late for clj to default to strings instead of symbols? That would solve above issue. Even in bash I find this quoting of strings awkward.

borkdude 2021-03-31T07:43:57.033300Z

@flyingpython This is an easy way to debug how args are parsed in a shell:

c:\Temp>bb -e "(prn *command-line-args*)" """foo"""
("\"foo\"")
bb.exe is babashka, a script interpreter for Clojure, but you can do this with normal Clojure as well. Apparently you have use use triple-quotes to preserve the quote in cmd.exe. I'll also try this in Powershell.

borkdude 2021-03-31T07:45:13.033600Z

This worked for me in Powershell:

PS C:\Users\borkdude> bb -e "(prn *command-line-args*)" '\"foo\"'
("\"foo\"")

Rowan Barnard 2021-03-31T07:48:12.033900Z

OK I'll give it a go thanks 🙂

thheller 2021-03-31T07:50:44.034400Z

pretty sure powershell uses backticks for escaping

thheller 2021-03-31T07:51:07.035Z

`"mwebacpp"` 
might be ok?

Rowan Barnard 2021-03-31T07:52:34.036500Z

Ah, how would I invoke this with Clojure? I tried clojure -M -e "(prn *command-line-args*)" '\"foo\"' but it doesn't work. I'm not that great at using commandline or Clojure yet 😅

borkdude 2021-03-31T07:52:41.036700Z

@thheller doesn't work for me:

PS C:\Users\borkdude> bb -e "(prn *command-line-args*)" `"mwebacpp"`
>>  ^C
it launches me into a shell

borkdude 2021-03-31T07:53:28.037100Z

@flyingpython What version of clojure do you have installed?

thheller 2021-03-31T07:54:08.038Z

oh right I remember something. I do have some quoting for this in some shadow-cljs code. let me see

thheller 2021-03-31T07:55:04.038400Z

oh yeah hehe. this wasn't fun at all to do manually https://github.com/thheller/shadow-cljs/blob/699ceec8a95f545581313be86bdcd778cf21575d/src/main/shadow/cljs/npm/cli.cljs#L378-L383

Rowan Barnard 2021-03-31T07:55:27.039100Z

The latest 1.10.3

Rowan Barnard 2021-03-31T07:57:50.040800Z

Ah OK so probably best to use Linux in WSL2 for Clojure like Sean recommended I think

borkdude 2021-03-31T07:58:15.041500Z

@flyingpython I don't know why this doesn't work with normal Clojure:

$ clojure -M -e "(prn *command-line-args*)" -- 1 2 3
("1" "2" "3")
Execution error (FileNotFoundException) at java.io.FileInputStream/open0 (FileInputStream.java:-2).
-- (No such file or directory)
Maybe because it tries to execute something as a file, while it shouldn't. Maybe a bug @alexmiller?

borkdude 2021-03-31T07:58:24.041900Z

Anyway, with babashka it works and it's fast so this might help for debugging

Rowan Barnard 2021-03-31T07:59:12.042700Z

OK there was a Scoop bucket I saw for babashka so I'll grab that

borkdude 2021-03-31T07:59:47.043Z

yeah, I added that scoop to the topic now

Rowan Barnard 2021-03-31T08:00:25.043800Z

Yeah the litteli scoop buckets are the ones I'm using to keep Java and Clojure up to date

Rowan Barnard 2021-03-31T08:02:30.045100Z

Thanks for the help @borkdude and thanks for that github link with your powershell replaces @thheller - those should help 🙂

borkdude 2021-03-31T08:04:16.045600Z

This is also a nice way of debugging:

PS>  bb -e "(map edn/read-string *command-line-args*)" '\"foo\"'
("foo")

thheller 2021-03-31T08:04:22.045800Z

"`\""two`\"""

thheller 2021-03-31T08:04:27.046Z

looks fun 🙂 maybe there is a better way to do this though 🙂

borkdude 2021-03-31T08:04:41.046200Z

I think mine looks simpler

borkdude 2021-03-31T08:06:15.047Z

ah, darn:

PS C:\Users\borkdude> bb -e "(map edn/read-string *command-line-args*)" '\"foo bar\"'
----- Error --------------------------------------------------------------------
Type:     java.lang.RuntimeException
Message:  EOF while reading string

(
it doesn't work with spaces in the string ;)

thheller 2021-03-31T08:06:30.047200Z

spaces also need to be escaped

borkdude 2021-03-31T08:07:58.047700Z

so this is basically a nightmare when it comes to -X and strings. I'm not sure if trying to map EDN onto shells was such a great idea.

borkdude 2021-03-31T08:10:32.048300Z

but for non-space strings, the solution in powershell is maybe doable... '\"foo\"', not pretty though

borkdude 2021-03-31T08:13:08.048900Z

I would argue that writing -main functions and applying a sprinkle of tools.cli isn't going away, -X isn't always obviously better / less verbose, it's just less work to maintain a command line API

Rowan Barnard 2021-03-31T08:19:41.050Z

Ah OK thanks that read-string looks handy too, though I'll put a reminder only to use non-space strings

borkdude 2021-03-31T10:55:10.050900Z

Babashka shebang in a .bat script! https://github.com/babashka/babashka/issues/766

alexmiller 2021-03-31T11:54:00.054Z

What are you expecting to happen? — is not something clojure.main understands

borkdude 2021-03-31T11:59:24.054200Z

I would expect remaining args to be bound to *command-line-args* but maybe that's my wrong understanding

borkdude 2021-03-31T11:59:47.054400Z

I'm sure you could argue otherwise

alexmiller 2021-03-31T13:03:17.054600Z

I think the clojure.main -h should lead you to not expect this to work

alexmiller 2021-03-31T13:07:07.054800Z

the command-line-args is designed to work with main-opts like -m or running a clj file, not to work with -e

borkdude 2021-03-31T14:48:40.055Z

ok