1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
use anyhow::Error;

use crate::{config::verify_if_config_file_is_present, graph::build_installer_graph};

pub fn execute_install(tool: Option<String>) -> Result<(), Error> {
    let config = verify_if_config_file_is_present()?;

    match tool {
        Some(tool) => {
            let tool = tool.replace(" ", "");
            let tool = tool.replace("ble.sh", "blesh");
            let tools = match tool.contains(",") {
                true => tool.split(",").collect(),
                false => vec![tool.as_str()],
            };
            for tool in tools {
                let (graph, installers) = build_installer_graph(&config);
                let tool = installers
                    .into_iter()
                    .find(|installer| installer.name() == tool)
                    .ok_or_else(|| Error::msg(format!("{} is not available yet", tool)))?;
                let mut visited = vec![false; graph.size()];
                graph.install(tool, &mut visited)?;
            }
        }
        None => {
            let (graph, _) = build_installer_graph(&config);
            graph.install_all()?;
        }
    }

    Ok(())
}