This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-04-02
Channels
- # announcements (2)
- # aws (7)
- # babashka (47)
- # beginners (54)
- # biff (6)
- # calva (14)
- # clojure-europe (7)
- # clojure-germany (2)
- # clojure-japan (4)
- # clojure-norway (5)
- # datalevin (1)
- # deps-new (13)
- # helix (5)
- # hoplon (1)
- # hyperfiddle (12)
- # introduce-yourself (6)
- # joyride (1)
- # malli (2)
- # off-topic (21)
- # polylith (11)
- # re-frame (3)
- # reitit (8)
- # remote-jobs (1)
- # scittle (25)
- # shadow-cljs (20)
- # vim (19)
- # xtdb (4)
as a bb excercise for myself, I’ve been trying to construct an argument set that would start portal in vscode with just one call:
bb --prn -cp `clj -Spath -Sdeps '{:deps {djblue/portal {:mvn/version "0.36.0"}}}'` --exec portal.api/open :launcher :vs-code :port 5678
this is my attempt so far, but it’s got shortcomings: by using clojure.core/identity
instead of portal.api/open
, I found that (a) “vs-code” is ":vs-code"
, not :vs-code
; and (b) it just prints whatever is returned and exits.(a) is a bit of a surprise to me given that babashka/cli is supposed to (?) auto-coerce the args, and they do start with :
for (b), I suppose I’d have to get it to block in some way; @(promise)
-style? :thinking_face:
$ bb -cp `clj -Spath -Sdeps '{:deps {djblue/portal {:mvn/version "0.36.0"}}}'` --exec clojure.core/prn :launcher :vs-code :port 5678
{:launcher :vs-code, :port 5678}
babashka v1.1.173
thanks for your quick help. updating…
$ bb -Sdeps '{:deps {djblue/portal {:mvn/version "0.36.0"}}}' -x portal.api/open :launcher :vs-code :port 5678
----- Error --------------------------------------------------------------------
Type: clojure.lang.ExceptionInfo
Message: No config file found: vs-code.edn
hrm. So I’ve been doing this in a repl and it worked; I wanted to condense it into one call:
$ bb -cp `clj -Spath -Sdeps '{:deps {djblue/portal {:mvn/version "0.36.0"}}}'`
Downloading: djblue/portal/0.36.0/portal-0.36.0.pom from clojars
Downloading: djblue/portal/0.36.0/portal-0.36.0.jar from clojars
Babashka v1.1.173 REPL.
Use :repl/quit or :repl/exit to quit the REPL.
Clojure rocks, Bash reaches.
user=> (require '[portal.api :as p])
nil
user=> (def p (p/open {:launcher :vs-code :port 5678}))
ah, got that from https://github.com/djblue/portal
gotcha. perhaps @U1G869VNV could update this.
or I can PR it tomorrow.
But this should work, probably?
bb -Sdeps '{:deps {djblue/portal {:mvn/version "0.36.0"}}}' -x portal.api/open :launcher :vs-code :port 5678
possibly. I get it to open the tab in vscode, but it’s empty. probably the @promise
thing
can I… emulate that in the CLI? :thinking_face:
(just checking, tasks also can’t do this, right? I’ve been wondering if I should define a task for this…)
> or you can write an exec function which calls the other function and then blocks can you point me to an example, please? 🙂
$ BABASHKA_PRELOADS='(ns exec) (defn block [{:keys [f] :as opts}] ((requiring-resolve (symbol f)) opts) @(promise))' bb -Sdeps '{:deps {djblue/portal {:mvn/version "0.36.0"}}}' -x exec/block -f portal.api/open :port 5678
oh wow. thank you
hm for some reason, adding the :launcher :vs-code
doesn’t work but I’ll try to take it from there. thanks again!
it’s suppose to open the portal UI in a vscode tab, but it opens it in a standalone window — like the :launcher arg was malformed or missing
Oh I see, babashka.cli doesn't like if you mix --
and :
style params, so this works:
$ BABASHKA_PRELOADS='(ns exec) (defn block [{:keys [f] :as opts}] (prn opts) ((requiring-resolve (symbol f)) opts) @(promise))' bb -Sdeps '{:deps {djblue/portal {:mvn/version "0.36.0"}}}' -x exec/block :f portal.api/open :port 5678 :launcher :vscode
thanks
(btw the latest portal is 0.38.1; I had started out with an old version above — it doesn’t matter for any of this, though.)
Oooh, this is so cool @U04GFG14FCP. Added this to my nostromo aliases. Also, as a thank you for sharing this, here is https://github.com/djblue/portal/pull/176 for portal's README. 🙇
thanks @U04CYFD1CDN, for noticing that I had dropped the ball on this 😅
LOLOLOL. Let's give you the benefit of the doubt. In a few years when an interviewer is looking at this monstrous PR, wide eyed in disbelief at its shear elegance, I will smile knowing that I STOLE this work from you and Michiel.
wait is this even correct? I think it should be
bb -Sdeps '{:deps {djblue/portal {:mvn/version "0.38.2"}}}'
without any of the backticks and the call to clj
@U04GFG14FCP, Is the --classpath
/`-cp` flag redundant as well
bb -Sdeps '{:deps {djblue/portal {:mvn/version "0.38.2"}}}'
yes, I believe so