Fork me on GitHub
#babashka
<
2021-07-25
>
athomasoriginal20:07:40

I’m converting a project to use bb tasks . Loving it! I have the following bb task scenario:

;; script/create-file.clj
(defn -main [& args]
  (do-stuff args))

;; bb.edn
{:init (defn get-app-config
         []
         (io/resource "config.edn"))
 :tasks
 {;; option 1
  the-task create-file}
  ;; option 2
  the-task (shell "bb create-file" (get-app-config))}
get-app-config is going to read an edn config file (aero) and pass it to create-file . “option 2” works, but I was curious if its possible to pass in args to option 1 where the value of the-task is just a symbol. Or maybe there is a more recommended approach for this idea? Example:
;; option 1
the-task (create-file (get-app-config))}
Thanks!

borkdude20:07:49

@tkjone let's see if I understand your question

borkdude20:07:44

what you can do there is:

:tasks
{-the-config (get-app-config)
 the-task {
  :depends [-the-config]
  :requires ([create-file])
  :task (create-file/do-stuff -the-config)}}
for example

borkdude20:07:13

by depending on -the-config, that will be executed first and then you can pass on that value to another function from another namespace

borkdude20:07:49

note that your filename has to use underscores script/create_file.clj, same as with clojure files in clojure on the classpath

👍 3
borkdude20:07:29

you can also invoke other tasks using run for example

athomasoriginal20:07:45

oh, that is very nice!

borkdude20:07:04

also add :paths ["script"], then bb will look into that dir for script files

👍 3