fix: make part and file section in config optional

This commit is contained in:
TECHNOFAB 2024-12-27 14:31:50 +01:00
parent 98ab491bd0
commit 1a7c22bdbf
No known key found for this signature in database
GPG key ID: D06FBA11BA6FF836
6 changed files with 11 additions and 8 deletions

View file

@ -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)]

View file

@ -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}", &current_version);
if !content.contains(&old_line) {

View file

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