This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-06-29
Channels
- # adventofcode (8)
- # babashka (12)
- # beginners (91)
- # calva (6)
- # cider (2)
- # circleci (11)
- # clj-kondo (19)
- # clojure (202)
- # clojure-australia (7)
- # clojure-brasil (1)
- # clojure-europe (123)
- # clojure-nl (2)
- # clojure-poland (24)
- # clojure-uk (6)
- # clojured (1)
- # clojurescript (91)
- # core-async (23)
- # cursive (16)
- # data-science (5)
- # datomic (26)
- # emacs (27)
- # events (2)
- # graalvm-mobile (50)
- # graphql (4)
- # honeysql (4)
- # instaparse (33)
- # lsp (24)
- # meander (22)
- # nrepl (3)
- # off-topic (26)
- # pedestal (1)
- # re-frame (15)
- # releases (1)
- # sci (1)
- # shadow-cljs (20)
- # tools-deps (22)
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])
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
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