mirror of
https://github.com/denisidoro/navi
synced 2024-11-25 04:50:21 +00:00
Ignore paths with invalid env vars
This commit is contained in:
parent
32a3746174
commit
c976c9199d
1 changed files with 8 additions and 7 deletions
|
@ -67,19 +67,20 @@ fn without_first(string: &str) -> String {
|
||||||
.to_string()
|
.to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn interpolate_paths(paths: String) -> Result<String> {
|
fn interpolate_paths(paths: String) -> String {
|
||||||
let re = Regex::new(r#"\$\{?[a-zA-Z_][a-zA-Z_0-9]*"#).unwrap();
|
let re = Regex::new(r#"\$\{?[a-zA-Z_][a-zA-Z_0-9]*"#).unwrap();
|
||||||
let mut newtext = paths.to_string();
|
let mut newtext = paths.to_string();
|
||||||
for capture in re.captures_iter(&paths) {
|
for capture in re.captures_iter(&paths) {
|
||||||
if let Some(c) = capture.get(0) {
|
if let Some(c) = capture.get(0) {
|
||||||
let varname = c.as_str().replace("$", "").replace("{", "").replace("}", "");
|
let varname = c.as_str().replace("$", "").replace("{", "").replace("}", "");
|
||||||
let replacement = &env_var::get(&varname)?;
|
if let Ok(replacement) = &env_var::get(&varname) {
|
||||||
newtext = newtext
|
newtext = newtext
|
||||||
.replace(&format!("${}", varname), replacement)
|
.replace(&format!("${}", varname), replacement)
|
||||||
.replace(&format!("${{{}}}", varname), replacement);
|
.replace(&format!("${{{}}}", varname), replacement);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(newtext)
|
}
|
||||||
|
newtext
|
||||||
}
|
}
|
||||||
|
|
||||||
fn gen_lists(tag_rules: Option<String>) -> (Option<Vec<String>>, Option<Vec<String>>) {
|
fn gen_lists(tag_rules: Option<String>) -> (Option<Vec<String>>, Option<Vec<String>>) {
|
||||||
|
@ -142,7 +143,7 @@ impl fetcher::Fetcher for Fetcher {
|
||||||
};
|
};
|
||||||
|
|
||||||
let paths = paths.expect("Unable to get paths");
|
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 folders = paths_from_path_param(&interpolated_paths);
|
||||||
|
|
||||||
let home_regex = Regex::new(r"^~").unwrap();
|
let home_regex = Regex::new(r"^~").unwrap();
|
||||||
|
|
Loading…
Reference in a new issue