mirror of
https://github.com/denisidoro/navi
synced 2024-11-21 19:13:07 +00:00
Improve error message when unable to interpolate env vars in path
This commit is contained in:
parent
0f95a29dfd
commit
5a46e48fd6
1 changed files with 4 additions and 4 deletions
|
@ -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();
|
||||
|
|
Loading…
Reference in a new issue