babashka / bbin

Install any Babashka script or project with one command
MIT License
139 stars 9 forks source link

Add ability to pick which script is installed if repo provides multiple #18

Open justone opened 2 years ago

justone commented 2 years ago

Awesome project, thanks for creating it! I tried it out and everything is working so far.

I have a repo containing multiple babashka scripts, each with its own main.

For now, I need to specify the main opts and the script name on the bbin install line, like this:

bbin install --as empath io.github.justone/bb-scripts --main-opts '["-m" "empath"]'

Since the :bbin/bin value in the repo's bb.edn file is a map, how about supporting a way of picking which script is installed? Something like this:

bbin install io.github.justone/bb-scripts --select empath

It could even be extended to support an :all keyword to install all scripts found.

Thanks again.

rads commented 2 years ago

Thanks for creating this issue. It's definitely something I've had in mind while building the initial version, even though I had to leave it out.

Right now we assume there is only one entry in :bbin/bin, so we need to think how we can support multiple entries while still prioritizing the more common case of having one script per lib.

What should happen if a lib has multiple scripts in :bbin/bin and --select is not provided? Do we error out?

What about providing a default script to install when there are multiple? Should this be supported? Perhaps a lib author could add a key in the script config such as :bbin/default true?

justone commented 2 years ago

Yeah, I think having a :bbin/default key to true is a good idea. As I was reading your comment, that's what came to mind. I think it might be good in that case to print a message like this:

io.github.justone/bb-scripts provides multiple scripts. Installing "foobar" by default.

That also makes me think that there could be a way of discovering what scripts are available. Perhaps:

bbin install io.github.justone/bb-scripts --list

That way the above "default" message can include a hint about running with --list as can the error message when no script is selected and there isn't a default.

$ bbin install io.github.justone/bb-scripts
io.github.justone/bb-scripts provides multiple scripts. Installing "foobar" by default.
...
Run "bbin install io.github.justone/bb-scripts --list" to see all available scripts.
$ bbin install io.github.justone/bb-scripts --list
empath
penv
comb
$ bbin install io.github.justone/bb-scripts --select penv

Now that I reflect back on writing all of that, I think that perhaps the --list (and :bbin/default key even) might be a bit much. Users presumably started at a script repository's readme and would know what is available. With this in mind, maybe the simplest thing is just to error when a script is not selected (and there are multiple) and leave it at that.

logseq-cldwalker commented 1 year ago

I have a repo containing multiple babashka scripts, each with its own main.

I also have the same setup at https://github.com/logseq/bb-tasks though I'm wanting to install all my scripts at once. Since :bbin/bin is a map, I thought I could do something in bb.edn like:

:bbin/bin
{logseq-import {:main-opts ["-m" "logseq.bb-tasks.bin.logseq-import/-main"]
 logseq-export {:main-opts ["-m" "logseq.bb-tasks.bin.logseq-export/-main"]}

When it only picked the first one I thought it was a bug until I found this issue. If this is unrelated enough, I could open a separate issue. Thanks for the great tool!