Fork me on GitHub
#babashka
<
2020-12-12
>
frederic10:12:44

I've recently started using https://asdf-vm.com/#/ to handle my programming language versions. There wasn't a babashka plugin for it yet, so I https://github.com/fredZen/asdf-babashka. I haven't submitted a pull request to add it to the http://list%20https://asdf-vm.com/#/plugins-all, but that would be my next step.

babashka 1
borkdude10:12:19

Awesome. Feel free to PR some docs for the install instructions (please use [skip ci] in the commit message for only doc PRs)

David Pham12:12:00

Hello 🙂 I am referring to this issue on jet (https://github.com/borkdude/jet/issues/74) I have an issue, I don't know how to solve: how do you transform the input stream *in* as string?

borkdude12:12:27

@neo2551 (slurp *in*) :)

David Pham12:12:34

thhanks 🙂

David Pham12:12:20

I get an exception: stream closed.

David Pham12:12:31

let me check

borkdude12:12:26

you can only read from it once

borkdude12:12:31

@neo2551

$ bb '(keys (yaml/parse-string (slurp *in*)))' < .circleci/config.yml
(:version :jobs :workflows)

David Pham12:12:55

Yep, my problem was for jet, the main read from a stream and expect to do so.

David Pham12:12:12

So I am circumventing the problem the problem by not supporting conversion from yaml

David Pham12:12:25

(I know it is weak)

borkdude12:12:29

I don't quite follow.

David Pham12:12:48

[reader (case from
                         :json (formats/json-parser)
                         :transit (formats/transit-reader)
                         :edn nil)
                next-val (case from
                           :edn #(formats/parse-edn edn-reader-opts *in*)
                           :json #(formats/parse-json reader keywordize)
                           :transit #(formats/parse-transit reader))
                collected (when collect (vec (take-while #(not= % ::formats/EOF)
                                                         (repeatedly next-val))))]
This is from the main namespace of jet. I did not manage to make work with input stream here.

borkdude12:12:17

but I'm not sure what the problem is you're running into

David Pham12:12:45

in the namespace there is a loop somehow, and if you slurp the *in* once, it will throw an error.

borkdude12:12:56

@neo2551 Let's discuss this in #jet

borkdude20:12:42

(defn clojure
  "Starts clojure similar to CLI. Use `rlwrap bb` for `clj`-like invocation.
  Invokes java with babashka.process/process for `-M`, `-X` and `-A`
  and returns the associated record. Default options passed to
  babashka.process/process are:

  {:in  :inherit
   :out :inherit
   :err :inherit
   :shutdown p/destroy-tree}

  which can be overriden with opts.

  Returns `nil` and prints to *out* for --help, -Spath, -Sdescribe and
  -Stree.

  Examples:

  (-> (clojure '[-M -e (+ 1 2 3)] {:out :string}) deref :out) returns
  \"6\n\".

  (-> @(clojure) :exit) starts a clojure REPL, waits for it
  to finish and returns the exit code from the process."
  ...)
^ proposal for babashka.deps/clojure, a function to launch a Clojure process from within babashka (without installing additional tools but java).

borkdude21:12:01

Here's a screenshot for how it's supposed to work:

borkdude22:12:09

$ bb "(->> (deps/clojure '[-X:deps tree :format :edn] {:out :string}) deref :out edn/read-string :children keys (take 2))"
(org.clojure/clojure org.clojure/tools.cli)