Update-informer v0.5.0


update-informer

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 🙏

Similar posts

Dotenv-linter v3.1.0

⚡️ Overview of the key changes included in this release

GitHub Actions to guard your workflow

Automated code review with GitHub Actions 🐶

Dotenv-linter v3.0.0

⚡️Обзор ключевых изменений вошедших в новый релиз 🎉

Dotenv-linter: линтер .env файлов

⚡️Молниеносный инструмент для проверки .env файлов 🦀

Автоматическая проверка кода на Go

Обзор инструмента для автоматической проверки кода на Go.

Docker for Mac и Kubernetes

Небольшой эксперимент с Docker for Mac и Kubernetes.

Автоматическая проверка кода с помощью Vexor

Пошаговая инструкция, что для этого нужно сделать.

Управление зависимостями через Homebrew

Управление внешними зависимостями проекта c помощью Homebrew Bundle.

Класс Set и уникальные коллекции объектов

Рассмотрим решение одной задачи с использованием класса Set и DDD.

Настройка Passenger для работы с Action Cable

Решаем проблему работы WebSocket-сервера через Phusion Passenger.