Cleanup State#process

This commit is contained in:
Dale Wijnand 2018-01-26 12:58:58 +00:00
parent 685b416b8e
commit 7b11729f8c
No known key found for this signature in database
GPG Key ID: 4F256E3D151DF5EF
1 changed files with 8 additions and 6 deletions

View File

@ -238,14 +238,16 @@ object State {
def process(f: (Exec, State) => State): State = {
def runCmd(cmd: Exec, remainingCommands: List[Exec]) = {
log.debug(s"> $cmd")
f(cmd,
s.copy(remainingCommands = remainingCommands,
currentCommand = Some(cmd),
history = cmd :: s.history))
val s1 = s.copy(
remainingCommands = remainingCommands,
currentCommand = Some(cmd),
history = cmd :: s.history,
)
f(cmd, s1)
}
s.remainingCommands match {
case List() => exit(true)
case List(x, xs @ _*) => runCmd(x, xs.toList)
case Nil => exit(true)
case x :: xs => runCmd(x, xs)
}
}
def :::(newCommands: List[String]): State = ++:(newCommands map { Exec(_, s.source) })