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-04-08T11:30:11.101900Z

@salkadam Yes if you look at the discussion here over the past little while as borkdude suggested you'll see I had the same issues trying to generate a Luminus template. You can see I found a way to invoke it with a commandline interface that doesn't involve passing strings: https://github.com/practicalli/clojure-deps-edn#create-new-projects-from-templates Use the classic approach there as opposed to the recommended approach (which is the same method you are already trying). Or alternatively you can install WSL2 as seancorfield suggests which lets you work on Linux from within Windows and shouldn't have the problems with passing the string arguments as they are displayed.

littleli 2021-04-08T13:08:18.103500Z

This works for me:

Projects $ clojure -X:project/new :template figwheel-main :name yourname/hello-world :args '[\"--reagent\"]'
Generating fresh figwheel-main project.
  To get started:
  -->  Change into the 'hello-world' directory
  -->  Start build with 'clojure -A:fig:build'
it's slightly different command, but it should not matter, rather the escaping example

littleli 2021-04-08T13:16:00.105700Z

so the command snippet from @jr0cket tutorial that @flyingpython suggested would look like this (example):

Projects $ clojure -X:project/new :template luminus :name practicalli/full-stack-app :args '[\"+http-kit\" \"+h2\"]'
Generating a Luminus project.

littleli 2021-04-08T13:27:03.107Z

I think I'll try to reach @jr0cket and ask to work with him if we can make the commands work properly on Windows.

borkdude 2021-04-08T13:30:56.108200Z

@ales.najmann note that the above works in PS but probably not in cmd.exe

borkdude 2021-04-08T13:31:51.109800Z

Perhaps the clj tool can be told to read the EDN args from a file? This would work in all shells. @alexmiller

practicalli-john 2021-04-08T13:32:14.109900Z

So if I understand correctly, the solution for Windows native command line is to escape the double quotes in the command. I can add a note about that to the Practicalli configuration.

littleli 2021-04-08T13:32:42.110100Z

Seems to be the case.

practicalli-john 2021-04-08T13:33:08.110300Z

Ah, according to Borkdude it's not the case for CMD.exe

littleli 2021-04-08T13:34:19.110500Z

Understand. I'll check. I just want to point out, you will likely won't be able to install Clojure on the machine without Powershell. So I would suggest to stick to a single way to use it. And I hope I'm not doing "works on my machine" kind of reply myself 😄

borkdude 2021-04-08T13:37:35.115400Z

As of now that is true because the CLI tools on Windows cornered themselves in some powershell function. This comes with trade offs like not being able to shell out to it from java without magic. Bb and deps.clj do not have these downsides and still work properly in cmd.exe. In the conversation above i showed how you can debug how cmd line args are parsed as EDN in both cmd.exe and powershell

borkdude 2021-04-08T13:38:40.116900Z

Bb comes with ‘bb clojure ...’ subcommand which should work identically to the Clojure CLI

practicalli-john 2021-04-08T13:40:44.117200Z

@salkadam if a template and set of option is used quite regularly, then a work-around could be to add a specific alias with the template and options already define. Calling this alias then reads the template options configuration from the ~/.clojure/deps.edn file. I appreciate this is not ideal.

borkdude 2021-04-08T13:45:47.118200Z

I guess you could also do that as a one off in your local deps.edn to bootstrap the project

littleli 2021-04-08T13:47:20.118300Z

That's interesting.

littleli 2021-04-08T13:51:33.118500Z

I mean I just wanted to provide positive, working examples. I'll have to take a look at babashka itself, at minimum what it can offer in this regard.

alexmiller 2021-04-08T13:53:47.119600Z

Well you can put :exec-args in your deps.edn

littleli 2021-04-08T13:54:29.119800Z

There are some ugly details. I would suggest not to use CMD.exe at all. Even if you execute cmd-clj it launches powershell, tooling etc. and then you're in complete escaping hell.

borkdude 2021-04-08T14:07:16.120100Z

true!

borkdude 2021-04-08T14:08:02.120500Z

So maybe that could be the recommended workaround for Windows

2021-04-08T18:21:17.121700Z

great suggestions, i will try those, the bigger issue for me is too convince us(IT) to move away from windows

2021-04-08T18:21:48.122100Z

that is more difficult compared to clj args

seancorfield 2021-04-08T19:31:15.122600Z

@salkadam I’m curious about whether your IT folks would allow using WSL2 on Windows?

2021-04-08T20:49:15.123900Z

that's possibly difficult too, i just added a new alias in ~/.clojure/deps.edn

:new-reagent {:extra-deps {seancorfield/clj-new {:mvn/version "1.1.293"}} :exec-fn clj-new/create :exec-args {:args ["--reagent"]}}
And it worked, so i am fine

👍 1
2021-04-08T20:49:17.124100Z

thanks

littleli 2021-04-08T23:16:07.125200Z

...to confuse things even more, this appear to be correct too, and likely even more correct according to Powershell escaping rules:

Projects $ clojure -X:project/new :template luminus :name practicalli/full-stack-app :args "[\`"+http-kit\`" \`"+h2\`"]"

Downloading: luminus/lein-template/maven-metadata.xml from clojars
Generating a Luminus project.

2021-04-08T23:24:34.126900Z

Not sure if this helps because I don't fully understand/remember how escaping works in powershell, but I have had luck with this kind of escaping to pass a string arg in powershell

clj -X my.ns/fn :str-arg '"""my-string"""'