Fork me on GitHub
#babashka
<
2021-09-16
>
Darin Douglass19:09:05

is there a way to get the bb invocation when running a task? i’d like to dynamically build out the usage section within our tasks that have a “proper” -h/--help flag

borkdude19:09:16

@douglassdarin The Java way :)

$ bb -e '(-> (java.lang.ProcessHandle/current) .info .command .get)'
"/Users/borkdude/Dropbox/bin/bb"
$ bb -e '(-> (java.lang.ProcessHandle/current) .info .arguments .get vec)' 1 2 3
["-e" "(-> (java.lang.ProcessHandle/current) .info .arguments .get vec)" "1" "2" "3"]

borkdude19:09:54

or did you mean *command-line-args* ?

Darin Douglass19:09:08

no the actual invocation bb <some task name> ...

borkdude19:09:18

yeah, you'll need the the first one then

borkdude19:09:26

There is also a babashka.task System property

borkdude19:09:34

that contains the name of the currently invoked task from the command line

Darin Douglass19:09:36

oh, nice. thats simple enough

borkdude19:09:48

it's only populated when you invoke from the cmd line

borkdude19:09:54

not when you call run

2