Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cli): add synergy between init and config flags #992

Merged
merged 4 commits into from
Jan 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading