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
#![deny(warnings)]

extern crate chrono;
#[macro_use] extern crate clap;
#[macro_use] extern crate error_chain;
extern crate git2;
#[macro_use] extern crate lazy_static;
#[macro_use] extern crate log;
extern crate mockito;
extern crate reqwest;
extern crate serde;
#[macro_use] extern crate serde_derive;
#[macro_use] extern crate serde_json;
extern crate termion;
extern crate url;
extern crate ws;

pub mod authentication;
pub mod cli;
pub mod client;
pub mod config;
pub mod deploy;
pub mod errors;
pub mod logs;
pub mod repo;
pub mod stages;
pub mod websocket;

pub use client::{Client, HttpClient, default_sherpa_stage};

use errors::Error;
use std::io::Write;
use std::process::exit;

pub fn handle_error(error: Error) {
    let stderr = &mut ::std::io::stderr();
    let errmsg = "Error writing to stderr";

    writeln!(stderr, "error: {}", error).expect(errmsg);

    for e in error.iter().skip(1) {
        writeln!(stderr, "caused by: {}", e).expect(errmsg);
    }

    // The backtrace is not always generated. Try to run this example
    // with `RUST_BACKTRACE=1`.
    if let Some(backtrace) = error.backtrace() {
        writeln!(stderr, "backtrace: {:?}", backtrace).expect(errmsg);
    }

    exit(1);
}