This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-01-27
Channels
- # announcements (4)
- # asami (6)
- # aws-lambda (1)
- # babashka (38)
- # babashka-sci-dev (20)
- # beginners (87)
- # calva (67)
- # cider (19)
- # clerk (13)
- # clojure (102)
- # clojure-europe (52)
- # clojure-filipino (1)
- # clojure-hungary (4)
- # clojure-nl (1)
- # clojure-norway (6)
- # clojure-sweden (3)
- # clojure-uk (1)
- # cursive (13)
- # data-science (7)
- # datomic (8)
- # deps-new (1)
- # emacs (3)
- # fulcro (16)
- # graphql (3)
- # humbleui (3)
- # kaocha (3)
- # leiningen (3)
- # malli (3)
- # off-topic (14)
- # pathom (34)
- # polylith (4)
- # rdf (12)
- # reitit (3)
- # releases (1)
- # remote-jobs (7)
- # rum (2)
- # sci (22)
- # shadow-cljs (115)
- # tools-deps (26)
- # tree-sitter (29)
hey all, I’m wondering if I’ve hit a bug, or if there is some way to prevent this “unintuitive” behavior… given deps.edn
{:aliases
{:cake {:exec-fn user/cake}}}
and src/user.clj
(ns user)
(defn cake [m]
(prn "you ran cake with " m))
(defn face [m]
(prn "you ran face with " m))
check out this behavior:
[sritchie@wintermute ~/code/clj/tools-repro]$ clj -X:cake user/face a b
"you ran face with " {a b}
[sritchie@wintermute ~/code/clj/tools-repro]$ clj -X:cake user/face a b c
"you ran cake with " {user/face a, b c}
[sritchie@wintermute ~/code/clj/tools-repro]$ clj -X:cake user/face a b c d
"you ran face with " {a b, c d}
depending on whether I supply an even or odd number of arguments, user/face is interpreted as a function OR as an argument
is there some way to cause this to error if I supply the wrong number of args? I can do it inside of a babashka task…
[sritchie@wintermute ~/code/clj/tools-repro]$ clj -X:cake a b c
Unqualified function can't be resolved: a
This is "expected" but perhaps surprising if you don't know how the CLI figures out what invocation you're trying to run...
Since CLI arguments are passed as key/value pairs, it uses the number of arguments to differentiate between a specific function and k/v pairs or the default function :exec-fn
and k/v pairs.
yeah, I get it, just trying to noob-proof a template I’m creating with some babashka tasks that call into clojure via -X
Hard to noob-proof -X
because you have to understand how it is called 😐
got it! bb.edn:
{:tasks
{:init (defn X [cmd]
(do (if (even? (count *command-line-args*))
(apply shell cmd *command-line-args*)
(do (println "Please supply an even number of arguments!")
(System/exit 1)))))
start-clerk
{:doc "Start a Clerk dev server configured with this project's custom JS."
:task (X "clojure -X:dev:nextjournal/clerk user/start!")}}}
Yeah, you basically need a wrapper around the invocation...
@U017QJZ9M7W What I typically do is:
{:task (apply clojure "-X:whatever" *command-line-args*))
Why wrap this with checks?because the alias has a default :exec-fn
, and I don’t want the user to accidentally call that
I can move the exec-fn to a NEW alias of course, since I’m using the clerk
alias for both extra deps and the exec-fn
but you're already providing the exec-fn in the task, so the user can't call another one?
that’s the problem, see my paste above; if you supply an odd number of args, the first one’s interpreted as a new :exec-fn
oh sorry I see your “what I typically do is” note
it’s because Clerk’s Garden needs a :nextjournal/clerk
alias with an :exec-fn
that triggers the static build
and I think it’s confusing for consumers of this template I’m writing if I put
• clerk dep in one alias with a different name
• garden :exec-fn
in :nextjournal/clerk
alias
• yet another alias with a different to supply another :exec-fn
to start the local clerk dev server
that’s why I’m using bb.edn
in the first place, because constructing these big strings out of simple decomplected parts is not something I want to explain to someone new who’s just trying to graph some functions 🙂
as much as I am on board with it!!
Hi everyone. I'm trying to use clojure.tools.deps/resolve-deps
in a leiningen project (throught a remote REPL). I could download the lib locally, but seems that I need to update the classpath because the lib I just fetched is not there. Does anyone knows how can I do that?
If you're using Leiningen, you already have Pomegranate available which lets you load new dependencies at runtime.
Otherwise, with tools.deps.alpha
you'd need the add-lib3
branch and the add-libs
function (which isn't documented and is subject to change). A variant of this may be built into Clojure 1.12 it seems.
Thanks @U04V70XH6. I'll try out Pomegranate