public abstract class CLI extends Object
| Modifier and Type | Class and Description |
|---|---|
static class |
CLI.Argument
For defining command line arguments that are not prefixed by the option
syntax.
|
| Modifier | Constructor and Description |
|---|---|
protected |
CLI()
Instantiates this application.
|
protected |
CLI(CLI.Argument[] arguments)
Instantiates the application with optional arguments.
|
protected |
CLI(CLI.Argument[] arguments,
boolean configurationIdEnabled)
Instantiates the application with a required shell command name and
whether to create the configuration id option.
|
protected |
CLI(String shellCommand)
Instantiates the application with a required shell command name.
|
protected |
CLI(String shellCommand,
CLI.Argument[] arguments)
Instantiates the application with a required shell command name and
optional arguments that are not prefixed with option syntax.
|
protected |
CLI(String shellCommand,
CLI.Argument[] arguments,
boolean configurationIdEnabled)
Instantiates the application with a required shell command name,
optional arguments that are not prefixed with option syntax, and
whether to create the configuration id option.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
addCustomCliOptions(org.apache.commons.cli.Options options)
Override to specify any custom command line options.
|
void |
close()
Closes the instance of
Protempa created by
#initialize(java.lang.String). |
void |
execute()
Calls the code in
execute(org.protempa.Protempa, org.apache.commons.cli.CommandLine). |
void |
execute(Protempa protempa,
org.apache.commons.cli.CommandLine commandLine)
Implemented with whatever is done with the instance of PROTEMPA
created with
#initialize(java.lang.String), and processing of
any arguments and command line options specified in
addCustomCliOptions(org.apache.commons.cli.Options). |
CLI.Argument[] |
getArguments()
Gets optional arguments that are not prefixed with option syntax.
|
String |
getShellCommand()
Gets the shell command.
|
void |
initialize()
Initializes PROTEMPA with the specified configuration.
|
void |
initializeExecuteAndClose()
|
boolean |
isConfigurationIdEnabled()
Whether the configuration option will be created.
|
void |
printException(Exception cliException)
Prints to the console an exception's message and its nested exception's
message (if any).
|
org.apache.commons.cli.CommandLine |
processOptionsAndArgs(String[] args)
Processes command line options.
|
protected CLI()
app.name
must be set to the shell command name.protected CLI(String shellCommand)
shellCommand - a String, cannot be null or
empty.protected CLI(CLI.Argument[] arguments)
app.name must be set to the shell command name.arguments - the command line arguments for this application. May
be null or empty.protected CLI(String shellCommand, CLI.Argument[] arguments)
addCustomCliOptions(org.apache.commons.cli.Options).shellCommand - a String, cannot be null or
empty.arguments - an Argument[].protected CLI(CLI.Argument[] arguments, boolean configurationIdEnabled)
true by default, and normally would be unless PROTEMPA
would not be initialized by the program for some reason.
To add options, override
addCustomCliOptions(org.apache.commons.cli.Options).arguments - an Argument[].configurationIdEnabled - whether or not the configuration id option
should be created.protected CLI(String shellCommand, CLI.Argument[] arguments, boolean configurationIdEnabled)
true by default, and normally would be unless PROTEMPA
would not be initialized by the program for some reason.
To add options, override
addCustomCliOptions(org.apache.commons.cli.Options).shellCommand - a String, cannot be null or
empty.arguments - an Argument[].configurationIdEnabled - whether or not the configuration id option
should be created.public final CLI.Argument[] getArguments()
Argument[]. Guaranteed not null.public final boolean isConfigurationIdEnabled()
true unless otherwise specified, and must be
true if initialize() will be called.true or false.public final void initialize()
throws ProtempaStartupException
#processArgs(java.lang.String[], int, int) .configurationId - the id String of a configuration.ProtempaStartupException - if an error occurred starting up
PROTEMPA.public void execute(Protempa protempa, org.apache.commons.cli.CommandLine commandLine) throws CLIException
#initialize(java.lang.String), and processing of
any arguments and command line options specified in
addCustomCliOptions(org.apache.commons.cli.Options). The
default implementation is a no-op.protempa - an instance of Protempa.commandLine - the CommandLine options passed in by the
caller.CLIException - if some exception was thrown by the implementation
of this method. The convention is for any such exceptions to be nested
in an instance of CLIException.public final void printException(Exception cliException)
cliException - the Exception to print.public final void execute()
throws CLIException
execute(org.protempa.Protempa, org.apache.commons.cli.CommandLine).CLIException - if
execute(org.protempa.Protempa, org.apache.commons.cli.CommandLine)
throws an exception.public final void close()
throws CloseException
Protempa created by
#initialize(java.lang.String).CloseExceptionpublic final org.apache.commons.cli.CommandLine processOptionsAndArgs(String[] args)
addCustomCliOptions(org.apache.commons.cli.Options) should be
handled by
execute(org.protempa.Protempa, org.apache.commons.cli.CommandLine).
There always must be at least one argument for the configuration id.args - the argument String[] passed into main.CommandLine instance.public final void initializeExecuteAndClose()
protected void addCustomCliOptions(org.apache.commons.cli.Options options)
options - the command line Options.Copyright © 2012–2018 Emory University. All rights reserved.