Fork me on GitHub
#babashka
<
2023-09-16
>
teodorlu14:09:16

I just had a realization about how REPL-friendly babashka/cli really is.

(cli/dispatch [{:cmds ["install"] :fn identity}]
              ["install" "myfile.clj"])
;; => {:cmds ("install" "myfile.clj"),
;;     :args ("myfile.clj"),
;;     :rest-cmds ("myfile.clj"),
;;     :opts {},
;;     :dispatch ["install"]}
It’s just data! I don’t really have to start my CLI every time to debug, I might as well call a function with data from the REPL. No questions, just note from a happy library consumer.

πŸŽ‰ 9
Bob B15:09:12

reading this, my mind goes back to that mock clojure marketing video and the "it's just data!" with an explosion going off in the background (in a good way)

πŸ˜† 5
Coby Tamayo16:09:45

How can I capture output from a shell task/call? Here is what I've tried:

{:tasks
 {minor-version "0.6"
  rev-count (shell "git rev-list HEAD --count")
  patch-version {:depends [minor-version rev-count]
                 :task (format "%s.%" minor-version rev-count)}}}}
Which gives:
$ bb run --prn patch-version
1092
"0.6.babashka.process.Process@bf50da14"
I also tried:
{:tasks
 {minor-version "0.6"
  patch-version {:depends [minor-version rev-count]
                 :task (format "%s.%" minor-version (with-out-str (shell "git rev-list HEAD --count")}}}}
but that just output:
1092     # output of rev-count task
"0.6."

borkdude16:09:20

(-> (shell {:out :string} ...) :out) 

borkdude16:09:44

you probably want to add clojure.string/trim to that as well to strip the newline

borkdude18:09:25

btw all options for shell can be found in the docs of this library: https://github.com/babashka/process

πŸ‘€ 1
pesterhazy09:09:41

Wow, these are both very cool projects. Being able to get mvn dependencies without java could open up many possibilities. For example, shadow-cljs might be able to use this

borkdude09:09:38

shadow-cljs in general still uses java right

pesterhazy09:09:03

Yeah that's true

pesterhazy09:09:57

Afaik it uses clever optimizations like aot to speed up startup time

pesterhazy09:09:27

but you're right, that kind of defeats the purpose of removing the java requirement

borkdude09:09:49

bb itself could use this to fetch deps without java

pesterhazy09:09:37

yes, that catches folks by surprise – the fact that you have to install java when using bb with maven deps

pesterhazy09:09:53

not a big thing, but a quality of life improvement