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) {