|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.sf.mmm.util.component.base.AbstractLoggableObject
net.sf.mmm.util.cli.api.AbstractMain
@CliClass @CliModes(value=@CliMode(id="help",title="help",usage="Print help about this program.")) public abstract class AbstractMain
This is the abstract base class for a main-program.
Field Summary | |
---|---|
protected static int |
EXIT_CODE_CONSTRAINT_VIOLATION
The exit-code on constraint error (illegal
command-line value). |
protected static int |
EXIT_CODE_ILLEGAL_SYNTAX
The exit-code on syntax error (illegal
command-line arguments). |
protected static int |
EXIT_CODE_OK
The exit-code on success. |
protected static int |
EXIT_CODE_UNEXPECTED
The exit-code if an unexpected
error occurred. |
private boolean |
help
Option to show the usage . |
private CliOutputSettings |
outputSettings
|
private CliParserBuilder |
parserBuilder
|
private PrintWriter |
standardError
|
private PrintWriter |
standardOutput
|
private StreamUtil |
streamUtil
|
Constructor Summary | |
---|---|
AbstractMain()
The constructor. |
Method Summary | |
---|---|
protected IocContainer |
getIocContainer()
This method gets the IocContainer used to manage components with
their implementation. |
CliOutputSettings |
getOutputSettings()
This method gets the output settings used for
information and error messages. |
protected CliParserBuilder |
getParserBuilder()
This method gets the CliParserBuilder used to
build the CliParser . |
Appendable |
getStandardError()
This method gets the standard error where to print errors for the end-user. |
PrintWriter |
getStandardOutput()
This method gets the standard output where to print information for the end-user. |
protected StreamUtil |
getStreamUtil()
This method gets the StreamUtil to use. |
protected int |
handleError(Exception exception,
CliParser parser)
This method is invoked if an Exception occurred. |
protected void |
printHelp(CliParser parser)
This method prints the help output with the program usage. |
protected abstract int |
run(CliModeObject mode)
This method is called after the options are parsed and injected. |
int |
run(String... args)
This method should be invoked from the static main-method. |
void |
setStandardError(Appendable error)
This method sets the standard error . |
void |
setStandardOutput(Appendable output)
This method sets the standard output . |
protected void |
validate(CliModeObject mode)
This method is called after the command-line arguments are checked for syntactically correctness and applied to this class in order to perform complex validations. |
Methods inherited from class net.sf.mmm.util.component.base.AbstractLoggableObject |
---|
getLogger |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected static final int EXIT_CODE_OK
exit-code
on success.
protected static final int EXIT_CODE_ILLEGAL_SYNTAX
exit-code
on syntax error (illegal
command-line arguments).
protected static final int EXIT_CODE_CONSTRAINT_VIOLATION
exit-code
on constraint error (illegal
command-line value).
CliParameterContainer.getValidator()
,
Constant Field Valuesprotected static final int EXIT_CODE_UNEXPECTED
exit-code
if an unexpected
error
occurred.
private final CliOutputSettings outputSettings
getOutputSettings()
private PrintWriter standardOutput
getStandardOutput()
private PrintWriter standardError
getStandardError()
private CliParserBuilder parserBuilder
getParserBuilder()
private StreamUtil streamUtil
getStreamUtil()
@CliOption(name="--help", aliases="-h", required=true, usage="Print this help.", mode="help") private boolean help
usage
.
Constructor Detail |
---|
public AbstractMain()
Method Detail |
---|
protected abstract int run(CliModeObject mode) throws Exception
mode
- is the mode
of the invocation.
EXIT_CODE_OK
on success.
Exception
- in case of an unexpected error.protected int handleError(Exception exception, CliParser parser)
Exception
occurred. It implements how
to handle the error. You may override to add a custom handling.
exception
- is the actual error that occurred.parser
- is the CliParser
.
0
).protected IocContainer getIocContainer()
IocContainer
used to manage components with
their implementation. It should be created and initialized on the first
call of this method.null
to avoid
dependencies on a IocContainer
implementation. Override this method
to use proper component management.
IocContainer
.SpringContainer
protected CliParserBuilder getParserBuilder()
CliParserBuilder
used to
build
the CliParser
.IoC container
in advance to overriding this
method.
CliParserBuilder
.protected StreamUtil getStreamUtil()
StreamUtil
to use.
StreamUtil
to use.public CliOutputSettings getOutputSettings()
output settings
used for
information and error messages.
public final PrintWriter getStandardOutput()
print
information for the end-user.System.out
.
public final void setStandardOutput(Appendable output)
standard output
. It may
be used by sub-classes or tests to redirect output.
output
- is the output to setpublic final Appendable getStandardError()
print
errors for the end-user.System.err
.
public final void setStandardError(Appendable error)
standard error
. It may be
used by sub-classes or tests to redirect errors.
error
- is the error to set.protected void printHelp(CliParser parser)
parser
- is the CliParser
.protected void validate(CliModeObject mode) throws RuntimeException
mode
- is the mode
of the invocation.
RuntimeException
- if the state is invalid.public int run(String... args)
args
- are the commandline-arguments.
0
on success.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |