Update-informer

Update informer for CLI applications written in Rust 🦀
It checks for a new version on Crates.io, GitHub and PyPI 🚀
Benefits
- Support of Crates.io, GitHub and PyPI.
- Ability to implement your own registry to check updates.
- Configurable check frequency and request timeout.
- Minimum dependencies - only directories, ureq, semver and serde.
Idea
The idea is actually not new. This feature has long been present in the GitHub CLI application and npm. There is also a popular JavaScript library.
Usage
Add update-informer to Cargo.toml:
[]
= "0.5.0"
By default, update-informer can only check on Crates.io.
To enable support for other registries, use features:
[]
= { = "0.5.0", = false, = ["github"] }
Available features:
| Name | Default? |
|---|---|
| cargo | Yes |
| github | No |
| pypi | No |
Crates.io
To check for a new version on Crates.io, use the UpdateInformer::check_version function.
This function takes the project name and current version as well as check interval:
use ;
let informer = new;
if let Some = informer.check_version.ok.flatten
Also, you can take the name and version of the project from Cargo using environment variables:
use ;
let name = env!;
let version = env!;
new.check_version;
Interval
Note that the first check will start only after the interval has expired. By default, the interval is 24 hours, but you can change it:
use Duration;
use ;
const EVERY_HOUR: Duration = from_secs;
let informer = new.interval;
informer.check_version; // The check will start only after an hour
Cache file
By default, update-informer creates a file in the cache directory to avoid spam requests to the registry API.
In order not to cache requests, use a zero interval:
use Duration;
use ;
let informer = new.interval;
informer.check_version;
Request timeout
You can also change the request timeout. By default, it is 5 seconds:
use Duration;
use ;
const THIRTY_SECONDS: Duration = from_secs;
let informer = new.timeout;
informer.check_version;
GitHub
To check for a new version on GitHub (note that the project name must contain the owner):
use ;
let informer = new;
informer.check_version;
PyPi
To check for a new version on PyPI:
use ;
let informer = new;
informer.check_version;
Implementing your own registry
You can implement your own registry to check updates. For example:
use Duration;
use ;
;
let informer = new;
informer.check_version;
Example
use *;
use ;
The result will look like:
Tests
In order not to check for updates in tests, you can use the FakeUpdateInformer::check_version function, which returns the desired version.
Example of usage in unit tests:
use ;
let name = "crate_name";
let version = "0.1.0";
let informer = new;
let informer = fake;
if let Some = informer.check_version.ok.flatten
Integration tests
To use the FakeUpdateInformer::check_version function in integration tests, you must first add the feature flag to Cargo.toml:
[]
= []
Then use this feature flag in your code and integration tests:
use ;
let name = "crate_name";
let version = "0.1.0";
let informer = new;
let informer = fake;
informer.check_version;
Users
MSRV
Minimum Supported Rust Version: 1.56.1
Sponsors
update-informer is created & supported by Evrone