From 183481bac374707fbb7c579e2df83296e27f7251 Mon Sep 17 00:00:00 2001 From: orhun Date: Wed, 18 Aug 2021 03:51:04 +0300 Subject: [PATCH] feat(config): add `--init` flag for creating the default config --- README.md | 10 +++++++++- git-cliff/src/args.rs | 3 +++ git-cliff/src/lib.rs | 8 ++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b4ea6be6a4..fd01969d2e 100644 --- a/README.md +++ b/README.md @@ -107,6 +107,7 @@ git-cliff [FLAGS] [OPTIONS] [RANGE] ``` -v, --verbose Increases the logging verbosity +-i, --init Creates the default configuration file -l, --latest Processes the commits starting from the latest tag -u, --unreleased Processes the commits that do not belong to a tag -h, --help Prints help information @@ -134,7 +135,14 @@ git-cliff [FLAGS] [OPTIONS] [RANGE] ### Examples -To simply create a changelog at your projects git root directory with a [configuration file](#configuration-file) (e.g. `cliff.toml`) present: +The default [configuration file](#configuration-file) (`cliff.toml`) can be generated using the `--init` flag: + +```sh +# create cliff.toml +git cliff --init +``` + +Then simply create a changelog at your projects git root directory: ```sh # same as running `git-cliff --config cliff.toml --repository .` diff --git a/git-cliff/src/args.rs b/git-cliff/src/args.rs index dab545eb58..adf94ddf57 100644 --- a/git-cliff/src/args.rs +++ b/git-cliff/src/args.rs @@ -54,6 +54,9 @@ pub struct Opt { allow_hyphen_values = true )] pub body: Option, + /// Creates the default configuration file + #[structopt(short, long)] + pub init: bool, /// Processes the commits starting from the latest tag. #[structopt(short, long)] pub latest: bool, diff --git a/git-cliff/src/lib.rs b/git-cliff/src/lib.rs index e361f53a4a..961e29a067 100644 --- a/git-cliff/src/lib.rs +++ b/git-cliff/src/lib.rs @@ -17,6 +17,7 @@ use git_cliff_core::error::{ }; use git_cliff_core::release::Release; use git_cliff_core::repo::Repository; +use git_cliff_core::DEFAULT_CONFIG; use std::env; use std::fs::{ self, @@ -26,6 +27,13 @@ use std::io; /// Runs `git-cliff`. pub fn run(mut args: Opt) -> Result<()> { + // Create the configuration file if init flag is given. + if args.init { + info!("Saving the configuration file to {:?}", DEFAULT_CONFIG); + fs::write(DEFAULT_CONFIG, EmbeddedConfig::get_config()?)?; + return Ok(()); + } + // Set the working directory. if let Some(workdir) = args.workdir { args.config = workdir.join(args.config);