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.
Completely agree. At least this should be well documented. Positive, working examples needed.
đź‘Ť
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?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).
> 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.
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.
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).
I think I have missed those requests then, I wasn't aware of those at all
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…
Currently only :name
and :template
accept symbols in place of strings, so implementing that issue will improve matters for Windows users.
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.
$ 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.Why deal with a shell if you can have a REPL anyway? ;)
You recommend what you want; I’ll continue to recommend what Nubank/Cognitect and the core Clojure folks suggest 🙂
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.
> 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?
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
@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]'
-R
? Do you mean -A
?
sorry, meant repl (so yes -A)
@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
That’s because your :new
alias is not set up correctly.
In your case clojure -X:new clj-new/create :name ...
should work
Or add :exec-fn clj-new/create
to your :new
alias.
@borkdude I appreciate you testing it for me 🙂
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
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
oh I guess I need to upgrade, my bad, will test again
I do all my Clojure dev on WSL2. I haven’t installed clojure
on Powershell since I got my Surface Laptop 3.
(I haven’t installed anything under PS since I got this machine)
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.
Much appreciated.
Ya, I don’t even have scoop installed. I pretty much haven’t started up PS at all since I bought this.
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.Thanks. https://github.com/seancorfield/clj-new#example-usage shows the usage that works on both Linux/macOS/PS now.
I can't help but the backslash still causes trouble.
Careless user who uses his clipboard jump into the error immediately
Temp $ clojure -X:new :template luminus :name yourname/example.webapp \
Unreadable arg: "\\"
Dang, Windows sucks. Does it have a way to spread a command over multiple lines?
Space followed by backtick... I guess
Which wouldn't work on macOS/Linux. Sheesh.
OK, I've updated most of the examples: https://github.com/seancorfield/clj-new/commit/a3389d67daa67fe474bd7fc502625e8193e58ff6
Looks good. Sorry for being annoying. But it's not my fault.
As a funny side note. PowerShell is actually posix compliant
Not that it does mean anything to a way we are used to work daily
It shows how little "Posix-compliant" actually means...
Well to be fair PowerShell works with structured data, not strings and bytes. So there is a lot of differences
cool, that's an improvement :)