This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-10-07
Channels
- # announcements (2)
- # babashka (34)
- # beginners (114)
- # biff (7)
- # calva (16)
- # cider (2)
- # clj-kondo (46)
- # clj-on-windows (14)
- # clojars (13)
- # clojure (33)
- # clojure-europe (17)
- # clojure-nl (2)
- # clojure-norway (8)
- # clojure-spec (3)
- # clojure-uk (3)
- # clojurescript (25)
- # community-development (1)
- # datalevin (1)
- # emacs (53)
- # fulcro (31)
- # gratitude (2)
- # jobs (1)
- # lambdaisland (12)
- # lsp (57)
- # malli (3)
- # nbb (1)
- # off-topic (92)
- # pathom (2)
- # pedestal (2)
- # releases (5)
- # shadow-cljs (25)
- # sql (3)
- # squint (1)
- # testing (6)
- # vim (11)
I've created a tiny VS-Code extension to run Babashka Tasks. First release v0.1.0 is out! https://marketplace.visualstudio.com/items?itemName=fbeyer.babashka-tasks
What is a good way of working with urls in babashka? I’m looking specifically for a nice way of adding query parameters.
Lambdaisland has a lib for this:
(require '[babashka.deps :as deps])
(deps/add-deps '{:deps {lambdaisland/uri {:mvn/version "1.13.95"}}})
(require '[lambdaisland.uri :as uri :refer [uri]])
(-> (uri "")
(uri/assoc-query {:foo :bar})
uri/uri-str prn)
Nice! Thank you very much for the complete example with add-deps
and everything!
I didn't appreciate that if you have a script, say <dir>/bin/my-command
, that Babashka will look upwards for bb.edn
, so that can be in <dir>/bb.edn
. This makes it really easy to write scripts with dependencies. Full example here: https://github.com/hlship/cli-tools#defcommand
if you execute <dir>/bin/my-command
and you have <dir>/bb.edn
that works, because <dir>
is the current working directory
Shoot. Was running from the root directory, and forgot to check if it works from elsewhere. Ok, gotta fix that.
If you want to have self-contained scripts with dependencies, you can use this: https://clojurians.slack.com/archives/CLX41ASCS/p1665143925396069?thread_ts=1665143479.202349&cid=CLX41ASCS
I ended up with:
#!/usr/bin/env bb
(require '[babashka.deps :as deps])
(let [root (-> *file*
fs/parent
fs/parent)
paths [(fs/path root "src")
(fs/path root "resources")]]
(deps/add-deps `{:paths ~paths
:deps {io.github.hlship/cli-tools {:mvn/version "0.5"}}}))
(require '[net.lewisship.cli-tools :as cli])
(cli/dispatch {:tool-name "flow"
:namespaces '[flow.commands]})
Well, it's able to load namespaces under the root src
dir, so it's working for whatever reason.
Would you consider an extra switch on bb
to look upwards from the script file to find the bb.edn
?
Or, I suppose, could move the bb.edn
to the bin
dir, but that feels dirty for some reason.
I wonder what edge cases that might introduce. clj
doesn't support this either right?
I've tried a bunch of variations of #!/usr/bin/env bb --config "$(dirname $0)/../bb.edn"
but it doesn't look like you can do a shell expansion there, so I get error Message: File does not exist: $0)/../bb.edn"
I'm also curious about the space between "full blown project in its own git repo" (at least its own folder with a bb.edn
file) and "single file self contained script". I feel like I have to pick one or the other.
Not that I have any solutions to suggest 😄😅
Or just babashka.process/shell
:
So instead of the shebang you could do:
(babashka.process/shell "bb" "--config" "...")
But I wonder what is the problem behind the problem here. I never have this problem since I always launch scripts from the root:
script/foo.clj
bin/foo.clj
Not:
cd bin && ./foo.clj
I think I mentioned flow
in the 'cast. It's a tool I use all over the place (it's that personal tool you don't necessarily share with anyone). So I have that bin
directory on my $PATH
but I'm almost never in that root directory to execute it, so it has to be able to find that directory to find src
, resources
and dependencies.