mirror of
https://github.com/orhun/git-cliff.git
synced 2024-09-11 06:55:38 +03:00
fix(config)!: nested environment config overrides (#157)
* chore: update env variable override format * tests: add a copule env override assertions * docs: add a doc for env overrides * docs: wording * docs: wording * fix: prefix * docs: format first
This commit is contained in:
parent
2d721259ca
commit
bb9a889f1b
@ -144,7 +144,9 @@ impl Config {
|
||||
config::Config::builder().add_source(config::File::from(path))
|
||||
};
|
||||
Ok(config_builder
|
||||
.add_source(config::Environment::with_prefix("CLIFF").separator("_"))
|
||||
.add_source(
|
||||
config::Environment::with_prefix("GIT_CLIFF").separator("__"),
|
||||
)
|
||||
.build()?
|
||||
.try_deserialize()?)
|
||||
}
|
||||
@ -164,9 +166,29 @@ mod test {
|
||||
.to_path_buf()
|
||||
.join("config")
|
||||
.join(crate::DEFAULT_CONFIG);
|
||||
env::set_var("CLIFF_CHANGELOG_FOOTER", "test");
|
||||
|
||||
const FOOTER_VALUE: &str = "test";
|
||||
const TAG_PATTERN_VALUE: &str = "*[0-9]*";
|
||||
const IGNORE_TAGS_VALUE: &str = "v[0-9]+.[0-9]+.[0-9]+-rc[0-9]+";
|
||||
|
||||
env::set_var("GIT_CLIFF__CHANGELOG__FOOTER", FOOTER_VALUE);
|
||||
env::set_var("GIT_CLIFF__GIT__TAG_PATTERN", TAG_PATTERN_VALUE);
|
||||
env::set_var("GIT_CLIFF__GIT__IGNORE_TAGS", IGNORE_TAGS_VALUE);
|
||||
|
||||
let config = Config::parse(&path)?;
|
||||
assert_eq!(Some(String::from("test")), config.changelog.footer);
|
||||
|
||||
assert_eq!(Some(String::from(FOOTER_VALUE)), config.changelog.footer);
|
||||
assert_eq!(
|
||||
Some(String::from(TAG_PATTERN_VALUE)),
|
||||
config.git.tag_pattern
|
||||
);
|
||||
assert_eq!(
|
||||
Some(String::from(IGNORE_TAGS_VALUE)),
|
||||
config
|
||||
.git
|
||||
.ignore_tags
|
||||
.map(|ignore_tags| ignore_tags.to_string())
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
@ -276,3 +276,26 @@ Examples:
|
||||
`limit_commits` is a **optional** positive integer number that limits the number of included commits in the generated changelog.
|
||||
|
||||
`limit_commits` is not part of the default configuration.
|
||||
|
||||
### Environment Configuration Overrides
|
||||
|
||||
It's possible to use environment variables to override configuration elements. If an environment variable matches a configuration element the variable's value will be used instead of the element's.
|
||||
|
||||
Format:
|
||||
```
|
||||
[PREFIX]__[CONFIG SECTION]__[FIELD NAME]
|
||||
```
|
||||
|
||||
Examples:
|
||||
|
||||
To override the `footer` element:
|
||||
|
||||
```bash
|
||||
export GIT_CLIFF__CHANGELOG__FOOTER="<!-- footer from env -->"
|
||||
```
|
||||
|
||||
To override the `ignore_tags` element:
|
||||
|
||||
```bash
|
||||
export GIT_CLIFF__GIT__IGNORE_TAGS="v[0-9]+.[0-9]+.[0-9]+-rc[0-9]+"
|
||||
```
|
Loading…
Reference in New Issue
Block a user