Fork me on GitHub
#babashka
<
2024-01-05
>
reefersleep10:01:01

Still a bb noob. I'm trying to rewrite a bash script. One command is a long one-liner of commands piped together with various args. What's the easiest way to convert something like that to valid bb? And what's the most idiomatic/smartest? 😄 I tried just (shell "the-whole-thing"), but that was invalid, I guess because it needs to be tokenized. But perhaps it's better to convert into pb/`pipeline` usage?

borkdude10:01:36

You can also use process with ->

reefersleep10:01:46

So just use {:out :string} for the last command, then deref and :out

reefersleep10:01:59

(-> (process smth)
    (process smthelse)
    (process {:out :string} athirdthing)
    deref
    :out)

reefersleep10:01:03

Nice, got it working!

reefersleep10:01:28

Thought about doing the conversion programatically, but some string literals in the bash one-liner contained pipes, so I quickly gave in and converted by hand 🙂

Brett12:01:03

Any plans to support babashka pods (client) on ClojureDart ? Why do you ask ? Well, I have a couple of Clojure JVM dependencies that I would like to use in my Flutter app and I thought maybe a pod would be more convenient than something like JNI/JNA

borkdude12:01:12

There’s a couple of implementations of pod clients in other languages like python. Since this isn’t part of the bb binary anyone is free to implement and maintain that stuff for other languages. The protocol is documented. I can give you some guidance if you want

Brett13:01:58

Thanks for the answer. I'll have a look at the other implementations 👍

Akiz12:01:35

Is there a way to disable automatic decoding of URL-encoded characters in babashka.http-client ?

borkdude12:01:53

Can you give an example / some code?

Akiz12:01:18

It looks like once query-params are used then this url

(http/get "" {:headers {} :query-params {:ref "xx"}})
is decoded to But I still need I am calling a site that doesn’t work with decoded URL chars.

borkdude12:01:00

hmm let me take a look, I don't exactly remember what goes on

Akiz12:01:41

Thank you. Sometimes the workaround works, that you rewrite %2F to “%252F”, so you are left with %2F, but it doesn’t work here.

borkdude12:01:45

it seems the decoding only happens when you use :query-params, so a workaround could be to add those query-params yourself

borkdude12:01:22

it seems the roundtrip for the uri decodes stuff:

(java.net.URI. (.getScheme uri) (.getAuthority uri)
                                             (.getPath uri) new-query (.getFragment uri))

borkdude12:01:33

user=> (def uri (java.net.URI. ""))
#'user/uri
user=> (def uri2 (java.net.URI. (.getScheme uri) (.getAuthority uri) (.getPath uri)))
#'user/uri2
user=> uri2
#object[java.net.URI 0x5961e92d "https:foobar#/ok/"]

Akiz12:01:18

Thanks! adding query-params is a fine workaround.

borkdude13:01:10

shouldn't you write %25 to escape the percent maybe?