rusty_ci/buildbot/
step.rs1use std::fmt::{Display, Error, Formatter};
2
3#[derive(Clone, Debug)]
6pub enum Step {
7 GitClone {
9 url: String, },
11
12 GitLabClone {
16 url: String, },
18
19 Command {
21 command: String, workdir: Option<String>, },
24}
25
26impl Step {
28 pub fn command<S: Display>(command: S, workdir: Option<S>) -> Self {
30 Step::Command {
31 command: command.to_string(),
32 workdir: workdir.and_then(|s| Some(s.to_string())),
33 }
34 }
35
36 pub fn git_clone<S: Display>(url: S) -> Self {
38 Step::GitClone {
39 url: url
40 .to_string()
41 .trim()
42 .trim_start_matches('\"')
43 .trim_end_matches('\"')
44 .to_string(),
45 }
47 }
48
49 pub fn gitlab_clone<S: Display>(url: S) -> Self {
51 Step::GitLabClone {
52 url: url
53 .to_string()
54 .trim()
55 .trim_start_matches('\"')
56 .trim_end_matches('\"')
57 .to_string(),
58 }
60 }
61}
62
63impl Display for Step {
65 fn fmt(&self, f: &mut Formatter) -> Result<(), Error> {
66 match self {
67 Step::GitClone { url } => write!(f,
69 "steps.Git(repourl=\"{}\", mode=\"full\", branch=\"master\", method=\"clobber\", shallow=False, submodules=True)", url),
70
71 Step::GitLabClone { url } => write!(f,
73 "steps.GitLab(repourl=\"{}\", mode=\"full\", branch=\"master\", method=\"clobber\", shallow=False, submodules=True)", url),
74
75 Step::Command {command, workdir: Some(workdir)} => write!(
77 f, "steps.ShellCommand(command={command:?}, workdir=\"{workdir}\")",
78 command = command
79 .split_whitespace()
80 .map(String::from)
81 .collect::<Vec<String>>(),
82 workdir = workdir
83 ),
84
85 Step::Command {command, workdir: None} => write!(
87 f, "steps.ShellCommand(command={:?})",
88 command.split_whitespace()
89 .map(String::from)
90 .collect::<Vec<String>>()
91 ),
92 }
93 }
94}