*
* @param cls Application class to run.
* @param args the arguments to run this application with
*/
public static void runCLIApplication(Class<?> cls, String[] args) {
final Flag HELP_FLAG = new Flag(OptionID.HELP);
final Flag HELP_LONG_FLAG = new Flag(OptionID.HELP_LONG);
final ClassParameter<Object> DESCRIPTION_PARAM = new ClassParameter<Object>(OptionID.DESCRIPTION, Object.class, true);
final StringParameter DEBUG_PARAM = new StringParameter(OptionID.DEBUG, true);
SerializedParameterization params = new SerializedParameterization(args);
try {
params.grab(HELP_FLAG);
params.grab(HELP_LONG_FLAG);
params.grab(DESCRIPTION_PARAM);
params.grab(DEBUG_PARAM);
if(DESCRIPTION_PARAM.isDefined()) {
params.clearErrors();
printDescription(DESCRIPTION_PARAM.getValue());
return;
}
// Fail silently on errors.
if(params.getErrors().size() > 0) {
params.logAndClearReportedErrors();
return;
}
if(DEBUG_PARAM.isDefined()) {
LoggingUtil.parseDebugParameter(DEBUG_PARAM);
}
}
catch(Exception e) {
printErrorMessage(e);
return;
}
try {
TrackParameters config = new TrackParameters(params);
AbstractApplication task = ClassGenericsUtil.tryInstantiate(AbstractApplication.class, cls, config);
if((HELP_FLAG.isDefined() && HELP_FLAG.getValue()) || (HELP_LONG_FLAG.isDefined() && HELP_LONG_FLAG.getValue())) {
LoggingConfiguration.setVerbose(true);
STATIC_LOGGER.verbose(usage(config.getAllParameters()));
}
else {
params.logUnusedParameters();