ducaale / xh

Friendly and fast tool for sending HTTP requests

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Show a message if a newer version is available

beardgans opened this issue · comments

👋 Thank you for this awesome project!

I found this feature in the GitHub CLI application and npm.

I think it'll be useful for users who install xh using the installation script or cargo.
And this will let them know that a new version is available and it's time to update.

Ready-made crates to implement that:

Thanks for the suggestion. Do you know of any other CLI tool that checks for updates in the background? I thought npm, github-cli and ngrok were unique cases in that they need to be up to date to keep up with their backing server. However, for tools installed via an installation script, perhaps a dedicated update-checker tool would be more ideal?

Do you know of any other CLI tool that checks for updates in the background? However, for tools installed via an installation script, perhaps a dedicated update-checker tool would be more ideal?

No, I don't know such CLI tools.

However, for tools installed via an installation script, perhaps a dedicated update-checker tool would be more ideal?

I'm not sure because I can't imagine how it could be 🤔

(EDIT: I wrote the below thinking this was about an updater, not just a notifier, so some of it doesn't apply.)

I definitely wouldn't want xh to check for updates on its own accord.

A builtin updater you call manually might be reasonable, but it wouldn't be straightforward.

  • We already have reqwest and serde-json, so we can roll our own solution without adding dependency bloat.
  • We wouldn't want it included in distro builds.
  • For installations done through cargo install we'd probably also want to leave it out. At most a notifier.
  • We'd have to take care with permissions, xh might be installed as root with the updater running as a user.
  • IIRC Windows doesn't let you replace an executable while it's running, and macOS may also have something like that.
  • The new version should not have different feature flags (i.e. native-tls).
  • I personally don't like it when this is built into tools. I prefer package managers so you don't have to update a million programs in a million different ways.

I'm not sure because I can't imagine how it could be 🤔

I was thinking of a tool that uses either update-informer or update-notifier to check for updates before spawning the command it received as the first argument

$ update-checker xh httpbin.org/json
---------------------------------------
New version of xh is available: v0.17.0
---------------------------------------
HTTP/1.1 200 OK
Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: *
Content-Length: 429
Content-Type: application/json
Date: Wed, 20 Apr 2022 22:49:04 GMT
Server: gunicorn/19.9.0

{
    "slideshow": {
        "author": "Yours Truly",
        "date": "date of publication",
        "slides": [
            {
                "title": "Wake up to WonderWidgets!",
                "type": "all"
            },
            {
                "items": [
                    "Why <em>WonderWidgets</em> are great",
                    "Who <em>buys</em> WonderWidgets"
                ],
                "title": "Overview",
                "type": "all"
            }
        ],
        "title": "Sample Slide Show"
    }
}

# avoid typing update-checker by aliasing it to the command that needs to be up to date
$ alias xh="update-checker xh"

Basic configuration needed by update-checker

# update-checker.toml

[xh]
version = "xh -V"
repo = "ducaale/xh"

[rg]
version = "rg -V"
repo = "BurntSushi/ripgrep"

You can then add an interactive setup to the update-checker that takes care of aliasing + updating the config file.

terraform does that when you use 'terraform version'

$ terraform version
Terraform v1.1.3
on linux_amd64

Your version of Terraform is out of date! The latest version
is 1.1.9. You can update by downloading from https://www.terraform.io/downloads.html

Personally, I am using cargo install-update from time to time and this works the best for me.