mirror of
https://github.com/TECHNOFAB11/bump2version.git
synced 2025-12-12 16:10:07 +01:00
feat: allow replacing multiple lines per file
This commit is contained in:
parent
053b7cb94b
commit
a576cb735f
5 changed files with 22 additions and 20 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
current_version = "1.0.2"
|
current_version = "1.1.0"
|
||||||
commit = true
|
commit = true
|
||||||
tag = true
|
tag = true
|
||||||
message = "chore: bump {current_version} → {new_version}"
|
message = "chore: bump {current_version} → {new_version}"
|
||||||
|
|
@ -11,8 +11,8 @@ type = "string"
|
||||||
values = ["alpha", "beta", "stable"]
|
values = ["alpha", "beta", "stable"]
|
||||||
|
|
||||||
[file."Cargo.toml"]
|
[file."Cargo.toml"]
|
||||||
format = 'version = "{version}"'
|
formats = ['version = "{version}"']
|
||||||
|
|
||||||
[file."Cargo.lock"]
|
[file."Cargo.lock"]
|
||||||
format = """name = "bump2version"
|
formats = ["""name = "bump2version"
|
||||||
version = "{version}""""
|
version = "{version}""""]
|
||||||
|
|
|
||||||
2
Cargo.lock
generated
2
Cargo.lock
generated
|
|
@ -61,7 +61,7 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bump2version"
|
name = "bump2version"
|
||||||
version = "1.0.2"
|
version = "1.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"clap",
|
"clap",
|
||||||
"regex",
|
"regex",
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "bump2version"
|
name = "bump2version"
|
||||||
version = "1.0.2"
|
version = "1.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
description = "⬆️ Easily manage version numbers in your projects."
|
description = "⬆️ Easily manage version numbers in your projects."
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
|
|
|
||||||
|
|
@ -35,8 +35,8 @@ pub(crate) struct Part {
|
||||||
|
|
||||||
#[derive(Debug, Clone, Deserialize)]
|
#[derive(Debug, Clone, Deserialize)]
|
||||||
pub(crate) struct File {
|
pub(crate) struct File {
|
||||||
/// Format to replace, eg. `current_version = "{version}"`
|
/// Formats to replace, eg. `current_version = "{version}"`
|
||||||
pub(crate) format: String,
|
pub(crate) formats: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn default_parse() -> String {
|
fn default_parse() -> String {
|
||||||
|
|
|
||||||
26
src/main.rs
26
src/main.rs
|
|
@ -84,22 +84,24 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
// Update version in specified files
|
// Update version in specified files
|
||||||
info!(amount = &files.len(), "Updating version in files");
|
info!(amount = &files.len(), "Updating version in files");
|
||||||
for path in files.clone() {
|
for path in files.clone() {
|
||||||
let content = fs::read_to_string(path)?;
|
let mut content = fs::read_to_string(path)?;
|
||||||
let format = &config_files.get(path).unwrap().format.clone();
|
let formats = &config_files.get(path).unwrap().formats.clone();
|
||||||
|
|
||||||
let old_line = format.replace("{version}", ¤t_version);
|
for format in formats {
|
||||||
if !content.contains(&old_line) {
|
let old_line = format.replace("{version}", ¤t_version);
|
||||||
warn!(
|
if !content.contains(&old_line) {
|
||||||
current_version,
|
warn!(
|
||||||
path, "Did not find current version in file"
|
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 {
|
if !dry_run {
|
||||||
fs::write(path, updated_content)?;
|
fs::write(path, content)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue