(Babashka 1.13.225)
I'm building a cli with tasks, works great, then trying as an installed binary via bbin and it seems there is something missing.
I'm guessing I can't use fully qualified symbols with babashka.cli/dispatch and expect it to work, right?
So I now have this resolve-tree helper to convert my tree to something that works with babashka.cli/dispatch`
Something like this should probably go into babashka.cli itself?
(def tree {"login" {:exec-fn `login}
"token" {:exec-fn `token}
"refresh" {:exec-fn `refresh}
"status" {:exec-fn `status}
"logout" {:exec-fn `logout}})
(defn resolve-tree [tree]
(clojure.walk/postwalk (fn [x]
(if-let [sym (:exec-fn x)]
(let [v (resolve sym)]
(merge {:exec-fn v} (:org.babashka/cli (meta sym))))
x))
tree))
CONCLUSION: just use vars in the tree instead of symbolsCan you state the problem before presenting me with a solution? :)
Sorry yeah it was my intention to show the problem by showing a simplified solution.
The problem is that tree doesn't work with babashka.cli/dispatch
Because babashka.cli/dispatch` expects functions not symbols i think
it should work
So there is a mismatch between what works with babashka tasks and babashka.cli/
I mean with vars
in bb tasks those are symbols, but in bb.cli vars since it's normal clojure
Ok i felt symbols were nicer than vars and since it works with tasks i was happy with that. So in this case I should use vars i guess
with vars it does work indeed
Ok example here. It's really quick to develop now for bbin https://github.com/jeroenvandijk/chatgpt-oidc/blob/main/src/jeroenvandijk/oidc/chatgpt/cli.clj#L41-L62
I haven't looked at the code but you can just start out with the tree with vars right away, no need to start with symbols if they are in code?
Yeah it works so just sharing in case you are interested. But I think I prefer the symbols over the vars, but I can get used to using the vars instead.
and then you can just use one symbol in bb.tasks to refer to that tree in the code
Yeah I think i have everything now as how you intended it (hopefully :))
confusing experience i just had. If you invoke bb from a directory that has been deleted you get a really confusing stacktrace. Can easily happen if you want to run a script from a terminal in a temp directory and that has been deleted underneath you. Repro:
mkdir deleted-dir
cd deleted-dir
# another terminal deletes it: rm -rf /tmp/deleted-dir
bb
and yields:
Uncaught exception while initializing isolate: java.lang.Error: Properties init: Could not determine current working directory.
makes sense. Just felt broken when i didn’t realize what was going on. Just putting it here in case anyone runs into this and is confused and searches for it here.full output:
/tmp/deleted-dir
❯ bb
Uncaught exception while initializing isolate: java.lang.Error: Properties init: Could not determine current working directory.
at com.oracle.svm.core.posix.PosixSystemPropertiesSupport.userDirValue(PosixSystemPropertiesSupport.java:62)
at com.oracle.svm.core.jdk.SystemPropertiesSupport$LazySystemProperty.computeValue(SystemPropertiesSupport.java:385)
at com.oracle.svm.core.jdk.SystemPropertiesSupport.initializeProperty(SystemPropertiesSupport.java:338)
at com.oracle.svm.core.jdk.SystemPropertiesSupport.initializeAllProperties(SystemPropertiesSupport.java:293)
at com.oracle.svm.core.jdk.SystemPropertiesSupport.ensureAllPropertiesInitialized(SystemPropertiesSupport.java:282)
at com.oracle.svm.core.jdk.SystemPropertiesSupport.getCurrentProperties(SystemPropertiesSupport.java:241)
at java.lang.System.getProperties(System.java:393)
at java.io.UnixFileSystem.<init>(UnixFileSystem.java:45)
at java.io.DefaultFileSystem.getFileSystem(DefaultFileSystem.java:40)
at com.oracle.svm.core.jdk.runtimeinit.DefaultFileSystemHolder.<clinit>(FileSystemProviderRunTimeInitSupport.java:123)
at com.oracle.svm.core.jdk.runtimeinit.DefaultFileSystemAccessor.get(FileSystemProviderRunTimeInitSupport.java:131)
at java.io.File.<init>(File.java:285)
at com.oracle.svm.core.jdk.NativeLibraries.loadLibraryRelative(NativeLibraries.java:110)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:135)
at java.lang.Runtime.loadLibrary0(Runtime.java:822)
at java.lang.System.loadLibrary(System.java:1685)
at com.oracle.svm.core.jdk.JNIPlatformNativeLibrarySupport.loadJavaLibrary(JNIPlatformNativeLibrarySupport.java:45)
at com.oracle.svm.core.posix.PosixNativeLibrarySupport.loadJavaLibrary(PosixNativeLibraryFeature.java:132)
at com.oracle.svm.core.posix.PosixNativeLibrarySupport.initializeBuiltinLibraries(PosixNativeLibraryFeature.java:99)
at com.oracle.svm.core.graal.snippets.CEntryPointSnippets.initializeIsolateInterruptibly1(CEntryPointSnippets.java:517)
at com.oracle.svm.core.graal.snippets.CEntryPointSnippets.initializeIsolateInterruptibly0(CEntryPointSnippets.java:427)
at com.oracle.svm.core.graal.snippets.CEntryPointSnippets.initializeIsolateInterruptibly(CEntryPointSnippets.java:422)
at com.oracle.svm.core.graal.snippets.CEntryPointSnippets.initializeIsolate(CEntryPointSnippets.java:411)
at com.oracle.svm.core.JavaMainWrapper$EnterCreateIsolateWithCArgumentsPrologue.enter(JavaMainWrapper.java:459)
Fatal error: Failed to create the main Isolate. (code 13)Oh look, bb comes out great in this AI thing, least amount of tokens https://sstoehrm.github.io/stack-cap-bench/
that's really cool!
Not a surprise! Clojure is already super terse, and I've noticed newer models seem to know what libs are included in bb already. Or maybe they're sneakier about looking it up. But they can do a ton of cool projects with only the built in libs, which I assume means less tokens spent on checking environment/config stuff
Just added this to my CLAUDE.md. Need to stop the waste 🙏 > For scripting / CLI work, prefer babashka (bb) over python unless you have a good reason.
Here is some serious bb maxxing going on https://x.com/spacebat/status/2108292322152902865
I stand by what I wrote back in May: https://clojurians.slack.com/archives/CLX41ASCS/p1778775129032099
This is a port of a library that @agilecreativity wrote to deal with the raylib library in Clojure (+ dialects). Since his library was LLM-generated, I did an LLM-mechanical port of his to check if all his examples worked with bb.ffi (they all worked). https://github.com/borkdude/raylib-bb-ffi Use at your own risk.
Maybe you can run each one of them and take screenshots like how I did it here: https://b12n-oss.github.io/raylib-clj-demo/guide/demos.html