Package org.dellroad.stuff.main
Class MainClass
java.lang.Object
org.dellroad.stuff.main.MainClass
- Direct Known Subclasses:
ContextMainClass
Support superclass for command line classes.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidInvokesrun(java.lang.String[]), catching any exceptions thrown and exiting with a non-zero value if and only if an exception was caught.protected final voidEmit an error message an exit with exit value 1.protected String[]parsePropertyFlags(String[] args) Parse command line flags of the form-Dname=valueand set the corresponding system properties.abstract intSubclass main implementation.protected voidPrint the usage message and exit with exit value 1.protected abstract voidDisplay the usage message to standard error.
-
Field Details
-
log
-
-
Constructor Details
-
MainClass
protected MainClass()
-
-
Method Details
-
run
Subclass main implementation. This method is free to throw exceptions; these will be displayed on standard error and converted into non-zero exit values.- Parameters:
args- command line arguments- Returns:
- process exit value
- Throws:
Exception- if an error occurs; will result in the process exiting with an exit value of one
-
usageMessage
protected abstract void usageMessage()Display the usage message to standard error. -
usageError
protected void usageError()Print the usage message and exit with exit value 1. -
errout
Emit an error message an exit with exit value 1.- Parameters:
message- error message
-
parsePropertyFlags
Parse command line flags of the form-Dname=valueand set the corresponding system properties. Parsing stops at the first argument not starting with a dash (or--).- Parameters:
args- command line arguments- Returns:
argswith the-Dname=valueflags removed
-
doMain
Invokesrun(java.lang.String[]), catching any exceptions thrown and exiting with a non-zero value if and only if an exception was caught.The concrete class'
main()method should invoke this method.- Parameters:
args- command line arguments
-