mirror of https://github.com/sbt/sbt.git
Refactor State#process for clarity
This commit is contained in:
parent
4ab11d7948
commit
a4e0d9a932
|
|
@ -178,16 +178,16 @@ object State {
|
||||||
/** Provides operations and transformations on State. */
|
/** Provides operations and transformations on State. */
|
||||||
implicit def stateOps(s: State): StateOps = new StateOps {
|
implicit def stateOps(s: State): StateOps = new StateOps {
|
||||||
def process(f: (String, State) => State): State = {
|
def process(f: (String, State) => State): State = {
|
||||||
def doX(x: String, xs: Seq[String]) = {
|
def runCmd(cmd: String, remainingCommands: Seq[String]) = {
|
||||||
log.debug(s"> $x")
|
log.debug(s"> $cmd")
|
||||||
f(x, s.copy(remainingCommands = xs, history = x :: s.history))
|
f(cmd, s.copy(remainingCommands = remainingCommands, history = cmd :: s.history))
|
||||||
}
|
}
|
||||||
def isInteractive = System.console() != null
|
def isInteractive = System.console != null
|
||||||
def hasInput = System.console().reader().ready()
|
def hasInput = Option(System.console) exists (_.reader.ready())
|
||||||
def hasShellCmd = s.definedCommands exists { case c: SimpleCommand => c.name == Shell; case _ => false }
|
def hasShellCmd = s.definedCommands exists { case c: SimpleCommand => c.name == Shell; case _ => false }
|
||||||
s.remainingCommands match {
|
s.remainingCommands match {
|
||||||
case Seq() => if (isInteractive && hasInput && hasShellCmd) doX(Shell, Nil) else exit(true)
|
case Seq() => if (isInteractive && hasInput && hasShellCmd) runCmd(Shell, Nil) else exit(true)
|
||||||
case Seq(x, xs @ _*) => doX(x, xs)
|
case Seq(x, xs @ _*) => runCmd(x, xs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
def :::(newCommands: Seq[String]): State = s.copy(remainingCommands = newCommands ++ s.remainingCommands)
|
def :::(newCommands: Seq[String]): State = s.copy(remainingCommands = newCommands ++ s.remainingCommands)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue