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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#[cfg(test)]
#[path = "./types_test.rs"]
mod types_test;
use std::error;
use std::fmt;
use std::fmt::Display;
use std::io::Error;
#[derive(Debug)]
pub enum ErrorInfo {
IOError(Error),
Description(&'static str)
}
#[derive(Debug)]
pub struct ScriptError {
pub info: ErrorInfo
}
impl error::Error for ScriptError {
fn description(&self) -> &str {
match self.info {
ErrorInfo::IOError(ref cause) => cause.description(),
ErrorInfo::Description(description) => description,
}
}
fn cause(&self) -> Option<&error::Error> {
match self.info {
ErrorInfo::IOError(ref cause) => Some(cause as &error::Error),
_ => None,
}
}
}
impl Display for ScriptError {
fn fmt(
&self,
format: &mut fmt::Formatter,
) -> Result<(), fmt::Error> {
match self.info {
ErrorInfo::IOError(ref cause) => cause.fmt(format),
ErrorInfo::Description(description) => description.fmt(format),
}
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct ScriptOptions {
pub runner: Option<String>,
pub capture_output: bool,
pub exit_on_error: bool,
pub print_commands: bool
}
impl ScriptOptions {
pub fn new() -> ScriptOptions {
ScriptOptions { runner: None, capture_output: true, exit_on_error: false, print_commands: false }
}
}