Any way to get the contents of a jar in bb?
@kevin.van.rooijen yes, look at examples/ls_jar.clj
Amazing
Works as a little sun. Thanks
I could use edamame.core/parse-string
in bb. Any chance we can include this in the clojure.edn NS? Or is there another way to include this?
Currently tripping over the #()
reader with clojure.edn
. Which was fixed in edamame
@kevin.van.rooijen you can use read-string
in bb as well
which is basically edamame
$ bb -e '(read-string "#()")'
(fn* [] ())
Let me try that 🙂
hmm
clojure.lang.ExceptionInfo: Read-eval not allowed. Use the
:read-eval` option`
but read-string in bb doesn't accept 3 args?
*read-eval*
is also undefined
currently read-string is a bit under-developed. but read-eval is turned off by default in edamame
you could post an issue about what you expect to work, but I expect read-string to be safe by default in bb currently
Yeah I don't actually want to eval anything. I just want the form
I guess it makes sense for this to crash (read-string "#=(+ 1 2 3))")
Actually I think I'd expect (eval '(+ 1 2 3))
edamame currently doesn't even support this, nobody has ever asked for this before. edamame just returns (read-eval (+ 1 2 3))
when you pass :read-eval true
but doesn't have a callback for evaluating it, which we of course can include
so currently bb crashes when you try to do this
So maybe the sane behavior would be to do it exactly as clojure. PR welcome
1) The first step would be to fix edamame to support a read-eval function which gets the expression and then can eval it
2) Fix read-string in bb or sci (not sure where it is currently). I think in the case of sci it could make sense to disallow it by default unless someone passes a setting. In bb we can enable this setting by default.
Does it hurt anyone if we allow it in sci by default?
security-wise
you're evaluating already anyway, so maybe not
For my use case I don't actually want anything evalled though
Yes, so you can set *read-eval*
to false, like in clj.
3) Include *read-eval*
in sci
But doesn't it just crash, like in clj? https://clojuredocs.org/clojure.core/*read-eval*#example-542692d1c026201cdc326f3a
yes. so you want to parse code which contains it but not eval it? why?
Currently I just want to get all the functions in a namespace, without having to require it
Not sure if edamame has any magic for that
you are parsing defn etc manually?
I think clj-kondo is a much better tool for this.
$ clj-kondo --config '{:output {:analysis true :format :edn}}' --lint - <<< '(defn foo [])' | puget
{:analysis {:namespace-definitions [],
:namespace-usages [],
:var-definitions [{:col 1,
:filename "<stdin>",
:fixed-arities #{0},
:name foo,
:ns user,
:row 1}],
:var-usages [{:arity 2,
:col 2,
:filename "<stdin>",
:from user,
:macro true,
:name defn,
:row 1,
:to clojure.core,
:varargs-min-arity 2}]},
:findings [],
:summary {:duration 35,
:error 0,
:files 1,
:info 0,
:type :summary,
:warning 0}}
Ahh, that might be exactly what I need
you can use clj-kondo as a babashka pod as well, for scripting
Very cool, I'll try that. Thanks
@kevin.van.rooijen if you're using this from emacs, you might also want to look at anakondo: https://github.com/didibus/anakondo
oh wow
I did not know about this
Private functions can't be called in bb? Trying to figure out what this function results in (#'babashka.curl/curl-command {})
that function just isn't exposed in the bb sci config (if you have watched the internals talk, you will know what I mean)
but if you run babashka.curl from source, you should be able to do that
Haven't watched that yet 😛
Yeah I'll just clone it
Trying to pass in a cookie but not sure how / if it's possible
@kevin.van.rooijen if you want to see the command, you can also do (:command (curl/get "foobar" {:debug true}))
$ bb -e "(:command (curl/get \"<https://babashka.org>\" {:debug true}))"
["curl" "--silent" "--show-error" "--location" "--dump-header" "/var/folders/2m/h3cvrr1x4296p315vbk7m32c0000gp/T/babashka.curl8448783184890828476.headers" "--compressed" "<https://babashka.org>"]
Cookies are passed using :headers
they are just that
Ahh ok, I assumed I have to use the --cookie
arg in curl
That might be better, I haven't used it that way yet. But Cookie is just an HTTP header, so something like this should also work:
$ bb -e '(org.httpkit.server/run-server (fn [req] (clojure.pprint/pprint req) {:body "hello"}) {:port 3000}) (curl/post "<http://localhost:3000>" {:headers {"Cookie" "name=dude; foo=bar"}}) nil'
{:remote-addr "0:0:0:0:0:0:0:1",
:headers
{"accept" "*/*",
"accept-encoding" "deflate, gzip",
"cookie" "name=dude; foo=bar",
"host" "localhost:3000",