a extremely customizable Rust library for CLI apps by Evrone

[ad_1]

update-informer is a library created primarily for CLI tools that are written in Rust — such as dotenv-linter, datanymizer. It checks for new versions that have been released and sends notifications when an update is found. update-informer was developed by an open-source enthusiast Mikhail Grachev.

CLI stands for Command Line Interface — a command-line program that reads the commands you enter and performs the requested action. In general, any program that can be used through terminal commands falls into this category.

 

How does it work?

update-informer allows you to automatically check for new versions on resources like Crates.io and GitHub. Crates.io is the Rust community’s crate registry, the main resource where all projects, libraries, etc. are stored.

When you add the update-informer library in your CLI application, which runs in the console, it periodically (for example, once a day) checks to see if a new version has been released. If one is out, then update-informer sends a message to the console like, “A new release is available, update with this link.”

There are a number of projects with similar tools. For example, GitHub CLI can bring GitHub to your terminal. Its functionality comes out of the box, and you can work with issues, pull requests, checks, releases, and more. There is also a library like this in Javascript, which is very popular.

Rust had a similar library, but it hadn’t been maintained for quite a long time, it didn’t have GitHub support, and we weren’t quite satisfied with how it worked. It could not be customized or changed. So we developed a more universal solution for Rust community that can be customized in every possible way.

update-informer generates a notification in the code during program start (in the logs). One of the key features of this tool that sets it apart from others is GitHub support, in addition to Crates.io. It also offers the ability to configure the frequency of checks (you can specify any length of time, even checking every single second) and has the minimum number of dependencies — only ureq, semver and serde. This is very important, since third-party solutions very often bring a lot of dependencies, resulting in code base increases, compilation time increases, etc.

The result looks like this:

update-informer

Usage

Add update-informer to Cargo.toml:

[dependencies]
update-informer = "0.2.0"

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 update_informer::{registry::Crates, Check, UpdateInformer};

let informer = UpdateInformer::new(Crates, "repo", "0.1.0", Duration::from_secs(60 * 60 * 24));
if let Ok(Some(version)) = informer.check_version() {
    println!("New version is available: {}", version);
}

Also, you can take the name and version of the project from Cargo using environment variables:

use update_informer::{registry::Crates, Check, UpdateInformer};

let name = env!("CARGO_PKG_NAME");
let version = env!("CARGO_PKG_VERSION");
UpdateInformer::new(Crates, name, version, Duration::from_secs(60 * 60 * 24)).check_version();

Note that the first check will start only after the interval has expired:

use update_informer::{registry::Crates, Check, UpdateInformer};

const EVERY_HOUR: Duration = Duration::from_secs(60 * 60);

let informer = UpdateInformer::new(Crates, "repo", "0.1.0", EVERY_HOUR);
informer.check_version(); // The check will start only after an hour

To check for a new version on GitHub (note that the project name must contain the owner):

use update_informer::{registry::GitHub, Check, UpdateInformer};

let informer = UpdateInformer::new(GitHub, "owner/repo", "0.1.0", Duration::from_secs(60 * 60 * 24));
informer.check_version();

Plans for the future

At the moment, the v0.2.0 version of the update-informer has been released. If there is interest from the community or requests for improvements, then of course we will work on improving this tool and expanding the functionality. In the future, we plan to support all popular hosts, such as GitLab and Bitbucket, as well as add support for various HTTP clients to reduce dependencies. Check the project’s GitHub and send us pull requests!

Our work on open-source projects — and the fact that every month we choose several OSS projects to sponsor — shows our initiative and understanding of what developers love and need. Reach out to us via the form below if you need to update your project to the latest versions of the technology stack!



[ad_2]

1 Comment

Leave a Reply

Your email address will not be published.

You might like

© 2022 All in Cyrpto - WordPress Theme by WPEnjoy