bricks/cli/install/
mod.rs

1use std::{fs, path::Path};
2
3use anyhow::{bail, Result};
4
5use crate::{
6    cli::pretty,
7    config::{overrides::OverrideDatabase, Config},
8    libs::install_lib::install_lib,
9};
10
11use super::args::InstallCommand;
12
13pub fn install(config: &Config, install_command: InstallCommand) -> Result<()> {
14    let mut override_db = OverrideDatabase::new();
15
16    for (name, lib) in &config.libs {
17        match install_lib(name, lib, install_command.force, install_command.silent) {
18            Ok(Some(overrides)) => {
19                override_db.insert(name.to_string(), overrides);
20            }
21            Ok(_) => {}
22            Err(err) => {
23                bail!(
24                    "during install. {}\nresolve the problem and then run `bricks install --force`",
25                    err
26                )
27            }
28        };
29    }
30
31    let override_path = Path::new(&install_command.path)
32        .join("build")
33        .join("overrides.json");
34    match fs::create_dir_all(override_path.parent().unwrap()) {
35        Ok(_) => {}
36        Err(err) => {
37            dbg!(err);
38        }
39    };
40    let override_file = fs::File::create(override_path)?;
41    serde_json::to_writer(override_file, &override_db)?;
42
43    if !install_command.silent {
44        pretty::info("done!");
45        pretty::info("you might need to run `bricks build` before seeing headers in your editor");
46        pretty::info("if you are still having issues, try `bricks install --force`");
47    }
48
49    Ok(())
50}