1
1
mirror of https://github.com/orhun/git-cliff.git synced 2024-11-29 02:15:26 +03:00

refactor(cli): make update-informer opt-out via feature flag (#69)

This commit is contained in:
Orhun Parmaksız 2022-03-29 01:49:44 +03:00
parent efd40e02b3
commit cddb4d49fb
No known key found for this signature in database
GPG Key ID: B928720AEC532117
2 changed files with 16 additions and 4 deletions

View File

@ -16,12 +16,15 @@ edition = "2021"
name = "git-cliff-completions"
path = "src/bin/completions.rs"
[features]
# check for new versions
default = ["update-informer"]
[dependencies]
pretty_env_logger = "0.4.0"
log = "0.4.14"
dirs-next = "2.0.0"
clap_complete = "3.1.1"
update-informer = "0.5.0"
[dependencies.git-cliff-core]
version = "0.6.1" # managed by release.sh
@ -31,5 +34,9 @@ path = "../git-cliff-core"
version = "3.1.6"
features = ["derive", "env", "wrap_help"]
[dependencies.update-informer]
version = "0.5.0"
optional = true
[dev-dependencies]
pretty_assertions = "1.1.0"

View File

@ -29,14 +29,18 @@ use std::fs::{
File,
};
use std::io;
use update_informer::registry::Crates;
use update_informer::Check;
/// Checks for a new version on crates.io
#[cfg(feature = "update-informer")]
fn check_new_version() {
use update_informer::Check;
let pkg_name = env!("CARGO_PKG_NAME");
let pkg_version = env!("CARGO_PKG_VERSION");
let informer = update_informer::new(Crates, pkg_name, pkg_version);
let informer = update_informer::new(
update_informer::registry::Crates,
pkg_name,
pkg_version,
);
if let Some(new_version) = informer.check_version().ok().flatten() {
log::info!(
"A new version of {pkg_name} is available: v{pkg_version} -> \
@ -48,6 +52,7 @@ fn check_new_version() {
/// Runs `git-cliff`.
pub fn run(mut args: Opt) -> Result<()> {
// Check if there is a new version available.
#[cfg(feature = "update-informer")]
check_new_version();
// Create the configuration file if init flag is given.