bolt/utils/
resolve_alias.rs

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
34
35
36
37
38
39
40
use std::ffi::OsString;
use std::path::Path;

use super::super::utils;

pub fn resolve_alias(root: &str, alias: &str, results: Vec<OsString>) -> Option<String> {
    let wp_cfg = utils::get_workspace_config();
    let target: Vec<_> = results
        .iter()
        .filter(|r| {
            let str_version = r.to_str().unwrap();
            match &wp_cfg.registered {
                Some(vector) => {
                    if vector.contains(&str_version.to_owned()) {
                        let proj_path: String = format!("{}/{}/", root, str_version);
                        let config = utils::get_project_config(&Path::new(proj_path.as_str()));

                        return config.info.alias == alias;
                    }
                    false
                }
                None => {
                    let proj_path: String = format!("{}/{}/", root, str_version);
                    let config = utils::get_project_config(&Path::new(proj_path.as_str()));

                    config.info.alias == alias
                }
            }
        })
        .collect();

    if target.is_empty() {
        return None;
    }

    let resolved = target[0].to_str().unwrap();
    let resolved_path = format!("{}/{}/", root, resolved);

    Some(resolved_path)
}