Fork me on GitHub
#babashka
<
2023-05-11
>
joakimen07:05:30

Out of curiosity, what data format do you guys use to communicate between your bb scripts? Trying to keep my scripts small and concrete as possible (in the unix fashion), and glue things together with pipes. For scalar values, I just print the value, but for stuff like lists and hashmaps, i haven't really decided on edn, json or others. What do you guys prefer, and why?

borkdude07:05:37

Probably EDN is fine?

joakimen07:05:38

It would definitely be the most comfortable to parse, but then it also locks the tool into the clojure-ecosystem. Haven't really checked out edn support in other languages

borkdude08:05:45

"between bb scripts" -> EDN "other languages" -> JSON I'd say.

teodorlu08:05:29

For me, either EDN or "one EDN value per line". Generally just EDN. But "one EDN value per line" is nice to use with grep. Since key value pairs are next to each other, one can ... | grep ":key :value".

joakimen08:05:05

> "between bb scripts" -> EDN > "other languages" -> JSON Sounds like a sane default. On the topic, considering both clojure.edn and edamame.core are included in babashka, which one should be used for which usecase? @U3X7174KS being able to grep with the colon in ":key" actually sounds useful yeah!

jeroenvandijk08:05:29

You can also add a flag to switch between json or edn output

πŸ‘€ 2
borkdude08:05:44

bb has support for reading multiple EDN objects from a stream:

$ echo '{:a 1} {:a 2}' | bb -I -e '(prn *input*)'
({:a 1} {:a 2})
so it doesn't have to be on one line, that's more a limitation if you don't have a good EDN reader

πŸ‘ 2
borkdude08:05:19

@U0422G22932 About clojure.edn vs edamame: use edn for reading data, edamame for reading code

πŸ‘ 1
πŸ™‡ 1
joakimen08:05:12

Thanks all πŸ˜„

❀️ 2
nate00:05:28

One more vote for EDN between scripts and JSON for interop with other tools. There are more and more tools that offer JSON on the command line and it usually comes from APIs (via curl) too.

otfrom10:05:45

any handy babashka things for reading exif information? I've got some photos I want to organise and think it might be a good way for me to learn babashka

borkdude10:05:32

despite "cljs" it also works in bb

borkdude10:05:23

You can add that dependency to bb.edn, similar to what you would do in deps.edn

πŸ‘ 2
Samuel Ludwig13:05:29

not sure if i've lost my mind or something, but it seems like all pages under the babashka namespace on github are throwing 500 errors

borkdude13:05:45

It seems Github is having problems

βž• 1
dpsutton13:05:38

it’s been a rough stretch for github

lread14:05:20

> not sure if i've lost my mind or something, but it seems like all pages under the babashka namespace on github are throwing 500 errors Speaking from experience, these 2 things are not necessarily correlated.

βœ… 1
Peter Tonner14:05:42

I'm having trouble figuring out how to call shell with variable arguments. Basically I have certain command options that are only present sometimes. So I'm trying to do something like (shell "cmd" (when opt "--opt")) but this doesn't work b/c nil arguments into shell throws an error. The best I can come up with is something like (apply shell (filter (comp not nil?) ["cmd" (when opt "--opt") ...])) but doesn't seem great.

borkdude14:05:30

@U03G25L065N It's sufficient, but this is usually where cond-> comes in:

(cond-> ["cmd"]
  opt (conj "--opt"))

πŸ‘ 3
1
Peter Tonner14:05:14

ahh thanks! makes sense