Fork me on GitHub
Brandon Stubbs18:06:51

Hey, I am not an advanced user of Clojure yet, but I was trying to do the following in Babashka (load a script in another script and try execute it's functions) foo script

#!/usr/bin/env bb
(ns foo)

(when (= *file* (System/getProperty "babashka.file"))
  (load-file "bar")
  (println (ns-interns 'bar)) ;; => {test #'bar/test}
  ;;(bar/test) <-- how to execute loaded functions?
bar script
#!/usr/bin/env bb
(ns bar)

(defn test [] (println "test"))
If someone could point me in the right direction on how I could execute functions from the loaded script? Thank for your time and the awesomeness that Babashka is


@brandon746 You should be able to load the functions like that.


In a multi-file project it's more common to have a bb.edn like {:paths ["script"]} and then put bar.clj in the script directory so you can use (require '[bar :as b])


@brandon746 Btw, welcome! You are the 600th member of this channel! :)

🎉 4
Brandon Stubbs21:06:06

Thank you very much 🙂 I would use the local bb.edn normally, but what I am trying to achieve is similar to the question you asked here: Basically a library to turn tasks into a global cli. So I can add the directory to my PATH, which will contain something like:

This way the brandon root will control the entire cli. So you could then execute brandon aws bucket-delete x brandon git assigned-prs So the logic for the aws commands sit within brandon-aws but the root brandon will dispatch them


ah I see. What you could do in that case is use add-classpath on a path that's a combination of *file* and a relative directory


and then you can use require from after that


you could just add the parent file of *file* to the classpath, (which is the directory of the file you're executing)

Brandon Stubbs21:06:03

Ah great thanks! Let me give that a go