public abstract class Command extends Object
Command,
where prefix is IAppConstants.APP_PACKAGE and
name is the canonical Command name;(String, String[]) signature;_usage.res.method.| 限定符和类型 | 字段和说明 |
|---|---|
protected static String |
COMMA_DELIMITERS |
protected String[] |
m_args |
protected boolean |
m_exit |
protected PrintWriter |
m_out |
protected File |
m_propertyFile |
protected Properties |
m_propertyOverrides |
protected String |
m_usageCommandName |
protected static 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 String[] |
USAGE_OPT_NAMES |
| 限定符 | 构造器和说明 |
|---|---|
protected |
Command(String usageName,
String[] args)
A public version of this constructor is called by the Factory method
create(String, String, String[]). |
| 限定符和类型 | 方法和说明 |
|---|---|
static Command |
create(String name,
String usageName,
String[] args)
Factory method for Commands.
|
protected void |
exit(boolean showBuildID,
String msg,
Throwable t,
int rc)
A helper method to terminate a Command execution with correct -exit semantics.
|
protected 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 String[] |
getListOptValue(IOptsParser.IOpt opt,
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(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 String |
usageArgsMsg()
Implemented by actual Command classes to specify the string that
should follow command name prefix when dumping usage.
|
protected void |
usageexit(String msg,
IOptsParser parser,
int level)
A helper method to emit usage-related messages before a call to
exit(boolean, String, Throwable, int). |
protected String |
usageMsgPrefix()
Returns a prefix used for usage-related error messaging.
|
protected final String m_usageCommandName
protected final String[] m_args
protected final PrintWriter m_out
protected File m_propertyFile
protected Properties m_propertyOverrides
protected boolean m_exit
protected static final String PATH_DELIMITERS
protected static final 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(String usageName, String[] args)
create(String, String, String[]).
Subclasses must keep this constructor signature and make it public.public static Command create(String name, String usageName, 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 String usageArgsMsg()
protected final String getCanonicalCommandName()
protected final String usageMsgPrefix()
protected final IOptsParser getOptParser(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(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,
String msg,
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 String[] getListOptValue(IOptsParser.IOpt opt, String delimiters, boolean processAtFiles) throws IOException
opt - [may not be null]delimiters - [@see Strings#mergeAT(String[], String, boolean)]processAtFiles - [@see Strings#mergeAT(String[], String, boolean)]IOException - on any at-file I/O errorsCopyright © 2018. All rights reserved.