mirror of
https://github.com/TECHNOFAB11/bump2version.git
synced 2025-12-12 16:10:07 +01:00
fix: make part and file section in config optional
This commit is contained in:
parent
98ab491bd0
commit
4700482139
6 changed files with 11 additions and 8 deletions
|
|
@ -1,4 +1,4 @@
|
|||
current_version = "1.0.0"
|
||||
current_version = "1.0.1"
|
||||
commit = true
|
||||
tag = true
|
||||
message = "chore: bump {current_version} → {new_version}"
|
||||
|
|
|
|||
2
Cargo.lock
generated
2
Cargo.lock
generated
|
|
@ -61,7 +61,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "bump2version"
|
||||
version = "1.0.0"
|
||||
version = "1.0.1"
|
||||
dependencies = [
|
||||
"clap",
|
||||
"regex",
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "bump2version"
|
||||
version = "1.0.0"
|
||||
version = "1.0.1"
|
||||
edition = "2021"
|
||||
description = "⬆️ Easily manage version numbers in your projects."
|
||||
license = "MIT"
|
||||
|
|
|
|||
|
|
@ -13,8 +13,8 @@ pub(crate) struct Config {
|
|||
#[serde(default = "default_serialize")]
|
||||
pub(crate) serialize: String,
|
||||
|
||||
pub(crate) part: HashMap<String, Part>,
|
||||
pub(crate) file: HashMap<String, File>,
|
||||
pub(crate) part: Option<HashMap<String, Part>>,
|
||||
pub(crate) file: Option<HashMap<String, File>>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@ 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};
|
||||
|
|
@ -57,7 +59,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
.or(config.message)
|
||||
.unwrap_or("Bump version: {current_version} → {new_version}".to_string());
|
||||
|
||||
let files: Vec<&String> = config.file.keys().collect();
|
||||
let config_files = config.file.unwrap_or_default();
|
||||
let files: Vec<&String> = config_files.keys().collect();
|
||||
|
||||
// Check if Git working directory is clean
|
||||
if fs::metadata(".git").is_ok() {
|
||||
|
|
@ -84,7 +87,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
info!(amount = &files.len(), "Updating version in files");
|
||||
for path in files.clone() {
|
||||
let content = fs::read_to_string(path)?;
|
||||
let format = &config.file.get(path).unwrap().format;
|
||||
let format = &config_files.get(path).unwrap().format.clone();
|
||||
|
||||
let old_line = format.replace("{version}", ¤t_version);
|
||||
if !content.contains(&old_line) {
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ pub fn attempt_version_bump(args: Cli, config: Config) -> Option<String> {
|
|||
|
||||
for label in order.clone() {
|
||||
if let Some(part) = parsed.get_mut(label) {
|
||||
let part_cfg = part_configs.get(label);
|
||||
let part_cfg = part_configs.as_ref().and_then(|c| c.get(label));
|
||||
|
||||
if label == args.bump {
|
||||
match part_cfg
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue