Fork me on GitHub
#babashka
<
2023-08-31
>
borkdude09:08:02

Anyone going to JavaZone in Norway? @rahul080327 and @anupriyajo are giving a babashka workshop there! https://2023.javazone.no/program/19a5cab3-7afd-4dc1-b60a-bea8562d3186

babashka 4
Ingy döt Net20:08:21

Is there a way to have bb report (at least something close to) the equivalent shell commands it performs for a task?

👀 2
elken21:08:13

:pre-start-fn in babashka.process/process maybe?

borkdude21:08:32

you can do something like this:

(alter-var-root #'babashka.process/*defaults* assoc :pre-start-fn println)

borkdude21:08:50

This is probably even better:

(alter-var-root #'babashka.process/*defaults* assoc :pre-start-fn #(apply println ">" (:cmd %)))

Ingy döt Net21:08:14

hmmm, where do I put that if I'm running the task via bb run some:task ?

borkdude21:08:09

e.g. in :init inside of :tasks

Ingy döt Net21:08:34

in bb.edn right?

borkdude21:08:20

Yeah, but in this case, you can't use #' and #(..) so you have to write:

(alter-var-root (var babashka.process/*defaults*) assoc :pre-start-fn (fn [m] (apply println ">" (:cmd m))))

Ingy döt Net21:08:50

finally got it to work. my first time inside a bb.edn file

Ingy döt Net21:08:23

anyway, seems to work well. should save quite a bit of time

Ingy döt Net21:08:52

maybe a good idea for a future bb option?

borkdude21:08:29

yeah perhaps. one of the issues that it's currently a bit verbose is that not everyone wants to have this logging in the same way as others

pesterhazy08:09:41

Looks like :init isn't run if I use

bb -m my.entrypoint
Any way to run something in that case?

pesterhazy08:09:31

I was thinking of chaining main calls, like so:

bb -m my.enable-debug -m my.entrypoint

pesterhazy08:09:58

but couldn't see how to make that work given that babshka.main doesn't seem to be available to require

pesterhazy08:09:48

I guess what I'm thinking is that it would be cool to have a way to specify a preload code to run ad-hoc on the cli for debugging or other tooling purposes

borkdude08:09:34

There is an env var for this BABASHKA_PRELOADS, see docs. There’s also the —init option

borkdude08:09:50

:init only belongs to tasks

pesterhazy14:09:55

Ah, i'll check that out

pesterhazy09:09:06

This works like a charm and adds a touch of color

BABASHKA_PRELOADS='(alter-var-root (var babashka.process/*defaults*) assoc :pre-start-fn (fn [m] (println (str "\u001B[37m\u001B[45m" (pr-str (:cmd m)) "\u001B[0m"))))'