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-09T06:32:15.130200Z

Thanks, your string escaping example worked for me @ales.najmann Still it would be nice to have some kind of 'official' method/convention for doing this kind of thing on Windows.

littleli 2021-04-09T06:34:11.130300Z

Completely agree. At least this should be well documented. Positive, working examples needed.

Rowan Barnard 2021-04-09T06:35:55.130500Z

đź‘Ť

Rowan Barnard 2021-04-09T06:49:43.134Z

And I still think the commandline interface is easier to use as opposed to passing in the EDN as borkdude pointed out:

clojure -X:new :template luminus :name yourname/example.webapp :output '"mywebapp"' :args '["+http-kit" "+h2" "+reagent" "+auth"]'
clojure -M:project/new luminus practicalli/full-stack-app +http-kit +h2 +reagent +auth
Borkdude mentioned that one is easier for the user and one for the author, isn't there some way to get the benefits of both?

seancorfield 2021-04-09T16:29:28.139Z

The evolution path of the Clojure CLI and its support of tools you can run is toward -X and away from -M in general so I think folks need to get used to -X. It is a lot more flexible: with -M you only get one set of :main-opts (from the last alias specified that has it — it does not combine with other aliases); with -X you can spread :exec-args across multiple aliases and they compose (essentially via merge). Yes, it’s a bit of a pain on Powershell/cmd.exe but once you learn the quoting needed — a one-time cost — then you can pass any EDN that any tool could require. You’d have similar problems with -M-based tools that expected anything more than plain strings anyway (and you can only pass strings: all of the semantics of the tool have to be buried inside the tool, to parse a sequence of strings, and so the semantics of every tool is going to be unique).

borkdude 2021-04-09T16:31:36.140400Z

> toward -X and away from -M, it’s a bit of a pain on Powershell/cmd.exe In my opinion this is the "human interface on top of programmatic interface" without the human interface, a step back in command line UX for Clojure. I can see that -X is convenient for CLI authors: no need to think about the command line UX, but for users of a tool, it's more verbose and often just ugly.

borkdude 2021-04-09T16:33:12.141200Z

Having said that, it's probably a ship that has already sailed without any feedback from the community, a thing that just got dropped out of the sky.

seancorfield 2021-04-09T16:34:59.142600Z

I think that’s a mischaracterization: a lot of people have been asking for a more Clojuresque way of invoking code from the command-line for a long time — and various folks have built small -main wrappers that do that sort of parsing (from a sequence of strings to Clojure data).

borkdude 2021-04-09T16:35:36.143200Z

I think I have missed those requests then, I wasn't aware of those at all

seancorfield 2021-04-09T16:37:33.144800Z

A lot of the pain can be eased by -X-based tools accepting symbols for “strings” and calling str on them as needed. I’ve have to check in clj-new to see if :output is treated that way and, given that :args is passed directly to templates and they nearly all accept strings, I could make it accept symbols there and just mapv str over them…

seancorfield 2021-04-09T16:39:17.145Z

https://github.com/seancorfield/clj-new/issues/59

seancorfield 2021-04-09T16:41:44.145900Z

Currently only :name and :template accept symbols in place of strings, so implementing that issue will improve matters for Windows users.

borkdude 2021-04-09T16:42:56.146600Z

Just launch a REPL and call the damn function with normal args instead of using -X with awkward quoting, I'd say. This works uniformly across all OS-es.

borkdude 2021-04-09T16:49:23.147400Z

$ cat deps.edn
{:aliases {:new {:extra-deps {com.github.seancorfield/clj-new {:mvn/version "1.1.293"}}}}}
$ clj -A:new
Clojure 1.10.1
user=> (require 'clj-new)
nil
user=> (clj-new/create {:template 'luminus :name 'yourname/example.webapp :output "mywebapp" :args ["+http-kit" "+h2" "+reagent" "+auth"]})
Generating a Luminus project.
Just document that. No need to confuse people with weird -X shell stuff. I think this will save lots of people lots of time. Or write a decent CLI tool. That's my opinion. Didn't mean to come across impolite , but after having seen too many questions about this already, this is what I'm probably going to recommend to people going forward.

borkdude 2021-04-09T16:59:25.148400Z

Why deal with a shell if you can have a REPL anyway? ;)

seancorfield 2021-04-09T17:03:49.149100Z

You recommend what you want; I’ll continue to recommend what Nubank/Cognitect and the core Clojure folks suggest 🙂

borkdude 2021-04-09T17:11:06.150400Z

Yeah, it's a free world. But as a clarification: I mean, recommend over stuggling with string quoting if the user can't find a solution. Instead of looking up bash/powershell/cmd/cygwin/whatever string quoting, I'm just going to say: hey, launch a REPL and invoke the function. Since that's basically what -X is.

borkdude 2021-04-09T17:11:58.150900Z

> I’ll continue to recommend what Nubank/Cognitect and the core Clojure folks suggest Is recommending -X over -M an official recommendation from Cognitect/clojure CLI folks or is this just your preference?

