From 9d23439982b4c118c857cab8bad3d3d353bb7367 Mon Sep 17 00:00:00 2001 From: Augustus Mayo Date: Mon, 4 Feb 2019 10:44:31 -0600 Subject: [PATCH] Fix env change selection --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/params.rs | 11 ++++------- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7713438..5a645ce 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -283,7 +283,7 @@ dependencies = [ [[package]] name = "envfmt" -version = "0.2.0" +version = "0.3.0" dependencies = [ "rusoto_core 0.36.0 (registry+https://github.com/rust-lang/crates.io-index)", "rusoto_mock 0.30.0 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/Cargo.toml b/Cargo.toml index c49b340..975338c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ authors = ["Augustus Mayo "] edition = "2018" name = "envfmt" -version = "0.2.0" +version = "0.4.0" license = "Apache-2.0" [badges] diff --git a/src/params.rs b/src/params.rs index 479c9ef..2d99433 100644 --- a/src/params.rs +++ b/src/params.rs @@ -68,7 +68,7 @@ impl ParamBag { for parameter in parameters { if let (Some(name), Some(value)) = (parameter.name, parameter.value) { self.params.push(Param { - key: to_env_name(self.prefix.as_str(), name.as_str()), + key: to_env_name(name.as_str()).to_string(), value, }); } @@ -95,8 +95,8 @@ pub fn make_path_req(path: &str, next_token: Option) -> GetParametersByP } } -pub fn to_env_name(prefix: &str, name: &str) -> String { - name.trim_start_matches(prefix).to_uppercase() +pub fn to_env_name(name: &str) -> String { + name[name.rfind('/').unwrap_or(0) + 1..].to_uppercase() } pub fn get_all_params_for_path(client: &T, path: &str) -> ParamResult @@ -253,10 +253,7 @@ mod tests { #[test] fn test_converts_to_env_var_name() { - assert_eq!( - "PARAM_KEY", - to_env_name("/path/to/the/", "/path/to/the/param_key") - ); + assert_eq!("PARAM_KEY", to_env_name("/path/to/the/param_key")); } #[test]