diff options
author | Christopher Vogt <oss.nsp@cvogt.org> | 2016-09-28 08:33:29 -0400 |
---|---|---|
committer | Christopher Vogt <oss.nsp@cvogt.org> | 2016-09-28 08:33:29 -0400 |
commit | d5a2a050a92b3844a21920b8e4629a4a295f8250 (patch) | |
tree | 1bacc3563be2176cc9606af35751ee87e3175774 /stage2/Lib.scala | |
parent | d23dd6040fdba7b201e5f15d7027030d5259ef8e (diff) | |
download | cbt-d5a2a050a92b3844a21920b8e4629a4a295f8250.tar.gz cbt-d5a2a050a92b3844a21920b8e4629a4a295f8250.tar.bz2 cbt-d5a2a050a92b3844a21920b8e4629a4a295f8250.zip |
unify checking for availability of java.io.Console
Diffstat (limited to 'stage2/Lib.scala')
-rw-r--r-- | stage2/Lib.scala | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/stage2/Lib.scala b/stage2/Lib.scala index c7580d4..e983a97 100644 --- a/stage2/Lib.scala +++ b/stage2/Lib.scala @@ -199,6 +199,12 @@ final class Lib(logger: Logger) extends Stage1Lib(logger) with Scaffold{ } } + def consoleOrFail(msg: String) = { + Option(System.console).getOrElse( + throw new Exception(msg + ". java.io.Console == null. See https://github.com/cvogt/cbt/issues/236") + ) + } + def clean(target: File, force: Boolean, dryRun: Boolean, list: Boolean, help: Boolean): ExitCode = { def depthFirstFileStream(file: File): Vector[File] = { ( @@ -225,9 +231,7 @@ final class Lib(logger: Logger) extends Stage1Lib(logger) with Scaffold{ } else { val performDelete = ( force || { - val console = Option(System.console).getOrElse( - throw new Exception("Can't access Console. Try running `cbt direct clean` or `cbt clean list` or `cbt clean force`.") - ) + val console = consoleOrFail("Use `cbt direct clean` or `cbt clean help`") System.err.println("Files to be deleted:\n\n") files.foreach( System.err.println ) System.err.println("") @@ -314,11 +318,7 @@ final class Lib(logger: Logger) extends Stage1Lib(logger) with Scaffold{ } lazy val passphrase = - Option(System.console).getOrElse( - throw new Exception("Can't access Console. This probably shouldn't be run through Nailgun.") - ).readPassword( - "GPG Passphrase please:" - ).mkString + consoleOrFail( "Use `cbt direct <task>`" ).readPassword( "GPG Passphrase please:" ).mkString def sign(file: File): File = { //http://stackoverflow.com/questions/16662408/correct-way-to-sign-and-verify-signature-using-bouncycastle |