Fork me on GitHub
#babashka
<
2023-01-18
>
Benjamin08:01:56

what is the nicest way to read a json, transform a val and spit back? I was thinking about a shell oneliner

iarenaza08:01:44

Maybe using jet, also from borkdude? https://github.com/borkdude/jet

👀 2
borkdude08:01:28

Yes: echo $json | jet --from json --func '#(-> % whatever)'

borkdude08:01:42

With bb:

echo $json | bb -e "(... (json/parse-string (slurp *in*)))" 

borkdude08:01:54

e.g.:

$ echo "{\"a\": 1}" | bb -e "(-> (json/parse-string (slurp *in*) true) :a (json/generate-string))"
"1"

Mikko Harju10:01:14

Hmh, how do I specify a default list of items to babashka.cli so that it does not append the ones from the argument list but replace them? In spec. Should I use the :exec-args instead in that case and not :default and :default-desc

👀 2
borkdude10:01:33

You can use both I think

borkdude10:01:09

Maybe it's best to provide an example

Mikko Harju10:01:25

Both ways seem to append, what am I doing wrong

Mikko Harju10:01:28

➜  frontend git:(enhancement/hierarchial-system-diagram) ✗ bb scripts/transpile-device-graph.bb
[CS2-GHS GHS-250 GHS-1000]
➜  frontend git:(enhancement/hierarchial-system-diagram) ✗ bb scripts/transpile-device-graph.bb -s CS2-GHS
[CS2-GHS GHS-250 GHS-1000 CS2-GHS]

borkdude10:01:37

Repro please

Mikko Harju10:01:35

(def small-spec {:systems {:ref "<name or names>"
                     :alias :s
                     :coerce []
                     :desc "To include only a selected set of systems, provide their names."}})

(let [{:keys [systems]} (cli/parse-opts *command-line-args* {:spec small-spec :error-fn error-fn :exec-args {:systems ["CS2-GHS" "GHS-250" "GHS-1000"]}})]
  (println systems))

Mikko Harju10:01:48

same output as above

borkdude10:01:21

ok, I'll have a look

🙇 2
Mikko Harju10:01:29

Should've that worked?

borkdude10:01:29

Yeah, this seems to be a bug. The argument should replace, not merge or concat

borkdude10:01:36

can you file an issue with babashka cli?

Mikko Harju10:01:52

Do you use GH for those?

Mikko Harju10:01:25

For now I just did

(if (> (count systems) (count default-systems))
                (subvec systems (count default-systems))
                systems)
and continue my life happily 🙂

borkdude10:01:47

Fixed and released as 0.6.44 You can test the new bb once the master build finishes with:

bash <(curl ) --dev-build --dir /tmp
or you can add babashka/cli to your bb.edn and load it with:
(:require [babashka.cli :as cli] :reload) 
to override the built-in one

Mikko Harju10:01:41

Thanks – that was fast! Will wait for propagation and update later 👍

👍 2
borkdude13:01:51

bb 1.0.170 released

🎉 2