Skip to content

Commit

Permalink
feat(config): add --init flag for creating the default config
Browse files Browse the repository at this point in the history
  • Loading branch information
orhun committed Aug 18, 2021
1 parent e5148e3 commit 183481b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 .`
Expand Down
3 changes: 3 additions & 0 deletions git-cliff/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ pub struct Opt {
allow_hyphen_values = true
)]
pub body: Option<String>,
/// 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,
Expand Down
8 changes: 8 additions & 0 deletions git-cliff/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
Expand Down

0 comments on commit 183481b

Please sign in to comment.