Fork me on GitHub
#babashka
<
2021-06-01
>
borkdude09:06:39

@nicolas.estrada938 Decided to add support to bb for this trailing map and StackTraceElement. I'm building a new bb version now

โค๏ธ 3
borkdude09:06:48

I also tested omniconf and it worked after those fixes

Nicolas Estrada09:06:21

You my friend are a saint! ๐Ÿ™‚

borkdude10:06:26

Fun side effect of including StackTraceElement in bb is that you can inspect some of bb/sci's runtime ;)

$ bb -e '(->> (try (/ 1 0) (catch Exception e (.getStackTrace e))) (map bean) clojure.pprint/print-table)'

| :classLoaderName |        :fileName | :moduleVersion | :nativeMethod |                              :className | :moduleName |                            :class | :lineNumber |  :methodName |
|------------------+------------------+----------------+---------------+-----------------------------------------+-------------+-----------------------------------+-------------+--------------|
|                  |     Numbers.java |                |         false |                    clojure.lang.Numbers |             | class java.lang.StackTraceElement |         188 |       divide |
|                  |         core.clj |                |         false |                    clojure.core$_SLASH_ |             | class java.lang.StackTraceElement |        1029 | invokeStatic |
|                  |         core.clj |                |         false |                    clojure.core$_SLASH_ |             | class java.lang.StackTraceElement |        1022 |       invoke |

๐Ÿ™Œ 3
borkdude11:06:27

This is pretty cool too. Get info about another process:

$ bb -e '(.info (.get (java.lang.ProcessHandle/of 39045)))'
#object[java.lang.ProcessHandleImpl$Info 0x6bd723ed "[user: Optional[borkdude], cmd: /Applications/Emacs.app/Contents/MacOS/Emacs-x86_64-10_14, startTime: Optional[2021-05-28T08:59:27.973Z]]"]

borkdude11:06:53

so with this you can get command line arguments, the exact binary location of what the process was started with, arguments, etc

Nom Nom Mousse12:06:09

There is supposed to be an alternative to clojure.java.shell/sh in babashka. What is it called?

Nom Nom Mousse12:06:25

And can I do (bb/sh "ecco my command is just a string") with it? (clojure.java.shell/sh "echo hi") fails with

Execution error (IOException) at java.lang.ProcessImpl/forkAndExec (ProcessImpl.java:-2).
error=2, No such file or directory

Nom Nom Mousse12:06:20

I do not want to split my command string into whitespace as that might not be easy "ecco 'hi there'":

(clojure.java.shell/sh (clojure.string/split "echo 'hi there'" #" "))
Execution error (IllegalArgumentException) at clojure.java.shell/parse-args (shell.clj:47).
No value supplied for key: ["echo" "'hi" "there'"]

Nom Nom Mousse12:06:01

With apply it works. But I wonder whether this might ever break a command line string.

borkdude12:06:59

@endrebak The alternative in babashka is babashka.process/process

borkdude12:06:22

The same library has a function called tokenize to split shell functions for you

borkdude12:06:19

If you want to invoke a shell command just like how you could do it in the shell, streaming output directly to stdout/stderr, then you could also use (babashka.tasks/shell "echo 'hi there'")

borkdude12:06:20

user=> (do @(babashka.tasks/shell "echo 'hi there'") nil)
hi there
nil

Nom Nom Mousse13:06:53

Syntax error (ClassNotFoundException) compiling at (*cider-repl code/myapp:localhost:56301(clj)*:32:12).
babashka.tasks
My lein coords are:
[babashka/babashka "0.4.4"]

Nom Nom Mousse13:06:22

Also tried:

(require '[babashka.impl.tasks :as tasks])

Syntax error (IllegalArgumentException) compiling . at (borkdude/deps.clj:196:12).
More than one matching method found: newFileSystem

borkdude13:06:05

Hmm, babashka isn't really supposed to be used as a JVM project. I was assuming you were using babashka as a tool

borkdude13:06:22

But the libraries contained in there, such as babashka.process, are available on the JVM

Nom Nom Mousse13:06:15

Cool! It seems like clojure.java.shell/sh does not support many simple commands like:

(clojure.java.shell/sh "sleep" "1" ";" "echo" "2")
;; => {:exit 1, :out "", :err "usage: sleep seconds\n"}
So I'll be looking into babashka :thumbsup:

borkdude13:06:56

The problem there is that ";" is bash syntax

borkdude13:06:03

if you want to invoke bash, you could invoke bash

borkdude13:06:17

with e.g. bash -c "echo hello"

Nom Nom Mousse13:06:40

Thanks ๐Ÿ™‚

borkdude12:06:03

2000+ stars! https://github.com/babashka/babashka/stargazers :star-struck:

โค๏ธ 18
๐Ÿ™ 12
๐ŸŒŸ 15
๐Ÿ‘ 3
Karol Wรณjcik12:06:37

Well deserved! Congrats!

borkdude16:06:39

So this now works @ben.sless

{:tasks
 {:init (do (def ^:dynamic *java*)
            (def ^:dynamic *browser*))
  test-front-end (println :browser *browser*)
  test-back-end (println :java *java*)
  test-app {:depends [test-front-end test-back-end]}
  run-matrix (doseq [java [8 11]
                     browser ["Safari" "Chrome" "Firefox"]]
               (binding [*java* java
                         *browser* browser]
                 (run 'test-app)))}}
The previous issues are fixed.

๐Ÿ’ช 6
๐Ÿ‘ 3
Ben Sless16:06:32

First, that's pretty cool, ngl, going to try it out Second, have you had a chance to give some thought to my suggestion regarding adding a :matrix key to tasks? I'm willing to donate a hammock ๐Ÿ™‚

borkdude16:06:05

Haven't thought through the matrix yet ;)