cobra
cobra copied to clipboard
Supporting upgrades for CLIs developed with Cobra?
Hello maintainers and community!
I am developing a CLI using cobra for my team's internal use. I expect somewhere between 5 to 50 people to use it actively. The purpose of the CLI is simply to automate some of the common tasks many people in our team frequently execute. As such I expect to roll out new versions of this CLI for my team fairly frequently.
How are upgrades for CLIs developed with Cobra typically carried out?
I was hoping for an upgrade command similar to the az upgrade
command available in the Azure CLI (docs), but I don't see anything related to that in the docs.
Are there any ways other than relying on the package manager like brew to offer upgrades? Would love to hear more suggestions from the maintainers and the community.
Thank you!
Hi @ekamwctx. There is no special support for upgrading within Cobra. However you can implement an upgrade
command yourself and do whatever you need within it.
But I expect others to have already done something like this and I hope they can give some info here.
I remember having to do this to a CLI I worked on a few years ago and we were doing the update ourselves. By now there are more tools that can help with this; a quick search turned up https://team.goodeggs.com/self-updating-go-binaries-with-go-selfupdate-f59c5ce50c26
I just remember doing a simple version of that; just pulling down the new binary and validating it, then moving it into place. Windows required some slightly different handling since you couldn't be executing file A and also rename/swap it with another file.
I think a reasonable approach is that when you call your app, you actually want to be invoking a launcher that will check the version you want to be using and invoke it from a local cache. That way you can cache various versions locally and swap between them if you want and it can make it simple to understand when/where the binaries live. When you update the app you put a new binary in the cache and update some key so you use the newer version.
The Cobra project currently lacks enough contributors to adequately respond to all issues. This bot triages issues and PRs according to the following rules:
- After 60d of inactivity, lifecycle/stale is applied. - After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied and the issue is closed. You can:
- Make a comment to remove the stale label and show your support. The 60 days reset. - If an issue has lifecycle/rotten and is closed, comment and ask maintainers if they'd be interseted in reopening