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
extern crate toml_edit;
extern crate ansi_term;

pub mod recipe;
pub mod steps;
pub mod config;
mod display;
mod cmd;

use config::stages::parse_config_file;
use config::steps::{parse_steps_config_file, StepConfig};
use std::process::exit;
use steps::Context;
use std::error::Error;

pub enum Operation {
    Deploy,
    Rollback
}

pub fn init_stage_context(config_file: &str, stage: &str, opt: Operation) -> Context {

    let host_config =  match parse_config_file(config_file, stage) {
        Ok(context) => context,
        Err(config_error) => {
            eprintln!("config error: {}", config_error);
            exit(1);
        }
    };

    let context = match Context::from_host_config(host_config, opt) {
        Ok(context) => context,
        Err(message) => {
            eprintln!("error: {:?}", message.description());
            exit(1);
        }
    };

    context
}

pub fn init_steps_from_config(config_file: &str, stage: &str) -> Vec<StepConfig> {
    parse_steps_config_file(config_file, stage).unwrap_or_else(|e| {
        eprintln!("steps config error: {}", e);
        exit(1);
    })
}