bolt/cmd/
up.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
use std::path::Path;

use colored::Colorize;

use crate::core::process_args::process_args;

use super::super::core;
use super::super::parser;
use super::super::program::Program;
use super::super::utils::ProjectConfig;

struct UpConfig {
    // help: bool,
    skip: bool,
}

pub fn up(cmd: &parser::Command, args: &Vec<String>) {
    if args.is_empty() {
        // dont throw err, instead prompt for opts: run all, enter prio, choose
        Program::output_command_help(cmd, "Missing required argument");
        return;
    }

    let (flags, name) = process_args(cmd, args);
    let mut opts = UpConfig {
        // help: false,
        skip: false,
    };

    for flag in flags {
        match flag.as_str() {
            "-s" | "--skip" => opts.skip = true,
            "-h" | "--help" => {
                Program::output_command_help(cmd, "");
                return;
            }
            _ => continue,
        }
    }

    if name.is_empty() {
        println!("{}", "Please pass the name of the project to start".red());
        return;
    }

    let (proj_path, config) = core::setup_cmd(&name);
    core::load_directives(Path::new(&proj_path.as_str()), false);
    start(config, "up".to_owned(), &proj_path)
}

fn start(cfg: ProjectConfig, value: String, dir: &String) {
    let root_path = std::env::current_dir().unwrap();
    let full_path = Path::new(&root_path).join(&dir);

    match core::resolve_policy(cfg.clone(), value) {
        (Some(val), cmd, msg) => {
            start(cfg.clone(), val, &dir);
            core::execute(&cmd, &full_path, true, &msg);
        }
        (None, cmd, msg) => {
            core::execute(&cmd, &full_path, true, &msg);
        }
    }
}