This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-07-14
Channels
- # announcements (3)
- # babashka (189)
- # beginners (157)
- # calva (5)
- # cider (5)
- # clj-kondo (7)
- # cljdoc (34)
- # clojure (61)
- # clojure-dev (2)
- # clojure-europe (42)
- # clojure-nl (15)
- # clojure-poland (1)
- # clojure-spec (5)
- # clojure-uk (6)
- # clojured (2)
- # clojurescript (31)
- # clojureverse-ops (8)
- # component (2)
- # cursive (41)
- # datomic (15)
- # depstar (44)
- # figwheel-main (9)
- # fulcro (14)
- # holy-lambda (1)
- # inf-clojure (13)
- # introduce-yourself (1)
- # jobs (1)
- # lsp (98)
- # malli (12)
- # off-topic (12)
- # pedestal (1)
- # polylith (3)
- # re-frame (51)
- # reitit (4)
- # releases (1)
- # reveal (5)
- # shadow-cljs (3)
- # tools-deps (56)
- # vim (12)
- # xtdb (36)
clojure -Ttools install com.github.seancorfield/depstar '{:git/tag "v2.1.267"}' :as depstar
Major documentation overhaul, aligns with tools.build
.For -X is there yet a strategy for substitution (i.e. where I can't manually do edn escaping) so that I can do something like clj -X:foo :bar-key "$(wl-paste)"
? I'm only ever expecting strings when doing this.
@borkdude that isn't general purpose though, what if my command outputs a "
? e.g. clj -X clojure.core/prn :foo \"$(echo '"dude')\"
$ escaped=$(echo '"dude' | bb -e '(prn (slurp *in*))')
$ clj -X clojure.core/prn :foo $escaped
{:foo "\"dude\n"}
I came across a new warning after updating TDA recently:
WARNING: Use of :paths external to the project has been deprecated, please remove: ...
What's the rationale behind disallowing such paths? Some of my builds include paths that symlink into /tmp, which look 'internal' e.g. :extra-paths ["target/cljs-resources"]
but become 'external' when canonicalized in clojure.tools.deps.alpha/validate-paths
.
(I use /tmp to include build inputs from previous steps, and because I can mount it as tmpfs for speed and to avoid wearing out my SSD.)
@alexmiller āļø:skin-tone-2:
> What's the rationale behind disallowing such paths? Projects that reach outside their project do not play well when moved to other people's machines, particularly as gitlibs
I don't understand "to avoid wearing out my SSD" but I do understand "for speed" :)
this may be a place where some careful path handling could keep the path to the in-project link. if you like, file a question on https://ask.clojure.org and I can add it to the queue of things to look at
@borkdude right, but ideally without needing an extra tool in there. Not everyone has bb installed (yet)
bb runs normal Clojure. You can use normal Clojure is bb is not there, so there's always an alternative
Yeah, true. Not particularly fast though. 2.46s overhead cost for it. And not great to type at the terminal either.
can you use something like this?
clj -X:foo :bar-key '"'$(wl-paste)'"'
@alexmiller that's going to fail if there's a space in the paste š
I don't think it will
% echo $FOO
a b c
% clj -X clojure.core/prn :a '"'$FOO'"'
{:a "a b c"}
I get a different result:
$ VAR='foo bar baz'
$ clj -X clojure.core/prn :bar-key '"'$VAR'"'
Unreadable arg: "\"foo"
you could surround $VAR with "" there again if you need to, not sure why mine is different
maybe bash version - Mac uses old bash
clj -X clojure.core/prn :bar-key '"'"$VAR"'"'
seems like it works on both zsh and bash
@alexmiller That doesn't work for anything containing a quote.
āÆ VAR='b"'
āÆ clj -X clojure.core/prn :bar-key '"'"$VAR"'"'
{:bar-key "b"}
have you heard the good word about putting your data in files? :)
Moving to -X causes shell-related pains like this and the solution is different for each shell/OS, which is a pity for a platform like the JVM which is supposed to be write-once, run anywhere, but yes, it seems the world is moving towards that.
I'm thinking about things like -X some.fn/bar '[:db :password]' "$(pass show -p password-for-db)"
or other things where users want to use the clojure stuff as a swiss army knife of dynamic parts.
env vars is probably a better choice for that particular case (where you don't want your passwords in your command lines, visible in process commands)
Well there're other things too, like script clj-new (which I've done for testing my templates before). You get into the game of escaping your temporary names. Rewriting clj-new to take env vars doesn't make sense. I'm looking for parameterization a la carte, rather than hard-coded into functions.
well you're making these calls from some shell, so there's no way to avoid the eccentricities of that API
if you want more control, write a clojure program into a file and run it
or pipe it over stdin with clojure.main :)
Clojure is worse than a shell here. Process substitution is much harder than $()
for example. Shells are optimized for combining things in ways like this on the fly.
Maybe we need a type system. clj -X clojure.core/prn ^String :foo-bar "$(echo 'b"zt')"
and then -X
can just treat it as a literal string. Of course, that breaks if someone accidentally echoes something like ^String
as their key. So we'll need an escaping system, just in case.
Sounds like the job of a tiny library for use with #babashka
I think most of the pain with shells + -X comes from having to quote strings. If that was not needed, it would probably a bit smoother.
Agreed, still an open topic
Something that would work without sub-shells or crazy escaping, although is eh compared to normal shell usage, would be FOO="$(echo 'b"zt')" clojure -X clojure.core/prn :foo-bar '#env FOO'
where env
is doing (System/getenv)
.
https://github.com/clojure/clojure/blob/b1b88dd25373a86e41310a525a21b497799dbbf2/src/clj/clojure/core_print.clj#L200-L221 This looks reasonably easy to port to a C/zig program that would be portable & tiny enough to include in a clojure distribution for making this escaping reasonably easy. It's like how xargs ports stdin to args, this ports shell args to clojure args so cargs? š
#!/bin/sh
printf '"'
sed 's/\\/\\\\/g' |
sed "s/\r/\\\\r/g" |
sed 's/$/\\n/g' | tr -d '\n' |
sed "s/\t/\\\\t/g" |
sed 's/"/\\"/g' |
sed "s/\f/\\\\f/g" |
# \b, but sed uses \b for word boundary
sed 's/\x08/\\b/g'
printf '"'
That seems to work as an edn escaper. I could see this going into the clj tool so you can do printf '"' | clj arg
Compared with the native zig version it's much slower, but also portable so probably worth it š Overall, both are fast.
Or a GraalVM version like https://github.com/borkdude/deps.clj which can properly work on Windows as well (which I wish the official cli followed this model instead of using bash)
@dominicm why not -X app.start-script/prod
where (defn prod [] (sh/sh "pass" "show" "-p" ....))
?
When I'm working from the shell I'll often use parameter subsitution in various ways, change it, etc.
That would have to be (defn prod [_] ...)
to be invoked with -X
but at this point I agree with Alex: write a (Clojure) script for something that is too complex to do easily from the command-line.
sorry if this is a dumb question, but how do I clojure -X:deps prep
a library that's only included under :extra-deps
for a specific alias? At first I assumed either clojure -X:my-alias:deps prep
or clojure -X:deps:my-alias prep
would work, but they both fail with the libs must be prepared before use
message. I tried clojure -X:deps prep :basis '{:aliases #{:my-alias}}'
after reading the https://github.com/clojure/tools.deps.alpha/blob/655ea0a037f041e365cc56db0dc8181268c29998/src/main/clojure/clojure/tools/cli/api.clj#L68 but that doesn't work either, since {:aliases #{:my-alias}}
isn't actually a basis (although it could be used to create one, e.g. with tools.build create-basis
) -- I'm not sure how to get an actual basis from the CLI. I tried clojure -X:deps basis '{:alias #{:my-alias}}'
thinking maybe that would return a basis that I could then pass to -X:deps prep
(e.g. something like clojure -X:deps prep :basis "$(clojure -X:deps basis '{:alias #{:my-alias}}')"
) but basis
doesn't write any results to the CLI.
How do I prep libs in an alias?
https://github.com/clojure/clojure/blob/b1b88dd25373a86e41310a525a21b497799dbbf2/src/clj/clojure/core_print.clj#L200-L221 This looks reasonably easy to port to a C/zig program that would be portable & tiny enough to include in a clojure distribution for making this escaping reasonably easy. It's like how xargs ports stdin to args, this ports shell args to clojure args so cargs? š