CORDA-1838: A few misc fixes (#4126)

* Remove unused code

* Make comment readable

* Remove joptsimple from node/shell

* tabs vs whitespace
This commit is contained in:
Anthony Keenan
2018-10-30 14:01:20 +00:00
committed by GitHub
parent 1de56550b0
commit 30fedec343
6 changed files with 10 additions and 49 deletions

View File

@ -1,39 +0,0 @@
package net.corda.node.utilities
import joptsimple.OptionException
import joptsimple.OptionParser
import joptsimple.OptionSet
import kotlin.system.exitProcess
abstract class AbstractArgsParser<out T : Any> {
protected val optionParser = OptionParser()
private val helpOption = optionParser.acceptsAll(listOf("h", "help"), "show help").forHelp()
/**
* Parses the given [args] or exits the process if unable to, printing the help output to stderr.
* If the help option is specified then the process is also shutdown after printing the help output to stdout.
*/
fun parseOrExit(vararg args: String): T {
try {
val optionSet = optionParser.parse(*args)
if (optionSet.has(helpOption)) {
optionParser.printHelpOn(System.out)
exitProcess(0)
}
return doParse(optionSet)
} catch (e: Exception) {
when (e) {
is OptionException, is IllegalArgumentException -> {
System.err.println(e.message ?: "Unable to parse arguments.")
optionParser.printHelpOn(System.err)
exitProcess(1)
}
else -> throw e
}
}
}
fun parse(vararg args: String): T = doParse(optionParser.parse(*args))
protected abstract fun doParse(optionSet: OptionSet): T
}