Skip to content

Commit

Permalink
Enable custom config file placement using the PLS_CONFIG env var
Browse files Browse the repository at this point in the history
  • Loading branch information
dhruvkb committed Dec 29, 2023
1 parent 782e710 commit 6f3d2bc
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/config/man.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use figment::providers::{Data, Format, Serialized, Yaml};
use figment::Figment;
use git2::Repository;
use log::{debug, info};
use std::env;
use std::path::Path;

/// Manages the configuration system of the application. This manager provides
Expand All @@ -15,14 +16,17 @@ pub struct ConfMan {
}

impl Default for ConfMan {
/// This includes config files from the following locations:
/// This includes config files from the one of the following locations:
///
/// * the home directory, if determined
/// * the file referenced in the `PLS_CONFIG` environment variable
/// * `.pls.yml` in the user's home directory
fn default() -> Self {
info!("Preparing base configuration.");

let mut base = Figment::from(Serialized::defaults(Conf::default()));
if let Some(home_yaml) = home::home_dir().and_then(Self::conf_at) {
if let Ok(config_path) = env::var("PLS_CONFIG") {
base = base.admerge(Yaml::file(config_path));
} else if let Some(home_yaml) = home::home_dir().and_then(Self::conf_at) {
base = base.admerge(home_yaml);
}

Expand Down

0 comments on commit 6f3d2bc

Please sign in to comment.