public abstract class Command
extends java.lang.Object
Command,
where prefix is IAppConstants.APP_PACKAGE and
name is the canonical Command name;(String, String[]) signature;_usage.res.method.| 限定符和类型 | 字段和说明 |
|---|---|
protected static java.lang.String |
COMMA_DELIMITERS |
protected java.lang.String[] |
m_args |
protected boolean |
m_exit |
protected java.io.PrintWriter |
m_out |
protected java.io.File |
m_propertyFile |
protected java.util.Properties |
m_propertyOverrides |
protected java.lang.String |
m_usageCommandName |
protected static java.lang.String |
PATH_DELIMITERS |
protected static int |
RC_OK |
protected static int |
RC_UNEXPECTED |
protected static int |
RC_USAGE |
protected static int |
STDOUT_WIDTH |
protected static java.lang.String[] |
USAGE_OPT_NAMES |
| 限定符 | 构造器和说明 |
|---|---|
protected |
Command(java.lang.String usageName,
java.lang.String[] args)
A public version of this constructor is called by the Factory method
create(String, String, String[]). |
| 限定符和类型 | 方法和说明 |
|---|---|
static Command |
create(java.lang.String name,
java.lang.String usageName,
java.lang.String[] args)
Factory method for Commands.
|
protected void |
exit(boolean showBuildID,
java.lang.String msg,
java.lang.Throwable t,
int rc)
A helper method to terminate a Command execution with correct -exit semantics.
|
protected java.lang.String |
getCanonicalCommandName()
Returns this command's canonical name (e.g, runCommand can be mapped to "emma run"
or "emmarun" command line tools but its canonical name is simply "run").
|
protected static java.lang.String[] |
getListOptValue(IOptsParser.IOpt opt,
java.lang.String delimiters,
boolean processAtFiles)
A helper method to convert a command line option to a value list
|
protected static boolean |
getOptionalBooleanOptValue(IOptsParser.IOpt opt)
A helper method to convert a command line option to a boolean.
|
protected IOptsParser |
getOptParser(java.lang.ClassLoader loader)
Loads the options parser associated with this command.
|
protected void |
processCmdPropertyOverrides(IOptsParser.IOpts parsedopts)
This method processes all -D property overrides specified on the command line.
|
protected boolean |
processFilePropertyOverrides()
This method processes the -properties override if it was specified.
|
protected boolean |
processOpt(IOptsParser.IOpt opt)
A helper method for handling a number of options common to all Commands.
|
abstract void |
run()
Implemented by subclasses to handle this command's unit of work and command
line arguments.
|
protected abstract java.lang.String |
usageArgsMsg()
Implemented by actual Command classes to specify the string that
should follow command name prefix when dumping usage.
|
protected void |
usageexit(java.lang.String msg,
IOptsParser parser,
int level)
A helper method to emit usage-related messages before a call to
exit(boolean, String, Throwable, int). |
protected java.lang.String |
usageMsgPrefix()
Returns a prefix used for usage-related error messaging.
|
protected final java.lang.String m_usageCommandName
protected final java.lang.String[] m_args
protected final java.io.PrintWriter m_out
protected java.io.File m_propertyFile
protected java.util.Properties m_propertyOverrides
protected boolean m_exit
protected static final java.lang.String COMMA_DELIMITERS
protected static final java.lang.String PATH_DELIMITERS
protected static final java.lang.String[] USAGE_OPT_NAMES
protected static final int STDOUT_WIDTH
protected static final int RC_OK
protected static final int RC_USAGE
protected static final int RC_UNEXPECTED
protected Command(java.lang.String usageName,
java.lang.String[] args)
create(String, String, String[]).
Subclasses must keep this constructor signature and make it public.public static Command create(java.lang.String name, java.lang.String usageName, java.lang.String[] args)
name - canonical command name [may not be null or empty]usageName - command's usage (as seen on the command line) name [may not be null or empty]args - command's command line args [null is equivalent to an empty array]run.EMMARuntimeException - if a Command with canonical name 'name' could not be instantiatedpublic abstract void run()
exit(boolean, String, Throwable, int).protected abstract java.lang.String usageArgsMsg()
protected final java.lang.String getCanonicalCommandName()
protected final java.lang.String usageMsgPrefix()
protected final IOptsParser getOptParser(java.lang.ClassLoader loader)
loader - classloader to use for loading the usage resource [may not be null]protected final boolean processOpt(IOptsParser.IOpt opt)
opt - option to handle [may not be null]protected final void processCmdPropertyOverrides(IOptsParser.IOpts parsedopts)
processFilePropertyOverrides().parsedopts - [may not be null]protected final boolean processFilePropertyOverrides()
processOpt(IOptsParser.IOpt), because that will ensure that
m_propertyFile has been set (otherwise, this method is a no-op). To
ensure that file overrides have lower priority than named property overrides,
this method should be called after processCmdPropertyOverrides(IOptsParser.IOpts).
This method calls exit(boolean, String, Throwable, int) on any file I/O error.
protected final void usageexit(java.lang.String msg,
IOptsParser parser,
int level)
exit(boolean, String, Throwable, int).msg - message to precede detailed usage text [if null, no such message is emitted]parser - options parser instance used to emit detailed usage text [if null, no text is emitted]level - usage text detail level [@see IOptsParser#usage(PrintWriter, int, int)]protected final void exit(boolean showBuildID,
java.lang.String msg,
java.lang.Throwable t,
int rc)
throws EMMARuntimeException
m_exit setting.showBuildID - flag to indicate that pre-exit message should be prefixed with IAppConstants.APP_USAGE_BUILD_IDmsg - message to precede exit exception stack traces, if any [ignored if null]t - exit exception [ignored if null, will be wrapped in an EMMARuntimeException if not an instance of that already]rc - one of RC_xxx constantsEMMARuntimeExceptionprotected static boolean getOptionalBooleanOptValue(IOptsParser.IOpt opt)
opt - [may not be null]Property.toBoolean(String).protected static java.lang.String[] getListOptValue(IOptsParser.IOpt opt, java.lang.String delimiters, boolean processAtFiles) throws java.io.IOException
opt - [may not be null]delimiters - [@see Strings#mergeAT(String[], String, boolean)]processAtFiles - [@see Strings#mergeAT(String[], String, boolean)]java.io.IOException - on any at-file I/O errorsCopyright © 2018. All Rights Reserved.