Improve error message when unable to interpolate env vars in path

This commit is contained in:
Denis Isidoro 2021-08-09 09:55:36 -03:00 committed by GitHub
parent 0f95a29dfd
commit 5a46e48fd6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -67,19 +67,19 @@ fn without_first(string: &str) -> String {
.to_string()
}
fn interpolate_paths(paths: String) -> String {
fn interpolate_paths(paths: String) -> Result<String> {
let re = Regex::new(r#"\$\{?[a-zA-Z_][a-zA-Z_0-9]*"#).unwrap();
let mut newtext = paths.to_string();
for capture in re.captures_iter(&paths) {
if let Some(c) = capture.get(0) {
let varname = c.as_str().replace("$", "").replace("{", "").replace("}", "");
let replacement = &env_var::must_get(&varname);
let replacement = &env_var::get(&varname)?;
newtext = newtext
.replace(&format!("${}", varname), replacement)
.replace(&format!("${{{}}}", varname), replacement);
}
}
newtext
Ok(newtext)
}
fn gen_lists(tag_rules: Option<String>) -> (Option<Vec<String>>, Option<Vec<String>>) {
@ -142,7 +142,7 @@ impl fetcher::Fetcher for Fetcher {
};
let paths = paths.expect("Unable to get paths");
let interpolated_paths = interpolate_paths(paths);
let interpolated_paths = interpolate_paths(paths)?;
let folders = paths_from_path_param(&interpolated_paths);
let home_regex = Regex::new(r"^~").unwrap();