Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: bin update check mode #83

Closed
breml opened this issue Mar 22, 2021 · 6 comments · Fixed by #90
Closed

Feature Request: bin update check mode #83

breml opened this issue Mar 22, 2021 · 6 comments · Fixed by #90
Labels
enhancement New feature or request question Further information is requested

Comments

@breml
Copy link
Collaborator

breml commented Mar 22, 2021

I would like to have a check mode (or dry run mode) for the update command. The command should exit with non 0 exit code, if there are updated version found for any installed binary. If no updates are found, the exit code would be 0 and no output would be printed.

This command I would like to execute on a regular basis (e.g. cron or init of my shell).

Bonus: In order to prevent too frequent requests to e.g. the github API, bin could have an option in the config file, how long bin does cache the results from this check update command. This would allow to run the check update command on every init of my shell (these can happen quite frequently, whenever I open a new pane/window in tmux).

@marcosnils marcosnils added enhancement New feature or request question Further information is requested labels Mar 23, 2021
@marcosnils
Copy link
Owner

I like this. Let's think about how that API would look like.

@breml
Copy link
Collaborator Author

breml commented Mar 23, 2021

Let us take some inspiration from other tools:

deb: apt list --upgradable or apt-get -u upgrade --assume-no
rpm: yum check-update
apk: apk upgrade --simulate

Judging from the current API, I assume the check mode / dry run to be a special case for the existing update command, because the current list command does not do any network requests, but only considers the configuration file (and checks if the binaries are present). In the update command, it would be pretty straight forward to implement a check only code path.

If we open up the scope a little bit, the question is, if we want to have a dry run feature for other commands as well (e.g. for install just to see, which archive/binary would be selected without actually installing it or for ensure to see which binaries would be added or for prune to see, what would get pruned). If this is the case, then I would go for -n / --dry-run (similar to e.g. rsync).

If this is not the case, I would propose something like bin update --check

If the command should exit with a non zero exit code when updates are available could potentially be an additional flag (I have seen this with other tools, but from the top of my head I can not recall an example).

@sirlatrom
Copy link
Collaborator

Isn't the default interactive mode of bin update already a kind of dry run mode? I tested out what happens when you run bin update and have updates, but don't provide a stdin:

$ : | bin update
   • /home/<redacted>/bin/buf v0.39.0 -> v0.40.0 (https://github.com/bufbuild/buf/releases/tag/v0.40.0)

Do you want to continue? [Y/n]    ⨯ command failed            error=Invalid input
exit status 1
$ echo $?
1
$ bin update
   • /home/<redacted>/bin/buf v0.39.0 -> v0.40.0 (https://github.com/bufbuild/buf/releases/tag/v0.40.0)

Do you want to continue? [Y/n] Y
   • Getting v0.40.0 release for bufbuild/buf

Multiple matches found, please select one:

 [1] buf-Linux-x86_64
 [2] buf-Linux-x86_64.tar.gz
 [3] protoc-gen-buf-breaking-Linux-x86_64
 [4] protoc-gen-buf-check-breaking-Linux-x86_64
 [5] protoc-gen-buf-check-lint-Linux-x86_64
 [6] protoc-gen-buf-lint-Linux-x86_64
 Select an option: 1
   • Starting download of https://github.com/bufbuild/buf/releases/download/v0.40.0/buf-Linux-x86_64
16.40 MiB / 16.40 MiB [-----------------------------------------------------------------------------------------------------------------------------------------------------] 100.00% 19.54 MiB p/s 2s
   • Copying for buf@v0.40.0 into /home/<redacted>/bin/buf
   • Done updating /home/<redacted>/bin/buf to v0.40.0
$ : | bin update
   • All binaries are up to date
$ echo $?
0

@breml
Copy link
Collaborator Author

breml commented Mar 25, 2021

Sort of true and one might also redirect stdout to /dev/null e.g. if used in cron. But is this user friendly? Does this also work on Windows?
If there is a flag, the normal help text will tell the user how to use it and what to expect. I think your workaround with : | is not obvious for most users. Of course we could put this into the FAQ, but I would prefer it to have it explicit as flag and in the help.

@marcosnils
Copy link
Owner

Of course we could put this into the FAQ, but I would prefer it to have it explicit as flag and in the help.

Agree that having a flag for bin update would be convenient here.

I guess bin update --dry-run SGTM. @sirlatrom ?

@sirlatrom
Copy link
Collaborator

Of course we could put this into the FAQ, but I would prefer it to have it explicit as flag and in the help.

Agree that having a flag for bin update would be convenient here.

I guess bin update --dry-run SGTM. @sirlatrom ?

Yes, it will definitely be cleaner than my workarounds above.

marcosnils added a commit that referenced this issue Mar 27, 2021
sirlatrom pushed a commit that referenced this issue Apr 1, 2021
* Add dry-run mode to update command

Fixes #83

* Update cmd/update.go

Co-authored-by: Lucas Bremgartner <breml@users.noreply.github.com>

* Return status code 3 for dry-run updates

I'm using 3 because 2 is generally reserved for special meanings.
Ref: https://tldp.org/LDP/abs/html/exitcodes.html

Co-authored-by: Lucas Bremgartner <breml@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request question Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants