Skip to content

Commit

Permalink
feat(cli): support initializing config with a custom filename (#992)
Browse files Browse the repository at this point in the history
* feat(cli): add synergy between init and config flags

* docs: update examples.md to list custom config path with init flag

* chore: rename output_path to config_path

* docs(init): update init examples

---------

Co-authored-by: Orhun Parmaksız <[email protected]>
  • Loading branch information
xsadia and orhun authored Jan 18, 2025
1 parent f29e815 commit 76bf9cf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
16 changes: 13 additions & 3 deletions git-cliff/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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(());
}

Expand Down
3 changes: 3 additions & 0 deletions website/docs/usage/initializing.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 76bf9cf

Please sign in to comment.