feat: allow replacing multiple lines per file

This commit is contained in:
TECHNOFAB 2024-12-29 17:54:38 +01:00
parent 053b7cb94b
commit a576cb735f
No known key found for this signature in database
GPG key ID: D06FBA11BA6FF836
5 changed files with 22 additions and 20 deletions

View file

@ -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}""""]

2
Cargo.lock generated
View file

@ -61,7 +61,7 @@ dependencies = [
[[package]]
name = "bump2version"
version = "1.0.2"
version = "1.1.0"
dependencies = [
"clap",
"regex",

View file

@ -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"

View file

@ -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<String>,
}
fn default_parse() -> String {

View file

@ -84,9 +84,10 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
// 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();
for format in formats {
let old_line = format.replace("{version}", &current_version);
if !content.contains(&old_line) {
warn!(
@ -96,10 +97,11 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
}
let new_line = format.replace("{version}", &new_version);
let updated_content = content.replace(&old_line, &new_line);
content = content.replace(&old_line, &new_line);
}
if !dry_run {
fs::write(path, updated_content)?;
fs::write(path, content)?;
}
}