Skip to content

Commit e8c54b1

Browse files
authored
Merge pull request #1161 from pkgxdev/refactor
Refactor
2 parents 4ed1d28 + a5615b6 commit e8c54b1

8 files changed

Lines changed: 494 additions & 403 deletions

File tree

crates/cli/src/dump.rs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
use std::collections::HashMap;
2+
3+
use libpkgx::{
4+
platform_case_aware_env_key::construct_platform_case_aware_env_key, types::Installation,
5+
};
6+
use serde_json::json;
7+
8+
pub fn dump(
9+
conn: rusqlite::Connection,
10+
installations: Vec<Installation>,
11+
env: HashMap<String, Vec<String>>,
12+
flags: &crate::args::Flags,
13+
) -> Result<(), Box<dyn std::error::Error>> {
14+
if !flags.json {
15+
let env = env
16+
.iter()
17+
.map(|(k, v)| {
18+
(
19+
construct_platform_case_aware_env_key(k.clone()),
20+
v.join(":"),
21+
)
22+
})
23+
.collect();
24+
let env = libpkgx::env::mix_runtime(&env, &installations, &conn)?;
25+
for (key, value) in env {
26+
println!(
27+
"{}=\"{}\"",
28+
key,
29+
value.replace(&format!(":${}", key), &format!("${{{}:+:${}}}", key, key))
30+
);
31+
}
32+
} else {
33+
let mut runtime_env = HashMap::new();
34+
for pkg in installations.clone() {
35+
let pkg_runtime_env =
36+
libpkgx::pantry_db::runtime_env_for_project(&pkg.pkg.project, &conn)?;
37+
if !pkg_runtime_env.is_empty() {
38+
runtime_env.insert(pkg.pkg.project, pkg_runtime_env);
39+
}
40+
}
41+
let json = json!({
42+
"pkgs": installations,
43+
"env": env,
44+
"runtime_env": runtime_env
45+
});
46+
println!("{}", json);
47+
}
48+
Ok(())
49+
}

0 commit comments

Comments
 (0)