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
use std::fmt::{Display, Error, Formatter};
#[derive(Clone, Debug)]
pub enum Step {
GitClone {
url: String,
},
Command {
command: String,
workdir: Option<String>,
},
}
impl Step {
pub fn command<S: Display>(command: S, workdir: Option<S>) -> Self {
Step::Command {
command: command.to_string().trim().trim_start_matches("\"").trim_end_matches("\"").to_string(),
workdir: workdir.and_then(|s| Some(s.to_string())),
}
}
pub fn git_clone<S: Display>(url: S) -> Self {
Step::GitClone {
url: url.to_string().trim().trim_start_matches("\"").trim_end_matches("\"").to_string(),
}
}
}
impl Display for Step {
fn fmt(&self, f: &mut Formatter) -> Result<(), Error> {
match self {
Step::GitClone { url } => write!(f,
"steps.Git(repourl=\"{}\", mode=\"incremental\", branch=\"master\", method=\"clobber\", submodules=True)", url),
Step::Command {command, workdir: Some(workdir)} => write!(
f, "steps.ShellCommand(command={command:?}, workdir=\"{workdir}\")",
command = command
.split_whitespace()
.map(String::from)
.collect::<Vec<String>>(),
workdir = workdir
),
Step::Command {command, workdir: None} => write!(
f, "steps.ShellCommand(command={:?})",
command.split_whitespace()
.map(String::from)
.collect::<Vec<String>>()
),
}
}
}