alexmiller 2021-04-09T17:30:06.152100Z

I think we would say -X is preferred, but -M is not going away and obvs there are tradeoffs between clojure.main + string parsing / -X and edn quoting / -R and interactivity

seancorfield 2021-04-09T17:38:02.153500Z

@borkdude @flyingpython Could you update your clj-new alias to use version 1.1.297 and let me know if this command works as-is on Windows?

clojure -X:new :name rowan/example :template luminus :output mywebapp :args '[+http-kit +h2 +reagent +auth]'

seancorfield 2021-04-09T17:38:33.153600Z

-R? Do you mean -A?

alexmiller 2021-04-09T17:56:02.153800Z

sorry, meant repl (so yes -A)

borkdude 2021-04-09T18:44:49.154200Z

@seancorfield Powershell:

PS C:\Temp> cat .\deps.edn
{:aliases {:new {:extra-deps {com.github.seancorfield/clj-new {:mvn/version "1.1.293"}}}}}
PS C:\Temp> clojure -X:new :name rowan/example :template luminus :output mywebapp :args '[+http-kit +h2 +reagent +auth]'
No function found on command line or in :exec-fn

seancorfield 2021-04-09T18:45:27.154800Z

That’s because your :new alias is not set up correctly.

seancorfield 2021-04-09T18:46:00.155200Z

In your case clojure -X:new clj-new/create :name ... should work

seancorfield 2021-04-09T18:46:27.155600Z

Or add :exec-fn clj-new/create to your :new alias.

seancorfield 2021-04-09T18:47:18.156Z

@borkdude I appreciate you testing it for me 🙂

borkdude 2021-04-09T18:48:38.156500Z

PS C:\Temp> clojure -X:new :name rowan/example :template luminus :output mywebapp :args '[+http-kit +h2 +reagent +auth]'
Downloading: luminus/lein-template/maven-metadata.xml from clojars
Unrecognized options: +reagent, +h2, +auth, +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

borkdude 2021-04-09T18:49:03.157100Z

I guess this is something you could test yourself as well, since you're probably using Windows more than me, but I'd be happy to test it anyway

borkdude 2021-04-09T18:51:40.158Z

oh I guess I need to upgrade, my bad, will test again

seancorfield 2021-04-09T18:52:10.158600Z

I do all my Clojure dev on WSL2. I haven’t installed clojure on Powershell since I got my Surface Laptop 3.

seancorfield 2021-04-09T18:52:55.159400Z

(I haven’t installed anything under PS since I got this machine)

borkdude 2021-04-09T18:53:33.159800Z

It's only one scoop away, and for a maintainer of a widely used tool it might come in handy but whatever you want. This worked.

seancorfield 2021-04-09T18:54:12.160Z

Much appreciated.

seancorfield 2021-04-09T18:54:35.160600Z

Ya, I don’t even have scoop installed. I pretty much haven’t started up PS at all since I bought this.

borkdude 2021-04-09T18:55:34.161100Z

In cmd.exe: clojure not available (because it's a PS function or something?), but:

C:\Temp>bb clojure -X:new :name rowan/example :template luminus :output mywebapp :args "[+http-kit +h2 +reagent +auth]"
Generating a Luminus project.
worked.

seancorfield 2021-04-09T18:57:42.162500Z

Thanks. https://github.com/seancorfield/clj-new#example-usage shows the usage that works on both Linux/macOS/PS now.

littleli 2021-04-11T00:41:49.183100Z

I can't help but the backslash still causes trouble.

littleli 2021-04-11T00:43:18.183300Z

Careless user who uses his clipboard jump into the error immediately

littleli 2021-04-11T00:43:33.183500Z

Temp $ clojure -X:new :template luminus :name yourname/example.webapp \
Unreadable arg: "\\"

seancorfield 2021-04-11T00:50:00.183700Z

Dang, Windows sucks. Does it have a way to spread a command over multiple lines?

littleli 2021-04-11T00:52:46.183900Z

Space followed by backtick... I guess

seancorfield 2021-04-11T00:54:38.184100Z

Which wouldn't work on macOS/Linux. Sheesh.

seancorfield 2021-04-11T00:54:49.184300Z

OK, I've updated most of the examples: https://github.com/seancorfield/clj-new/commit/a3389d67daa67fe474bd7fc502625e8193e58ff6

littleli 2021-04-11T00:55:48.184500Z

Looks good. Sorry for being annoying. But it's not my fault.

littleli 2021-04-11T00:56:38.184700Z

As a funny side note. PowerShell is actually posix compliant

littleli 2021-04-11T00:57:12.184900Z

Not that it does mean anything to a way we are used to work daily

seancorfield 2021-04-11T00:58:45.185100Z

It shows how little "Posix-compliant" actually means...

littleli 2021-04-11T01:00:13.185300Z

Well to be fair PowerShell works with structured data, not strings and bytes. So there is a lot of differences

borkdude 2021-04-09T18:58:45.163Z

cool, that's an improvement :)