Fork me on GitHub
#babashka
<
2021-04-06
>
grazfather00:04:07

is bb doc not supported? tasks are looking good. depends are looking good, and bb doc should show depends!

borkdude06:04:31

Not yet for tasks, I will fix that soon

馃憤 3
pithyless11:04:42

I've played with 0.3.1 before the weekend and came up with this kind of pattern:

bb -m my.runner/run some.ns/fn :a b :c 123 :d '#{:e :f "g" [:h]}'
So it works just like the tasks demo, but it will parse all args as EDN and will coerce unqualified symbols to strings (so in this case b would be a string argument). The nice thing about this is that all my tasks now just take a map of options, so I can reuse all the destructuring syntax without having to manually parse CLI arguments and the functions compose nicely. I'm kind of assuming I can pass in a flat map of keyword arguments and each task can just consider the ones it's actually interested in.

pithyless11:04:19

Since I'm wrapping the babashka main functionality, I could add some conveniences: if you pass an unqualified symbol as the first argument, it assumes you're calling a function in the tasks ns; and I also have a my.runner/doc that is similar to bb doc and a my.runner/echo which is kind of a --dry-run debug

pithyless12:04:13

I'm wondering if the parsing of CLI arguments as a map of keyword/edn-values may be popular enough to be supported more directly by a babashka helper (ala process/tokenize ). Either way, just giving a positive experience report -- and bb.edn is very helpful! 馃檪

馃憤 3
borkdude12:04:22

@pithyless Interesting! the clojure CLI also supports passing map args as EDN, was that your inspiration?

pithyless12:04:07

actually, I was hoping there was some code I could call directly, but my brief search was not fruitful

pithyless12:04:17

so I ended up heavily borrowing the ideas from this post: https://vlaaad.github.io/tools-cli-in-10-lines-of-code

pithyless12:04:23

I actually considered the idea of "default args", "command args", and "env args" could all be considered the same thing, if we try to map the CLI to the Clojure idea of flat maps with fully-qualified keywords. So maybe instead of: SOME_ENV=... command --verbose --some=args we could just say runner some.ns/command :some.env/stuff :value1 :some.cmd/arg :value2 :verbose true

pithyless12:04:02

and I could imagine that we could just merge mutiple maps (maybe part of it is just pulled from some file/env/wherever)?

richiardiandrea17:04:59

Hi there I have two babashka scripts that parse lines of edn from stdin, is there any practical difference between using a straight -f vs using a main with -m?

richiardiandrea17:04:06

as a requirement, my scripts are going to be uberjarred and I need to launch them separately in a pipe. This is what I am doing at the moment:

$script_dir/api-report-images-csv.sh \
  | bb -i -O -f "$script_dir/src/image_migration/csv_to_image_todos.bb" \
  | bb -I -O -f "$script_dir/src/image_migration/insert_images.bb" \
  > $result_todos_edn_path

richiardiandrea17:04:22

