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
mod rsscript;
mod shell_to_batch;
#[cfg(test)]
#[path = "./mod_test.rs"]
mod mod_test;
use types::Task;
#[derive(Debug, Clone, PartialEq)]
enum EngineType {
Rust,
Shell2Batch,
Unsupported
}
fn get_engine_type(task: &Task) -> EngineType {
match task.script_runner {
Some(ref script_runner) => {
match task.script {
None => EngineType::Unsupported,
_ => {
debug!("Checking script runner: {}", script_runner);
if script_runner == "@rust" {
debug!("Rust script detected.");
EngineType::Rust
} else if script_runner == "@shell" {
debug!("Shell to batch detected.");
EngineType::Shell2Batch
} else {
EngineType::Unsupported
}
}
}
}
None => EngineType::Unsupported,
}
}
pub fn invoke(task: &Task) -> bool {
let engine_type = get_engine_type(&task);
match engine_type {
EngineType::Rust => {
let script = task.script.as_ref().unwrap();
rsscript::execute(script);
true
}
EngineType::Shell2Batch => {
let script = task.script.as_ref().unwrap();
shell_to_batch::execute(script);
true
}
EngineType::Unsupported => false,
}
}