Fork me on GitHub
#babashka
<
2023-08-18
>
pesterhazy08:08:06

Is there a way to make -x work with positional args, or are only named args supported?

bb -x my/f a b c
I tried :opts->args but that doesn't seem to work

pesterhazy08:08:49

I guess I can use *command-line-args* directly?

borkdude08:08:24

-x expects key-value pairs, like -X in Clojure

pesterhazy08:08:55

Looks like *command-line-args* contains the remaining args, so I'll use that. Unless that's unsafe?

borkdude08:08:20

no sorry I was wrong, positional args work, like this:

(ns dude)

(defn foo
  {:org.babashka/cli {:coerce {:a []}}}
  [{:keys [a b c]}]
  (prn [a b c]))

borkdude08:08:27

$ bb -cp /tmp -x dude/foo -a 1 2 3 -b 1 -c 2
[[1 2 3] 1 2]

borkdude08:08:38

or do you mean, remaining arguments?

pesterhazy08:08:14

oh I meant that I want to pass in a bunch of files names, like a.txt b.txt c.txt

borkdude08:08:14

(ns dude)

(defn foo
  {:org.babashka/cli {:coerce {:a []}}}
  [{:keys [a b c] :as m}]
  (prn (meta m))
  (prn [a b c]))
$ bb -cp /tmp -x dude/foo -a 1 2 3 -b 1 -c 2 1 2 3
#:org.babashka{:cli {:args ["1" "2" "3"]}}
[[1 2 3] 1 2]

borkdude08:08:28

yeah, you can get this via the metadata of the passed map

pesterhazy08:08:26

oh the metadata 🤯

pesterhazy08:08:25

cool cool cool thanks! 🙂

👍 2
james09:08:43

Hard to to search for

$ bb
Babashka v1.3.182 REPL.
Use :repl/quit or :repl/exit to quit the REPL.
Clojure rocks, Bash reaches.

user=> (->> (babashka.process/shell "ls -l /tmp/*"  {:out :string})
       :out)
ls: cannot access '/tmp/*': No such file or directory
clojure.lang.ExceptionInfo [at <repl>:1:6]
user=> 
This works fine if I drop the * Guessing that sci is doing something to the * before it gets to the shell. I get the same output on mac and linux.

borkdude09:08:12

* is a bash-ism. process does not launch bash, it only launches programs

💡 2
borkdude09:08:50

if you want to list files from a directory, you can use fs/list-dir

james09:08:59

I see. I was trying to do a tar cvzf something.tgz /tmp/something* when I hit the issue. I'll work around it, Thanks for the clarification.

borkdude09:08:58

you can shell out to bash if you want. (shell "bash -c '...'")

james09:08:36

the fs api is great, I think I'll lean in to it to solve this one. Much appreciated.

👍 2
mmer12:08:07

(could be wrong channel to ask this) I use calva and it would be good if it were aware of the bb.edn file usage of functions.

borkdude12:08:23

It's probably best to minimize the amount of code in bb.edn and just require an external file and do the coding in there

pez12:08:26

How do you want Calva to be aware? (Calva maintainer here.)

mmer12:08:33

I really only have the calls to the entry points for each task, but it would be good to a have help when creating the function calls and also show that a function is used.

👍 2
mmer12:08:53

@U0ETXRFEW what I notice is that the functions that are used as the entry points show as unused, in someways helpful as you can find them, but in otherways it also keeps making me think I have made an error somewhere.

borkdude12:08:34

this is probably a clojure-lsp issue

borkdude12:08:46

can you navigate to the function from bb.edn?

pez12:08:51

I don’t know what’s possible here. This is functionality that Calva sources from #CPABC1H61 and. by proxy, #CHY97NXE2. @U04V15CAJ knows more about what’s involved. 😃

mmer12:08:40

It is a bit of a strange request as you are in effect tying an .edn file as if it were a code file, which is unusual for tools to pick up on.

mmer12:08:33

No you can't navigate from bb.edn file.

borkdude12:08:02

@U4C3ZU6KX navigation from edn files to functions does work when the symbol is fully qualified

borkdude12:08:15

e.g. foo.bar/baz should work

borkdude12:08:33

clj-kondo could try to support code in bb.edn a bit more

borkdude12:08:04

feel free to post an issue about it

borkdude12:08:23

with some examples. let's take a tiny step to begin with

mmer12:08:04

I am not seeing that. I have :

:tasks   {:requires ([convert.core :as  core]
                      [convert.utils :as utils]
                      [clojure.tools.cli :as cli])
          convert (do
                          (println "Converting " (:import-dir options))
                          (core/handle-conversion (:import-dir options)  (:export-dir options)))}

mmer12:08:58

And the core/handle-conversion shows No Definition when I use Go to Definition.

borkdude12:08:14

try convert.core/handle-conversion

mmer12:08:17

Thanks that worked. That just leaves the showing as unused in the convert.core.clj file.

borkdude12:08:36

ok, the latter can be solved in #CPABC1H61

borkdude12:08:15

but perhaps clj-kondo could try to better support bb.edn file by transforming the code and then linting that

borkdude12:08:20

issue welcome

mmer12:08:33

Where do I raise it?

mmer12:08:49

OK will do.

🙏 2