So there isn’t really a great solution for this at the moment. I’m working on it though, assuming there are no major hiccups bb support will be in the next Cursive version (1.11, I’ve had more 1.10.x releases than expected due to bugs).
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! :)
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: https://github.com/babashka/babashka/issues/819
Basically a library to turn tasks into a global cli.
So I can add the directory to my PATH, which will contain something like:
brandon
brandon-git
brandon-aws
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 themah 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)
Ah great thanks! Let me give that a go
Updated the babashka news page with highlights from: - May https://github.com/babashka/babashka/blob/master/doc/news.md#2021-05 - June https://github.com/babashka/babashka/blob/master/doc/news.md#2021-06