public abstract class AbstractCLIApplication
extends java.lang.Object
implements org.eclipse.equinox.app.IApplication
Modifier and Type | Field and Description |
---|---|
protected static int |
DEFAULT_HELP_WIDTH
Default with used when printing command line usage help.
|
protected java.io.PrintStream |
err |
static java.lang.Object |
ERROR_NO
Error code to indicate that everything is fine.
|
static java.lang.Object |
ERROR_UNSPECIFIED
General purpose error code used to indicate that something went wrong.
|
protected java.io.PrintStream |
out |
Constructor and Description |
---|
AbstractCLIApplication() |
Modifier and Type | Method and Description |
---|---|
protected void |
addOption(org.apache.commons.cli.Option option)
Registers given
option as supported command line option. |
protected org.apache.commons.cli.CommandLineParser |
createParser()
Creates an instance of the
command line parser to be used for analyzing the application
arguments. |
protected void |
defineOptions()
Returns the set of command line
option s to be used for parsing the application arguments. |
protected java.lang.String[] |
getApplicationArgs()
Returns the list of arguments passed to this
application . |
protected java.lang.String |
getApplicationDescription()
Returns a brief description of what this
application is doing. |
protected java.lang.String |
getApplicationName()
Deprecated.
Use
getCommandLineSyntax() instead. |
protected org.apache.commons.cli.CommandLine |
getCommandLine()
Returns the
command line resulting of the parsing operation on application arguments. |
protected java.lang.String |
getCommandLineSyntax()
Returns the command line syntax for this
application . |
protected org.apache.commons.cli.Options |
getOptions()
Returns the supported
command line options . |
protected org.apache.commons.cli.CommandLineParser |
getParser()
Returns the
command line parser to be used for analyzing the application arguments. |
protected java.lang.Object |
handleError(java.lang.Throwable throwable)
Central place for handling errors occurring while this
application is run. |
protected java.lang.Object |
interrogate()
Implements the interrogation stage that is invoked after the parsing stage analyzing the command line options.
|
protected boolean |
isHelpNeeded(org.apache.commons.cli.CommandLine commandLine)
Determines if command line usage help needs to be printed.
|
protected void |
parse()
Parses the application arguments based on the command line
Option s supported by this
application . |
protected void |
printHelp()
Prints the command line usage help.
|
java.lang.Object |
run(java.lang.String[] args)
Alternative entry point that can be used to invoke this
application from
non-Eclipse headless contexts (e.g., Ant task, Java standalone application). |
void |
setErrorStream(java.io.PrintStream err)
Uses given
print stream as substitution for System.err and uses it for all subsequent
writes to the "standard" error output stream. |
void |
setOutputStream(java.io.PrintStream out)
Uses given
print stream as substitution for System.out and uses it for all subsequent
writes to the "standard" output stream. |
java.lang.Object |
start(org.eclipse.equinox.app.IApplicationContext context) |
void |
stop() |
public static final java.lang.Object ERROR_NO
public static final java.lang.Object ERROR_UNSPECIFIED
Clients typically define application-specific error codes with values greater than 1
to give a hint
at the cause that has led to a failure. Applications which do not require such sophisticated error handling may
rely on this error code instead.
protected static final int DEFAULT_HELP_WIDTH
printHelp()
,
Constant Field Valuesprotected java.io.PrintStream out
protected java.io.PrintStream err
@Deprecated protected java.lang.String getApplicationName()
getCommandLineSyntax()
instead.application
.protected java.lang.String getApplicationDescription()
application
is doing.protected java.lang.String getCommandLineSyntax()
application
. Is expected to include
relevant Eclipse runtime options, application id, and arguments but not a detailed description of the command
line options. The latter is automatically added upon printing the application's help with printHelp()
.
E.g.,
eclipse -noSplash -data-application org.example.cli.SomeApplication [options] file
printHelp()
protected java.lang.String[] getApplicationArgs()
application
.protected org.apache.commons.cli.Options getOptions()
command line options
.protected void addOption(org.apache.commons.cli.Option option)
option
as supported command line option.option
- protected org.apache.commons.cli.CommandLine getCommandLine()
command line
resulting of the parsing operation on application arguments.public void setOutputStream(java.io.PrintStream out)
print stream
as substitution for System.out
and uses it for all subsequent
writes to the "standard" output stream.out
- The print stream to be used instead of System.out
.System.out
public void setErrorStream(java.io.PrintStream err)
print stream
as substitution for System.err
and uses it for all subsequent
writes to the "standard" error output stream.err
- The print stream to be used instead of System.err
.System.err
public java.lang.Object start(org.eclipse.equinox.app.IApplicationContext context)
start
in interface org.eclipse.equinox.app.IApplication
public void stop()
stop
in interface org.eclipse.equinox.app.IApplication
public java.lang.Object run(java.lang.String[] args)
application
from
non-Eclipse headless contexts (e.g., Ant task, Java standalone application).args
- The arguments for the application. The content of this argument will be checked for if it conforms to
the expectations of the application being invoked.protected void defineOptions()
option
s to be used for parsing the application arguments. The
command line usage help option is supported by default.
Clients should override this method to provide their own command line options.
http://commons.apache.org/cli/usage.html
protected void parse() throws org.apache.commons.cli.ParseException
Option
s supported by this
application
.org.apache.commons.cli.ParseException
#defineOptions()}
protected org.apache.commons.cli.CommandLineParser getParser()
command line parser
to be used for analyzing the application arguments.protected org.apache.commons.cli.CommandLineParser createParser()
command line parser
to be used for analyzing the application
arguments. Three command line parser types are available out-of-the box: BasicParser
, GnuParser
,
PosixParser
. In addition, clients are free to provide and use their own command line parser
implementations.defineOptions()
,
http://commons.apache.org/cli/usage.html
protected java.lang.Object interrogate() throws java.lang.Throwable
application
's semantics according to the command line
options that have been detected in the application arguments needs to be defined. The semantics for the command
line usage help option is implemented by default.
Clients should override this method to implement the semantics for their own command line options.
java.lang.Throwable
defineOptions()
,
http://commons.apache.org/cli/usage.html
protected boolean isHelpNeeded(org.apache.commons.cli.CommandLine commandLine)
true
if command line usage help needs to be printed, false
otherwise.protected void printHelp()
protected java.lang.Object handleError(java.lang.Throwable throwable)
application
is run.throwable
- The exception
describing the error that has occurred.