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
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
Invokesrun(java.lang.String[])
, catching any exceptions thrown and exiting with a non-zero value if and only if an exception was caught.protected final void
Emit an error message an exit with exit value 1.protected String[]
parsePropertyFlags
(String[] args) Parse command line flags of the form-Dname=value
and set the corresponding system properties.abstract int
Subclass main implementation.protected void
Print the usage message and exit with exit value 1.protected abstract void
Display 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=value
and set the corresponding system properties. Parsing stops at the first argument not starting with a dash (or--
).- Parameters:
args
- command line arguments- Returns:
args
with the-Dname=value
flags 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
-