From 9453b4576041bb7f2d5c3db1505e94ebc742f4cd Mon Sep 17 00:00:00 2001 From: xsadia Date: Wed, 25 Dec 2024 20:43:20 -0300 Subject: [PATCH] feat(cli): add synergy between init and config flags --- git-cliff/src/lib.rs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/git-cliff/src/lib.rs b/git-cliff/src/lib.rs index f7e458c59e..c76b97ed3b 100644 --- a/git-cliff/src/lib.rs +++ b/git-cliff/src/lib.rs @@ -47,7 +47,10 @@ use std::fs::{ File, }; use std::io; -use std::path::Path; +use std::path::{ + Path, + PathBuf, +}; use std::time::{ SystemTime, UNIX_EPOCH, @@ -376,12 +379,19 @@ pub fn run(mut args: Opt) -> Result<()> { Some(ref name) => BuiltinConfig::get_config(name.to_string())?, None => EmbeddedConfig::get_config()?, }; + + let output_path = if args.config == PathBuf::from(DEFAULT_CONFIG) { + PathBuf::from(DEFAULT_CONFIG) + } else { + args.config.clone() + }; + info!( "Saving the configuration file{} to {:?}", init_config.map(|v| format!(" ({v})")).unwrap_or_default(), - DEFAULT_CONFIG + output_path ); - fs::write(DEFAULT_CONFIG, contents)?; + fs::write(output_path, contents)?; return Ok(()); }