From a4e0d9a932ffa4f5b7c17c916619318dd3106dd3 Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Thu, 27 Apr 2017 13:03:34 +0100 Subject: [PATCH] Refactor State#process for clarity --- main/command/src/main/scala/sbt/State.scala | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/main/command/src/main/scala/sbt/State.scala b/main/command/src/main/scala/sbt/State.scala index bc79ba7a7..64cdf80e7 100644 --- a/main/command/src/main/scala/sbt/State.scala +++ b/main/command/src/main/scala/sbt/State.scala @@ -178,16 +178,16 @@ object State { /** Provides operations and transformations on State. */ implicit def stateOps(s: State): StateOps = new StateOps { def process(f: (String, State) => State): State = { - def doX(x: String, xs: Seq[String]) = { - log.debug(s"> $x") - f(x, s.copy(remainingCommands = xs, history = x :: s.history)) + def runCmd(cmd: String, remainingCommands: Seq[String]) = { + log.debug(s"> $cmd") + f(cmd, s.copy(remainingCommands = remainingCommands, history = cmd :: s.history)) } - def isInteractive = System.console() != null - def hasInput = System.console().reader().ready() + def isInteractive = System.console != null + def hasInput = Option(System.console) exists (_.reader.ready()) def hasShellCmd = s.definedCommands exists { case c: SimpleCommand => c.name == Shell; case _ => false } s.remainingCommands match { - case Seq() => if (isInteractive && hasInput && hasShellCmd) doX(Shell, Nil) else exit(true) - case Seq(x, xs @ _*) => doX(x, xs) + case Seq() => if (isInteractive && hasInput && hasShellCmd) runCmd(Shell, Nil) else exit(true) + case Seq(x, xs @ _*) => runCmd(x, xs) } } def :::(newCommands: Seq[String]): State = s.copy(remainingCommands = newCommands ++ s.remainingCommands)