Fork me on GitHub
#babashka
<
2023-09-20
>
stopa15:09:31

Hey team, one more question. is there a way I can make my babashka script -main when executing, without explicitly invoking -main in the file? Context: ā€¢ I love being edit the script in conjure. But if I weI love being to edit the script in conjure. But if I evaled the whole file, it would end up running the script, which I don't want

teodorlu15:09:00

You can check if the current file is the file babashka was asked to execute. Example from my code: https://github.com/teodorlu/play.teod.eu/blob/ba8cc73f0aeb701c6c277cbd7879a2ed06d09956/play.clj#L5 Then your code works both as a script (-main is executed) and as a library (-main is not executed)

dpsutton15:09:48

> This can be exceedingly handy for editing complex scripts interactively, while not being able to adjust how they are invoked by other tools.

āž• 2
teodorlu15:09:39

Also, you can eval the whole script from your REPL without accidentally running anything -main.

stopa15:09:04

Wohoo! This works great -- thank you team

ā¤ļø 2
mmer16:09:20

I ended up using the bb tasks rather than a main as it allows me to have multiple entry points for the different 'tasks' I want to handle. The :init section parses the command line and then options are available to the individual tasks.