marcosnils / bin

Effortless binary manager
MIT License
640 stars 44 forks source link

command line option select #199

Open perplexedpigmy opened 1 month ago

perplexedpigmy commented 1 month ago

I found this bin utility useful and wanted to use it inside Dockefiles, which meant that at no point can we drop to a TTY, the simplest way to circumvent user feedback is to allow explicit selection. This PR suggests a minimal addition required to allow for explicit command line selection as well as a use case in the .devcontainer added to the project. It is already being used, the PR is just in case the project maintainer find the added behavior desirable.

Note: The README was not updated, as it currently doesn't explain in detail all the options and switches, this oversight can be remedied on request.

There are 2 minor updates:

  1. Introduction of BIN_EXE_DIR

Previously, the installation/download directory is derived from the PATH, when it's unable to do so, the bin utility demands user feedback. In some cases it's useful to be able to shortcut this process and directly provide it with the installation directory using the BIN_EXE_DIR

# install `navi` in a specific designated directory, update the bin configuration in the same directory
$ BIN_EXE_DIR=~/.local/bin bin install github.com/denisidoro/navi

Note: while the original bin utility allows for installation at a specific directory

# Explicit install @ ~/.local/bin
$ bin install github.com/denisidoro/navi  ~/.local/bin

The behavior differs. Without BIN_EXE_DIR when the initial config is missing, the user will be requested to provide the installation directory.

  1. Introduction of a command line file option selection (--select | -s )

In some cases the release may contain multiple files and user intervention is required to choose which one to install. The select option was introduced to allow the user to specify the exact file to install even when it's inside an archive (tar, xz, etc).

SYNTAX:
   bin install <URL> [ --select | -s  FileName[:ContainedFile] ]
# Install the file yq_linux_amd64
$ bin install github.com/mikefarah/yq --select yq_linux_amd64

# Install broot selecting for the file x86_64-linux that is in the only tar ball existing in the release
$ bin install github.com/Canop/broot --select :x86_64-linux/broot

# Install the file age/age (age inside a directory with the same name) from the only tarball in the release
$ bin install github.com/filosottile/age -s :age/age

# Install btm file from the tarball bottom_x86_64-unknown-linux-gnu.tar.gz (select both the tarball and a file)
$ bin install github.com/ClementTsang/bottom -s bottom_x86_64-unknown-linux-gnu.tar.gz:btm

While it is possible to select partially, IMHO it defeats my original purpose of avoiding any TTY interaction, but why not?!

# No Selection output
$ bin install github.com/ClementTsang/bottom
   • Getting latest release for ClementTsang/bottom

Multiple matches found, please select one:

 [1] bottom_x86_64-unknown-linux-gnu.tar.gz
 [2] bottom_x86_64-unknown-linux-gnu2-17.tar.gz
 [3] bottom_x86_64-unknown-linux-musl.tar.gz
 Select an option: 1
   • Starting download of https://api.github.com/repos/ClementTsang/bottom/releases/assets/123278270
1.85 MiB / 1.85 MiB [------------------------------------------------------------------------------------------------------------------------------------------------------------------------------] 100.00% 19.58 MiB p/s 0s

Multiple matches found, please select one:

 [1] btm
 [2] completion/_btm
 [3] completion/_btm.ps1
 [4] completion/btm.bash
 [5] completion/btm.elv
 [6] completion/btm.fish
 Select an option:
# Partial selection output
$ bin install github.com/ClementTsang/bottom  -s bottom_x86_64-unknown-linux-gnu.tar.gz
   • Getting latest release for ClementTsang/bottom
   • Starting download of https://api.github.com/repos/ClementTsang/bottom/releases/assets/123278270
1.85 MiB / 1.85 MiB [------------------------------------------------------------------------------------------------------------------------------------------------------------------------------] 100.00% 22.72 MiB p/s 0s

Multiple matches found, please select one:

 [1] btm
 [2] completion/_btm
 [3] completion/_btm.ps1
 [4] completion/btm.bash
 [5] completion/btm.elv
 [6] completion/btm.fish
 Select an option:
# Full selection output
$ bin install github.com/ClementTsang/bottom  -s bottom_x86_64-unknown-linux-gnu.tar.gz:btm
   • Getting latest release for ClementTsang/bottom
   • Starting download of https://api.github.com/repos/ClementTsang/bottom/releases/assets/123278270
1.85 MiB / 1.85 MiB [------------------------------------------------------------------------------------------------------------------------------------------------------------------------------] 100.00% 20.29 MiB p/s 0s
   • Copying for btm@0.9.6 into /home/vscode/.local/bin/btm
   • Done installing btm 0.9.6
ristomatti commented 3 weeks ago

Does this also store the selection criteria in config.json, so that bin update --all would work without manually selecting the package? If it does, that would be a huge improvement!

I'm currently running a system with an old version of GLIBC which occasionally prevents me from using the gnu binaries (which I prefer over musl if they work). When I first install a package the first time, I first pick gnu, then go with musl if it doesn't work. Later when I run bin update --all, I've already forgotten which variant was the one that works and have to do this again.

perplexedpigmy commented 1 week ago

@ristomatti Yes, the config.json is storing all required information for bin update --all to work automatically. btw, tagging me would make sure that a notification is sent to my email so I am aware of your query.