From 5d2e86e6f16be753b0b266a01f261bd057b06794 Mon Sep 17 00:00:00 2001 From: TECHNOFAB Date: Fri, 27 Dec 2024 16:04:50 +0100 Subject: [PATCH 1/5] chore: remove lib related stuff --- Cargo.toml | 4 ---- src/cli.rs | 0 src/lib.rs | 6 ------ src/main.rs | 2 -- src/utils.rs | 2 +- 5 files changed, 1 insertion(+), 13 deletions(-) mode change 100755 => 100644 src/cli.rs delete mode 100644 src/lib.rs diff --git a/Cargo.toml b/Cargo.toml index 194717f..1b5123a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,10 +13,6 @@ authors = [ "TECHNOFAB ", ] -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html -[lib] -crate-type = ["cdylib"] - [dependencies] clap = { version = "4.5.1", features = ["derive"] } regex = "1.10.3" diff --git a/src/cli.rs b/src/cli.rs old mode 100755 new mode 100644 diff --git a/src/lib.rs b/src/lib.rs deleted file mode 100644 index 022eb5e..0000000 --- a/src/lib.rs +++ /dev/null @@ -1,6 +0,0 @@ -#![cfg_attr(docsrs, feature(doc_auto_cfg))] -#![doc = include_str!("../README.md")] - -pub(crate) mod cli; -pub(crate) mod config; -pub(crate) mod utils; diff --git a/src/main.rs b/src/main.rs index 244cb77..5b54806 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,8 +2,6 @@ use self::cli::Cli; use crate::config::Config; use crate::utils::attempt_version_bump; use clap::Parser; -use config::File; -use std::collections::HashMap; use std::fs; use std::process::{exit, Command}; use tracing::{error, info, level_filters::LevelFilter, warn}; diff --git a/src/utils.rs b/src/utils.rs index bf5ff9e..ddd68fb 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -6,7 +6,7 @@ use std::collections::HashMap; use std::ops::Index; use tracing::{error, trace}; -pub fn attempt_version_bump(args: Cli, config: Config) -> Option { +pub(crate) fn attempt_version_bump(args: Cli, config: Config) -> Option { let parse_regex = config.parse; let regex = match Regex::new(&parse_regex) { Ok(r) => r, From 053b7cb94b9d2cb099c47f439c09a4759a69550f Mon Sep 17 00:00:00 2001 From: TECHNOFAB Date: Fri, 27 Dec 2024 16:05:20 +0100 Subject: [PATCH 2/5] =?UTF-8?q?chore:=20bump=201.0.1=20=E2=86=92=201.0.2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .bumpversion.toml | 2 +- Cargo.lock | 2 +- Cargo.toml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.bumpversion.toml b/.bumpversion.toml index faa0fd5..b9a9e7f 100644 --- a/.bumpversion.toml +++ b/.bumpversion.toml @@ -1,4 +1,4 @@ -current_version = "1.0.1" +current_version = "1.0.2" commit = true tag = true message = "chore: bump {current_version} → {new_version}" diff --git a/Cargo.lock b/Cargo.lock index 8810e23..59f7f97 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -61,7 +61,7 @@ dependencies = [ [[package]] name = "bump2version" -version = "1.0.1" +version = "1.0.2" dependencies = [ "clap", "regex", diff --git a/Cargo.toml b/Cargo.toml index 1b5123a..dcff0e0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bump2version" -version = "1.0.1" +version = "1.0.2" edition = "2021" description = "⬆️ Easily manage version numbers in your projects." license = "MIT" From a576cb735f7324f5206e1a353d915a84bd6d8690 Mon Sep 17 00:00:00 2001 From: TECHNOFAB Date: Sun, 29 Dec 2024 17:54:38 +0100 Subject: [PATCH 3/5] feat: allow replacing multiple lines per file --- .bumpversion.toml | 8 ++++---- Cargo.lock | 2 +- Cargo.toml | 2 +- src/config.rs | 4 ++-- src/main.rs | 26 ++++++++++++++------------ 5 files changed, 22 insertions(+), 20 deletions(-) diff --git a/.bumpversion.toml b/.bumpversion.toml index b9a9e7f..3893965 100644 --- a/.bumpversion.toml +++ b/.bumpversion.toml @@ -1,4 +1,4 @@ -current_version = "1.0.2" +current_version = "1.1.0" commit = true tag = true message = "chore: bump {current_version} → {new_version}" @@ -11,8 +11,8 @@ type = "string" values = ["alpha", "beta", "stable"] [file."Cargo.toml"] -format = 'version = "{version}"' +formats = ['version = "{version}"'] [file."Cargo.lock"] -format = """name = "bump2version" -version = "{version}"""" +formats = ["""name = "bump2version" +version = "{version}""""] diff --git a/Cargo.lock b/Cargo.lock index 59f7f97..af2eacd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -61,7 +61,7 @@ dependencies = [ [[package]] name = "bump2version" -version = "1.0.2" +version = "1.1.0" dependencies = [ "clap", "regex", diff --git a/Cargo.toml b/Cargo.toml index dcff0e0..ea867a6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bump2version" -version = "1.0.2" +version = "1.1.0" edition = "2021" description = "⬆️ Easily manage version numbers in your projects." license = "MIT" diff --git a/src/config.rs b/src/config.rs index 1384979..125da3f 100644 --- a/src/config.rs +++ b/src/config.rs @@ -35,8 +35,8 @@ pub(crate) struct Part { #[derive(Debug, Clone, Deserialize)] pub(crate) struct File { - /// Format to replace, eg. `current_version = "{version}"` - pub(crate) format: String, + /// Formats to replace, eg. `current_version = "{version}"` + pub(crate) formats: Vec, } fn default_parse() -> String { diff --git a/src/main.rs b/src/main.rs index 5b54806..04d00fd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -84,22 +84,24 @@ fn main() -> Result<(), Box> { // Update version in specified files info!(amount = &files.len(), "Updating version in files"); for path in files.clone() { - let content = fs::read_to_string(path)?; - let format = &config_files.get(path).unwrap().format.clone(); + let mut content = fs::read_to_string(path)?; + let formats = &config_files.get(path).unwrap().formats.clone(); - let old_line = format.replace("{version}", ¤t_version); - if !content.contains(&old_line) { - warn!( - current_version, - path, "Did not find current version in file" - ); + for format in formats { + let old_line = format.replace("{version}", ¤t_version); + if !content.contains(&old_line) { + warn!( + current_version, + path, "Did not find current version in file" + ); + } + + let new_line = format.replace("{version}", &new_version); + content = content.replace(&old_line, &new_line); } - let new_line = format.replace("{version}", &new_version); - let updated_content = content.replace(&old_line, &new_line); - if !dry_run { - fs::write(path, updated_content)?; + fs::write(path, content)?; } } From 2136a99b31a6fb02dd414dc2acde13ad1bb59130 Mon Sep 17 00:00:00 2001 From: technofab Date: Wed, 9 Jul 2025 17:11:05 +0200 Subject: [PATCH 4/5] feat: allow specifying current version via cli --- src/cli.rs | 4 ++++ src/config.rs | 2 +- src/main.rs | 21 ++++++++++++++++----- src/utils.rs | 7 +++++-- 4 files changed, 26 insertions(+), 8 deletions(-) diff --git a/src/cli.rs b/src/cli.rs index cf8a99c..f07903f 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -24,6 +24,10 @@ pub(crate) struct Cli { #[arg(short = 'n', long = "dry-run", default_value_t = false)] pub(crate) dry_run: bool, + /// Current version + #[arg(long = "current-version", value_name = "VERSION")] + pub(crate) current_version: Option, + /// New version that should be in the files. #[arg(long = "new-version", value_name = "VERSION")] pub(crate) new_version: Option, diff --git a/src/config.rs b/src/config.rs index 125da3f..a2e0e1d 100644 --- a/src/config.rs +++ b/src/config.rs @@ -4,7 +4,7 @@ use serde_derive::Deserialize; #[derive(Debug, Clone, Deserialize)] pub(crate) struct Config { - pub(crate) current_version: String, + pub(crate) current_version: Option, pub(crate) message: Option, pub(crate) commit: bool, pub(crate) tag: bool, diff --git a/src/main.rs b/src/main.rs index 04d00fd..45903fd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -38,12 +38,23 @@ fn main() -> Result<(), Box> { } }; - let current_version = config.current_version.clone(); - - let attempted_new_version = args - .new_version + let current_version = args + .current_version .clone() - .or(attempt_version_bump(args.clone(), config.clone())); + .or(config.current_version.clone()); + + if current_version.is_none() { + error!("No current version could be determined, either set in config or pass as arg"); + exit(1); + } + + let current_version = current_version.unwrap(); + + let attempted_new_version = args.new_version.clone().or(attempt_version_bump( + args.clone(), + config.clone(), + current_version.clone(), + )); if attempted_new_version.is_some() { let new_version = attempted_new_version.clone().unwrap(); diff --git a/src/utils.rs b/src/utils.rs index ddd68fb..15d0606 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -6,7 +6,11 @@ use std::collections::HashMap; use std::ops::Index; use tracing::{error, trace}; -pub(crate) fn attempt_version_bump(args: Cli, config: Config) -> Option { +pub(crate) fn attempt_version_bump( + args: Cli, + config: Config, + current_version: String, +) -> Option { let parse_regex = config.parse; let regex = match Regex::new(&parse_regex) { Ok(r) => r, @@ -16,7 +20,6 @@ pub(crate) fn attempt_version_bump(args: Cli, config: Config) -> Option } }; - let current_version = config.current_version; let mut parsed: HashMap = HashMap::new(); if let Some(captures) = regex.captures(¤t_version) { From f6a50bbda09afc16ee9780c3612f4602f1927839 Mon Sep 17 00:00:00 2001 From: technofab Date: Wed, 9 Jul 2025 17:11:22 +0200 Subject: [PATCH 5/5] =?UTF-8?q?chore:=20bump=201.1.0=20=E2=86=92=201.1.1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .bumpversion.toml | 2 +- Cargo.lock | 2 +- Cargo.toml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.bumpversion.toml b/.bumpversion.toml index 3893965..0971522 100644 --- a/.bumpversion.toml +++ b/.bumpversion.toml @@ -1,4 +1,4 @@ -current_version = "1.1.0" +current_version = "1.1.1" commit = true tag = true message = "chore: bump {current_version} → {new_version}" diff --git a/Cargo.lock b/Cargo.lock index af2eacd..63177c3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -61,7 +61,7 @@ dependencies = [ [[package]] name = "bump2version" -version = "1.1.0" +version = "1.1.1" dependencies = [ "clap", "regex", diff --git a/Cargo.toml b/Cargo.toml index ea867a6..5a74359 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bump2version" -version = "1.1.0" +version = "1.1.1" edition = "2021" description = "⬆️ Easily manage version numbers in your projects." license = "MIT"