Skip to content

Commit

Permalink
feat(config): discover the configuration file when run in a sub direc…
Browse files Browse the repository at this point in the history
…tory
  • Loading branch information
orhun committed Dec 9, 2024
1 parent 216ac11 commit de90227
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion git-cliff/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ pub fn run(mut args: Opt) -> Result<()> {
}
}

// Parse the configuration file.
// Set path for the configuration file.
let mut path = args.config.clone();
if !path.exists() {
if let Some(config_path) = dirs::config_dir()
Expand All @@ -416,6 +416,7 @@ pub fn run(mut args: Opt) -> Result<()> {
}
}

// Parse the configuration file.
// Load the default configuration if necessary.
let mut config = if let Ok((config, name)) = builtin_config {
info!("Using built-in configuration file: {name}");
Expand All @@ -424,6 +425,20 @@ pub fn run(mut args: Opt) -> Result<()> {
Config::parse(&path)?
} else if let Some(contents) = Config::read_from_manifest()? {
Config::parse_from_str(&contents)?
} else if let Some(discovered_path) =
env::current_dir()?.ancestors().find_map(|dir| {
let path = dir.join(DEFAULT_CONFIG);
if path.is_file() {
Some(path)
} else {
None
}
}) {
info!(
"Using configuration from parent directory: {}",
discovered_path.display()
);
Config::parse(&discovered_path)?
} else {
if !args.context {
warn!(
Expand Down

0 comments on commit de90227

Please sign in to comment.