mirror of https://github.com/sbt/sbt.git
Refactor nulls to Option
This commit is contained in:
parent
ee7e2889dc
commit
5004b8a515
|
|
@ -15,13 +15,12 @@ abstract class JLine extends LineReader {
|
||||||
|
|
||||||
def readLine(prompt: String, mask: Option[Char] = None) = JLine.withJLine { unsynchronizedReadLine(prompt, mask) }
|
def readLine(prompt: String, mask: Option[Char] = None) = JLine.withJLine { unsynchronizedReadLine(prompt, mask) }
|
||||||
|
|
||||||
private[this] def unsynchronizedReadLine(prompt: String, mask: Option[Char]) =
|
private[this] def unsynchronizedReadLine(prompt: String, mask: Option[Char]): Option[String] =
|
||||||
readLineWithHistory(prompt, mask) match {
|
readLineWithHistory(prompt, mask) map { x =>
|
||||||
case null => None
|
x.trim
|
||||||
case x => Some(x.trim)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private[this] def readLineWithHistory(prompt: String, mask: Option[Char]): String =
|
private[this] def readLineWithHistory(prompt: String, mask: Option[Char]): Option[String] =
|
||||||
reader.getHistory match {
|
reader.getHistory match {
|
||||||
case fh: FileHistory =>
|
case fh: FileHistory =>
|
||||||
try { readLineDirect(prompt, mask) }
|
try { readLineDirect(prompt, mask) }
|
||||||
|
|
@ -29,17 +28,17 @@ abstract class JLine extends LineReader {
|
||||||
case _ => readLineDirect(prompt, mask)
|
case _ => readLineDirect(prompt, mask)
|
||||||
}
|
}
|
||||||
|
|
||||||
private[this] def readLineDirect(prompt: String, mask: Option[Char]): String =
|
private[this] def readLineDirect(prompt: String, mask: Option[Char]): Option[String] =
|
||||||
if (handleCONT)
|
if (handleCONT)
|
||||||
Signals.withHandler(() => resume(), signal = Signals.CONT)(() => readLineDirectRaw(prompt, mask))
|
Signals.withHandler(() => resume(), signal = Signals.CONT)(() => readLineDirectRaw(prompt, mask))
|
||||||
else
|
else
|
||||||
readLineDirectRaw(prompt, mask)
|
readLineDirectRaw(prompt, mask)
|
||||||
private[this] def readLineDirectRaw(prompt: String, mask: Option[Char]): String =
|
private[this] def readLineDirectRaw(prompt: String, mask: Option[Char]): Option[String] =
|
||||||
{
|
{
|
||||||
val newprompt = handleMultilinePrompt(prompt)
|
val newprompt = handleMultilinePrompt(prompt)
|
||||||
mask match {
|
mask match {
|
||||||
case Some(m) => reader.readLine(newprompt, m)
|
case Some(m) => Option(reader.readLine(newprompt, m))
|
||||||
case None => reader.readLine(newprompt)
|
case None => Option(reader.readLine(newprompt))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue