is bb doc
not supported? tasks are looking good. depends are looking good, and bb doc
should show depends!
Not yet for tasks, I will fix that soon
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.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
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! 🙂
@pithyless Interesting! the clojure CLI also supports passing map args as EDN, was that your inspiration?
yes
actually, I was hoping there was some code I could call directly, but my brief search was not fruitful
so I ended up heavily borrowing the ideas from this post: https://vlaaad.github.io/tools-cli-in-10-lines-of-code
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
and I could imagine that we could just merge mutiple maps (maybe part of it is just pulled from some file/env/wherever)?
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
?
(it's a migration script)
it seems from the manual that running a uberjar
would not allow me to call two different namespaces/files?
@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.
I documented here: https://book.babashka.org/#_scripts what the scripting alternatives are for the i/o flags
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
Just wanted to process things lazily from the shell piping as they come
When using an uberjar the main function must be set when creating the uberjar
or you can invoke it like this: bb -cp foo.jar -m foo
You can still do that, using *in*
$ echo '1 2 3' | bb -e '(take-while #(not= % ::EOF) (repeatedly #(edn/read {:eof ::EOF} *in*)))'
(1 2 3)
that is a lazy seq of edn vals from stdin
Yes that's what I am doing and I have a def at the top level for that. So do one-liners need them?
@borkdude 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
I don't understand your question. If you use the above construction, you don't need any special flags
I think you would need to create one main function that combines the two
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?
you can do bb -cp my.jar -m my-foo.main
so bb -cp my.jar -m foo/main1 | bb -cp my.jar -m foo/main1
but why use a pipe between two functions if you can just process the data within one process?
because I want to expose the intermediate result and possibly re-run it
it's some form of aid for my operators
the intermediate result can be inspected for problems, solve them, then run against it multiple times
thank you I will try your solution, it looks like it might work
never mind, I wanted to just understand when I need -IO
if at any point I can use *in*
what do these flags do under the hood basically, but I am checking the source right now no worries
the flags i
and I
influence the value of *input*
and -o
or -O
influence how results get printed
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
correct
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 😄does $uberjar_path
have the correct value?
@richiardiandrea I see, the expected directory structure here is image_migration/insert-images.bb
, not with src
prefixed
so I think something went wrong in your uberjar production
uhm ok let me see there
bb.edn is
{:paths ["src" "resources"]}
and I call bb uberjar $(UBERJAR)
in a Makefile
ah I see... there is a bug here. the uberjar task does not yet take into account bb.edn :/
I logged an issue for this
ok glad we found it
so for now you will have to do it like this:
bb -cp src:resources uberjar $(UBERJAR)
FYI the command with no -cp
before was including all the files in the folder where you were executing it
yeah, that's also not good.
this one now just includes the correct stuff in -cp
yeah
but this one works! bb -cp "src:resources" --uberjar $(UBERJAR)
🎉
cool! I logged the issue here: https://github.com/babashka/babashka/issues/776
PR ready for the former issue https://github.com/babashka/babashka/pull/777