Update-informer is a crate for CLI applications that written in Rust — such as git-cliff and dotenv-linter. It checks for a new version on Crates.io and GitHub.
Also, it has the minimum number of dependencies — only directories, ureq, semver and serde.
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.
What is new in v0.5.0?
PyPi support
Now update-informer
can check for a new version on PyPi:
use update_informer::{registry, Check};
let informer = update_informer::new(registry::PyPI, "package_name", "0.1.0");
informer.check_version();
Configurable check frequency and request timeout
By default, the first check will start only after the interval has expired (= 24 hours), but you can change it:
use std::time::Duration;
use update_informer::{registry, Check};
const EVERY_HOUR: Duration = Duration::from_secs(60 * 60);
let informer = update_informer::new(registry::Crates, "crate_name", "0.1.0").interval(EVERY_HOUR);
informer.check_version(); // The check will start only after an hour
It is also possible to change the request timeout (default 5 seconds).
Disabling caching
To avoid spam requests to the registry API, update-informer
creates a file in the cache directory.
In order not to cache requests, use a zero interval:
use std::time::Duration;
use update_informer::{registry, Check};
let informer = update_informer::new(registry::Crates, "crate_name", "0.1.0").interval(Duration::ZERO);
informer.check_version();
Implementing your own registry
You can implement your own registry to check updates. For example:
use std::time::Duration;
use update_informer::{registry, Check, Package, Registry, Result};
struct YourOwnRegistry;
impl Registry for YourOwnRegistry {
const NAME: &'static str = "your_own_registry";
fn get_latest_version(pkg: &Package, _timeout: Duration) -> Result<Option<String>> {
let url = format!("https://your_own_registry.com/{}/latest-version", pkg);
let result = ureq::get(&url).call()?.into_string()?;
let version = result.trim().to_string();
Ok(Some(version))
}
}
let informer = update_informer::new(YourOwnRegistry, "package_name", "0.1.0");
informer.check_version();
Please support the project 🙏
- Star on GitHub ⭐️
- Become a sponsor on OpenCollective ❤️