Fork me on GitHub
#babashka
<
2022-06-02
>
borkdude13:06:49

Introducing babashka.cli ! https://github.com/babashka/cli

borkdude 2
❤️ 2
🎉 3
borkdude19:06:18

A suggestion on how to use babashka.cli with babashka tasks: https://github.com/babashka/cli#usage-in-babashka-tasks

dpsutton20:06:57

Are there any babashka scripts/prior-art of finding all usages of vars from a certain namespace? I’d like to profile json libraries and would love to see the entirety of the cheshire api we use. Would be great to run some kind of bb <something> cheshire.core src:shared/src or similar and it would report all var usages. Does something like this exist already? Or do i need to just look at clj-kondo analysis?

borkdude20:06:13

@dpsutton clj-kondo analysis is a better tool for this

👍 1
borkdude20:06:57

@dpsutton

$ clj
Clojure 1.11.0-alpha4
user=> (require '[clj-kondo.core :as clj-kondo])
nil
user=> (def usages (-> (clj-kondo/run! {:lint ["src"] :config {:analysis true}}) :analysis :var-usages))
#'user/usages
user=> (count (filter #(= 'cheshire.core (:to %)) usages))
1

👏 1
borkdude20:06:16

({:end-row 52, :name-end-col 41, :name-end-row 47, :name-row 47, :name generate-string, :filename "src/clj_kondo/core.clj", :alias cheshire, :from clj-kondo.core, :col 16, :name-col 17, :from-var print!, :end-col 47, :arity 1, :row 47, :to cheshire.core})

🙏 1
dpsutton20:06:41

you’re too kind

dpsutton20:06:41

{cheshire.core/parse-stream 1,
 cheshire.generate/encode-str 1,
 cheshire.factory/default-date-format 1,
 cheshire.core/encode 3,
 cheshire.core/generate-stream 6,
 cheshire.generate/encode-map 8,
 cheshire.core/generate-string 29,
 cheshire.core/parse-string 31,
 cheshire.core/decode 1,
 cheshire.generate/write-string 1,
 cheshire.generate/add-encoder 13,
 cheshire.generate/*date-format* 1}
thank you so much @U04V15CAJ

👍 1
danieroux22:06:54

Got nerd-sniped hard with this @U04V15CAJ. Just wrote the fn-usage-constraint test I've always wanted to write! (only one d/transact in the main code)

danieroux22:06:53

(that is a thank you. Thank you!)

👍 1
perpen21:06:07

How do i find the pid of the current bb? My current method is spawning bash -c 'ps -o ppid= $$' but not very portable

borkdude21:06:37

You can use ProcessHandle for this

borkdude21:06:12

user=> (.pid (java.lang.ProcessHandle/current))
36069

colliderwriter23:06:23

I need to write a script which can either • make a number of file system changes or • with a command line switch report what file system changes it would perform, as in rsync --dry-run I can imagine building a vector of encoded changes and processing them according to the cli switch, but I thought there might be prior art out there to build on. Any suggestions?

borkdude06:06:30

That seems like a good approach to me

perpen12:06:11

Or if it fits, wrap the actual file modifying commands in a macro that either prints the change or applies it. I use this method sometimes when writing shell scripts.