Fork me on GitHub
#babashka
<
2023-12-21
>
ag01:12:39

I'm trying to run a simple task that uses a function that is defined in ./scripts/ file. Like this: bb.edn

{:paths ["scripts"]
 :deps {borkdude/rewrite-edn {:mvn/version "0.4.7"}}
 :tasks
 {foo {:doc "foo"
       :requires ([scripts.foo])
       :task (prn "foo")}}}
and I have: ./scripts/foo.clj
(ns scripts.foo)

(defn foo-bar []
  (println "foobar"))
Here's how the dir looks:
.
├── README.md
├── bb.edn
├── deps.edn
├── scripts
│   └── foo.clj
When I do bb tasks, it shows it. But when I run it: bb foo or bb run foo, it can't find it:
Type:     java.io.FileNotFoundException
Message:  Could not locate scripts/foo.bb, scripts/foo.clj or scripts/foo.cljc on classpath.
WAT?

1
Bob B01:12:53

I believe that the scripts dir is on the 'classpath', so you could change paths to just ["."], or change the ns structure to be rooted in ./scripts instead of .

ag01:12:26

Nope, I tried that too, that not helping

Bob B01:12:33

womm - what is it doing when you update foo.clj and bb.edn to just foo as the ns?

Bob B01:12:30

womm => works on my machine

ag01:12:52

I get that, I don't understand the question

Bob B01:12:05

./scripts/foo.clj
(ns foo) <-- change this to foo

(defn foo-bar []
  (println "foobar"))
./bb.edn
{:paths ["scripts"]
 :deps {borkdude/rewrite-edn {:mvn/version "0.4.7"}}
 :tasks
 {foo {:doc "foo"
       :requires ([foo]) <-- change this to foo
       :task (prn "foo")}}}

ag01:12:50

Ah... you know what happened? I previously ran: export BABASHKA_CLASSPATH=$(clojure -Spath) and totally forgot about that

ag01:12:12

Thank you for your help!

👍 1
ag01:12:15

btw, why :tasks :doc doesn't work with (str "bla-bla-bla")? Is there an issue to track?

Bob B02:12:46

I imagine that it's because bb.edn is an edn file, so most things aren't executed by default. Presumably this and related functionality would require executing code from the edn file to list tasks. I don't see an existing feature request in the repo for it.

👍 2
Matthew Twomey06:12:51

I’d like to get the (PEM formatted) ssl cert from a mqtt broker using babashka. From the command-line I can do it with this:

openssl s_client -connect HOST:8883 -showcerts < /dev/null 2> /dev/null | sed -n '/BEGIN/,/END/p' >/tmp/bbl.crt
I’d like to get it from within a babshka script however and I’m wondering if there is a way to do it without shelling out?

borkdude07:12:47

Have you searched how to do it via Java interop?

Matthew Twomey07:12:35

No - because I thought that bb wouldn’t have the classes. But let me look.

borkdude08:12:48

Sometimes bb does have those classes because someone a year ago asked for them :)

Matthew Twomey17:12:21

Ok - so I haven’t done a ton of interop stuff. I think I need javax.net.ssl whic does appear to be in bb. However, when I try to (.createSocket (.ssl.HttpsURLConnection/getDefaultSSLSocketFactory)) I get clojure.lang.ExceptionInfo: Method createSocket on class sun.security.ssl.SSLSocketFactoryImpl not allowed! user *cider-repl Git_Repos/bbl:127.0.0.1:59425(clj)*:1:2 I am not sure if this is something I’m doing wrong, or something else. Any hints?

borkdude18:12:20

what is the final Java program that leads to the goal of getting the certificates?

borkdude18:12:33

first try it in clojure (JVM) maybe

Matthew Twomey20:12:42

I’m working in JVM clojure now and I do get past the error I listed above ( (.createSocket (.ssl.HttpsURLConnection/getDefaultSSLSocketFactory)) Works fine. However, now I’m running into issues with reify for the custom X509 trust manager. That’s a different thing though. At this point I’m trying to get a sense on if this is ultimately going to not workout in bb and if I should just bite the bullet and shell out for it.

borkdude20:12:25

@U0250GGJGAE Ah got it. In babashka.http-client I'm doing something very similar and I think you could just copy that and modify it

Matthew Twomey20:12:47

Oh - ok, I’ll look at that code, ty.

Matthew Twomey20:12:45

I was just about to try that over reify

Matthew Twomey20:12:55

ok, thanks - will try this 👍

borkdude20:12:28

probably then don't go through HttpsUrlConnection but through java.net.http stuff which is fully supported in bb

Matthew Twomey20:12:59

Ok, thanks a lot for the pointer - I appreciate you 🙂

😀 1
John Doe13:12:06

empty bb.edn will blowup babashka, while bb.edn with empty map won't, does this consider a bug for bb 😄 https://clojure.atlassian.net/browse/TDEPS-239

borkdude13:12:13

yeah ok :)

$ bb -Sdeps ''
Error during loading bb.edn:
Exception in thread "main" java.lang.RuntimeException: EOF while reading

borkdude13:12:21

issue welcome

seancorfield17:12:41

bb matches the behavior of clojure here:

(~/clojure)-(!2002)-> mkdir q && cd q && touch deps.edn && clj
Error building classpath. Expected edn map in: /home/sean/clojure/q/deps.edn

Thu Dec 21 09:27:59
(~/clojure/q)-(!2003)-> echo '{}' > deps.edn && clj
Clojure 1.11.1
user=>

👍 1
seancorfield17:12:12

(although clj -Sdeps '' works fine, strangely)

borkdude17:12:54

TDEPS-239 seems to indicate that it's going to be fixed though?

borkdude17:12:07

(linked in OP)

seancorfield17:12:21

> it's going to be fixed Eventually, maybe 🙂 Perhaps.

Otto Nascarella16:12:44

hey beloved babashka peeps I’ve been thinking about interactive cli patterns… like when you have several options, and you want the user to select one of them then the user can start typing and filter the list… does anyone know any bb plugins/bash programs that can do that? I know https://invisible-island.net/dialog/, but that opens a whole menu. It’s cool for some use cases, but I wanted something that is straight in the command line…. much like assume from https://granted.dev does…

Otto Nascarella17:12:34

this is pretty. thanks for the xmas gift ❤️

🎉 1