Skip to content

Commit

Permalink
perf(pipeline): modify env loader (#43)
Browse files Browse the repository at this point in the history
- [x] support = sign in environment variable names;
- [x] skip blank lines when parsing .env;
  • Loading branch information
rfprod authored Oct 28, 2023
1 parent bb5966f commit 05130ae
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions src/data_pipeline/environment/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,9 @@ impl DataPipelineEnvironment {
let lines = self.read_lines(env_path_str);
let config: Vec<_> = lines
.iter()
.filter(|x| x.contains('='))
.flat_map(|x| {
let split_pair = x.split('=').collect::<Vec<&str>>();
let mut split_pair = x.split('=').collect::<Vec<&str>>();
let split_key = split_pair.first();
let some_key = split_key.is_some();
let key = if some_key {
Expand All @@ -99,16 +100,8 @@ impl DataPipelineEnvironment {
} else {
String::new()
};
let split_value = split_pair.get(1);
let some_value = split_value.is_some();
let value = if some_value {
match split_value.unwrap().trim().parse::<String>() {
Ok(value) => value,
Err(_) => String::new(),
}
} else {
String::new()
};
split_pair.remove(0);
let value = split_pair.join("");
let map = vec![(key, value)];
map
})
Expand Down

0 comments on commit 05130ae

Please sign in to comment.