Skip to content

Commit

Permalink
refactor(cli): make update-informer opt-out via feature flag (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
orhun committed Mar 28, 2022
1 parent efd40e0 commit cddb4d4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
9 changes: 8 additions & 1 deletion git-cliff/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
11 changes: 8 additions & 3 deletions git-cliff/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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} -> \
Expand All @@ -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.
Expand Down

0 comments on commit cddb4d4

Please sign in to comment.