(it's a migration script)

richiardiandrea18:04:33

it seems from the manual that running a uberjar would not allow me to call two different namespaces/files?

richiardiandrea20:04:06

@U04V15CAJ sorry I also had this side question 馃槂 I have.inspected the code and depstar only triggers one main. I basically need to call two mains 馃槂 in two different namespaces

borkdude20:04:49

I think you would need to create one main function that combines the two

richiardiandrea20:04:55

yeah that is not possible cause the two are piped one to the other in the script...can I do something like bb my.jar -m my-foo.main and then bb my.jar -m my-bar.main at the moment?

borkdude20:04:29

you can do bb -cp my.jar -m my-foo.main

borkdude20:04:10

so bb -cp my.jar -m foo/main1 | bb -cp my.jar -m foo/main1

borkdude20:04:09

but why use a pipe between two functions if you can just process the data within one process?

richiardiandrea20:04:25

because I want to expose the intermediate result and possibly re-run it

richiardiandrea20:04:41

it's some form of aid for my operators

richiardiandrea20:04:09

the intermediate result can be inspected for problems, solve them, then run against it multiple times

richiardiandrea20:04:36

thank you I will try your solution, it looks like it might work

richiardiandrea21:04:30

well no it does not seem to work... This is what I see with jar -tf my-jar

bb.edn
src/
src/image_migration/
src/image_migration/insert_images.bb
src/image_migration/csv_to_image_todos.bb
But then when I run bb -cp "$uberjar_path" --verbose -m image-migration.csv-to-image-todos/-main It throws a:
----- Error --------------------------------------------------------------------
Type:     java.lang.Exception
Message:  Could not find namespace: image-migration.csv-to-image-todos.
Location: <expr>:1:10
I am trying to understand now if I am donig something obviously stupid 馃槃

borkdude21:04:52

does $uberjar_path have the correct value?

borkdude21:04:00

@richiardiandrea I see, the expected directory structure here is image_migration/insert-images.bb, not with src prefixed

borkdude21:04:13

so I think something went wrong in your uberjar production

richiardiandrea21:04:13

uhm ok let me see there

richiardiandrea21:04:54

bb.edn is

{:paths ["src" "resources"]}
and I call bb uberjar $(UBERJAR) in a Makefile

borkdude21:04:14

ah I see... there is a bug here. the uberjar task does not yet take into account bb.edn :/

borkdude21:04:18

I logged an issue for this

richiardiandrea21:04:32

ok glad we found it

borkdude21:04:53

so for now you will have to do it like this:

bb -cp src:resources uberjar $(UBERJAR)

馃挴 3
richiardiandrea21:04:55

FYI the command with no -cp before was including all the files in the folder where you were executing it

borkdude21:04:10

yeah, that's also not good.

richiardiandrea21:04:13

this one now just includes the correct stuff in -cp

richiardiandrea21:04:02

but this one works! bb -cp "src:resources" --uberjar $(UBERJAR) 馃帀

richiardiandrea17:04:06

as a requirement, my scripts are going to be uberjarred and I need to launch them separately in a pipe. This is what I am doing at the moment:

$script_dir/api-report-images-csv.sh \
  | bb -i -O -f "$script_dir/src/image_migration/csv_to_image_todos.bb" \
  | bb -I -O -f "$script_dir/src/image_migration/insert_images.bb" \
  > $result_todos_edn_path

borkdude19:04:45

@richiardiandrea I don't recommend using the -i -O flags with scripts really, they were mostly designed for one-liners. Just use edn/read if you need to read multiple lines of edn for example.

richiardiandrea19:04:49

Just wanted to process things lazily from the shell piping as they come

borkdude19:04:46

You can still do that, using *in*

borkdude19:04:05

@richiardiandrea

$ echo '1 2 3' | bb -e '(take-while #(not= % ::EOF) (repeatedly #(edn/read {:eof ::EOF} *in*)))'
(1 2 3)

borkdude19:04:17

that is a lazy seq of edn vals from stdin

richiardiandrea19:04:01

Yes that's what I am doing and I have a def at the top level for that. So do one-liners need them?

borkdude20:04:01

I don't understand your question. If you use the above construction, you don't need any special flags

richiardiandrea20:04:29

never mind, I wanted to just understand when I need -IO if at any point I can use *in*

richiardiandrea20:04:59

what do these flags do under the hood basically, but I am checking the source right now no worries

borkdude20:04:11

the flags i and I influence the value of *input* and -o or -O influence how results get printed

richiardiandrea20:04:46

oh I see, so -o/`-O` is basically only useful if I don't println/`prn` myself and the script ends evaluating to a data structure...gotcha that makes sense

borkdude21:04:23

correct

鉂わ笍 3
borkdude19:04:13

I documented here: https://book.babashka.org/#_scripts what the scripting alternatives are for the i/o flags

馃憦 3
borkdude19:04:25

There is not really a practical difference between -f and -m. The main difference is that with -m the function you are invoking is explicit and with -f it's implicit via side effects

borkdude19:04:09

When using an uberjar the main function must be set when creating the uberjar

borkdude19:04:24

or you can invoke it like this: bb -cp foo.jar -m foo