diff --git a/git-cliff/src/lib.rs b/git-cliff/src/lib.rs index f7e458c59e..415b94cf01 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 config_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 + config_path ); - fs::write(DEFAULT_CONFIG, contents)?; + fs::write(config_path, contents)?; return Ok(()); } diff --git a/website/docs/usage/initializing.md b/website/docs/usage/initializing.md index 8efaad6899..e3195d3efa 100644 --- a/website/docs/usage/initializing.md +++ b/website/docs/usage/initializing.md @@ -9,6 +9,9 @@ The default [configuration file](/docs/configuration) (`cliff.toml`) can be gene ```bash # create cliff.toml git cliff --init + +# create a config file with a custom name +git-cliff --init --config custom.toml ``` There are also other templates under the [examples](https://github.com/orhun/git-cliff/blob/main/examples) directory. See the [template examples](/docs/templating/examples) for previewing the templates.