From be251fef2cfcf79a34f5c4e5086c715234281b5e Mon Sep 17 00:00:00 2001 From: Ryan Leckey Date: Fri, 16 Jun 2017 11:45:23 -0700 Subject: Fix a couple issues, mainly with env source --- src/config.rs | 9 ++++++++- src/env.rs | 8 ++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/config.rs b/src/config.rs index c355f2d..44c51d1 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,4 +1,5 @@ use std::collections::HashMap; +use std::str::FromStr; use serde::de::Deserialize; use error::*; @@ -88,7 +89,13 @@ impl Config { for source in sources { let props = source.collect()?; for (key, val) in &props { - path::Expression::Identifier(key.clone()).set(&mut cache, val.clone()); + match path::Expression::from_str(key) { + // Set using the path + Ok(expr) => expr.set(&mut cache, val.clone()), + + // Set diretly anyway + _ => path::Expression::Identifier(key.clone()).set(&mut cache, val.clone()) + } } } diff --git a/src/env.rs b/src/env.rs index c49bb0e..a0b190b 100644 --- a/src/env.rs +++ b/src/env.rs @@ -28,8 +28,8 @@ impl Environment { Environment::default() } - pub fn with_prefix(s: String) -> Self { - Environment { separator: s, ..Environment::default() } + pub fn with_prefix(s: &str) -> Self { + Environment { prefix: Some(s.into()), ..Environment::default() } } pub fn prefix(&mut self, s: String) -> &mut Self { @@ -68,7 +68,7 @@ impl Source for Environment { // Check for prefix if let Some(ref prefix_pattern) = prefix_pattern { - if key.starts_with(prefix_pattern) { + if key.to_lowercase().starts_with(prefix_pattern) { // Remove this prefix from the key key = key[prefix_pattern.len()..].to_string(); } else { @@ -80,7 +80,7 @@ impl Source for Environment { // Replace `separator` with `.` key = key.replace(&self.separator, "."); - m.insert(key, Value::new(Some(&uri), ValueKind::String(value))); + m.insert(key.to_lowercase(), Value::new(Some(&uri), ValueKind::String(value))); } Ok(m) -- cgit v1.2.3