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(),
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=\"full\", branch=\"master\", method=\"clobber\", shallow=False, 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>>()
),
}
}
}