From 8956c61a727b0408be202c9c7fc6c2f336166272 Mon Sep 17 00:00:00 2001 From: sgoudham Date: Thu, 5 Oct 2023 02:23:04 +0100 Subject: [PATCH] feat(cli): detect differences in major version --- src/lib.rs | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index cedea68..b89d490 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -17,6 +17,17 @@ pub enum TomlPath { const LATEST_ASSETS_VERSION: &str = env!("CARGO_PKG_VERSION"); const TOML_KEY: &str = "preprocessor.catppuccin.assets_version"; +fn get_major_version(version: &str) -> i32 { + version + .split_once('.') + .unwrap() + .0 + .parse::() + .unwrap_or_else(|_| { + panic!("Major version from '{version}' cannot be converted to an integer") + }) +} + impl Catppuccin { pub fn new() -> Self { Catppuccin @@ -43,11 +54,23 @@ impl Preprocessor for Catppuccin { r#"mdbook-catppuccin with version '{LATEST_ASSETS_VERSION}' is out of date with current asset version '{current_assets_version}'. Please upgrade by running 'cargo install --force mdbook-catppuccin' and then re-run 'mdbook-catppuccin install'"# ), - Cmp::Gt => error!( - r#"Out-Of-Date Asset Version '{current_assets_version}' Found: -Please update your version of 'mdbook-catppuccin' to '{LATEST_ASSETS_VERSION}'. + Cmp::Gt => { + error!( + r#"Out-Of-Date Asset Version '{current_assets_version}' Found: +Please update your version of 'mdbook-catppuccin' to '{LATEST_ASSETS_VERSION}'. Then run 'mdbook-catppuccin install' to install the lastest assets."# - ), + ); + + let current_major_version = get_major_version(current_assets_version); + let latest_major_version = get_major_version(LATEST_ASSETS_VERSION); + if latest_major_version > current_major_version { + error!( + r#"BREAKING CHANGES - Major Version Mismatch Detected. +Please see the version compatibility table to understand if you need to upgrade your 'index.hbs'. +https://github.com/catppuccin/mdBook?tab=readme-ov-file#version-compatibility"# + ) + } + } _ => {} } }