Skip to content

Commit

Permalink
Refactor apply/pitch logic a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
tailhook committed Apr 3, 2018
1 parent 6caa06c commit 6d91206
Showing 1 changed file with 17 additions and 34 deletions.
51 changes: 17 additions & 34 deletions src/render/apply/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,43 +172,26 @@ pub fn apply_list(role: &String,
sandbox: &Sandbox)
-> Result<(), Error>
{
let mut tasks = Vec::new();
for &(ref aname, ref commands, ref source) in &actions {
if commands.iter().any(|cmd| cmd.needs_pitch()) {
// TODO(tailhook) log.preaction?
let mut action = log.action(&aname);
let mut atasks = Vec::new();
for cmd in commands {
let vars = expand::Variables::new()
.add("role", role)
.add_source(&source);
if cmd.needs_pitch() {
let mut task = Task {
runner: &aname,
log: &mut action,
scratch: Scratch::new(),
dry_run, source, sandbox,
};
cmd.pitch(&mut task, &vars)?;
atasks.push((cmd, task.scratch, vars));
} else {
atasks.push((cmd, Scratch::new(), vars));
}
}
tasks.push((aname, atasks, source));
} else {
let mut atasks = Vec::new();
for cmd in commands {
let vars = expand::Variables::new()
.add("role", role)
.add_source(&source);
let mut action = log.action(&aname);
let mut atasks = Vec::with_capacity(commands.len());
for cmd in commands {
let vars = expand::Variables::new()
.add("role", role)
.add_source(&source);
if cmd.needs_pitch() {
let mut task = Task {
runner: &aname,
log: &mut action,
scratch: Scratch::new(),
dry_run, source, sandbox,
};
cmd.pitch(&mut task, &vars)?;
atasks.push((cmd, task.scratch, vars));
} else {
atasks.push((cmd, Scratch::new(), vars));
}
tasks.push((aname, atasks, source));
};
}
for (aname, atasks, source) in tasks {
let mut action = log.action(&aname);
}
for (cmd, scratch, vars) in atasks {
cmd.execute(&mut Task {
runner: &aname,
Expand Down

0 comments on commit 6d91206

Please sign in to comment.