use of de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters.StringParameter in project elki by elki-project.
the class LoggingTabPanel method configureStep.
@Override
protected synchronized void configureStep(Parameterization config) {
StringParameter debugParam = //
new StringParameter(AbstractApplication.Parameterizer.DEBUG_ID).setOptional(true);
Flag verboseFlag = new Flag(AbstractApplication.Parameterizer.VERBOSE_ID);
// Verbose mode is a lot simpler
if (config.grab(verboseFlag) && verboseFlag.isTrue()) {
LoggingConfiguration.setVerbose(Level.VERBOSE);
}
// FIXME: add second level of verbosity!
if (config.grab(debugParam)) {
try {
AbstractApplication.Parameterizer.parseDebugParameter(debugParam);
} catch (WrongParameterValueException e) {
de.lmu.ifi.dbs.elki.logging.LoggingUtil.exception(e);
}
}
}
use of de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters.StringParameter in project elki by elki-project.
the class AbstractApplication method runCLIApplication.
/**
* Generic command line invocation.
*
* Refactored to have a central place for outermost exception handling.
*
* @param cls Application class to run.
* @param args the arguments to run this application with
*/
public static void runCLIApplication(Class<?> cls, String[] args) {
SerializedParameterization params = new SerializedParameterization(args);
Flag helpF = new Flag(Parameterizer.HELP_ID);
params.grab(helpF);
Flag helpLongF = new Flag(Parameterizer.HELP_LONG_ID);
params.grab(helpLongF);
try {
ClassParameter<Object> descriptionP = new ClassParameter<>(Parameterizer.DESCRIPTION_ID, Object.class, true);
params.grab(descriptionP);
if (descriptionP.isDefined()) {
params.clearErrors();
printDescription(descriptionP.getValue());
System.exit(1);
}
// Parse debug parameter
StringParameter debugP = new StringParameter(Parameterizer.DEBUG_ID).setOptional(true);
params.grab(debugP);
if (debugP.isDefined()) {
Parameterizer.parseDebugParameter(debugP);
}
// Fail silently on errors.
if (params.getErrors().size() > 0) {
params.logAndClearReportedErrors();
System.exit(1);
}
} catch (Exception e) {
printErrorMessage(e);
System.exit(1);
}
try {
TrackParameters config = new TrackParameters(params);
Flag verboseF = new Flag(Parameterizer.VERBOSE_ID);
if (config.grab(verboseF) && verboseF.isTrue()) {
// Extra verbosity by repeating the flag:
Flag verbose2F = new Flag(Parameterizer.VERBOSE_ID);
LoggingConfiguration.setVerbose((config.grab(verbose2F) && verbose2F.isTrue()) ? Level.VERYVERBOSE : Level.VERBOSE);
}
AbstractApplication task = ClassGenericsUtil.tryInstantiate(AbstractApplication.class, cls, config);
if ((helpF.isDefined() && helpF.getValue()) || (helpLongF.isDefined() && helpLongF.getValue())) {
LoggingConfiguration.setVerbose(Level.VERBOSE);
LOG.verbose(usage(config.getAllParameters()));
System.exit(1);
}
if (params.getErrors().size() > 0) {
LoggingConfiguration.setVerbose(Level.VERBOSE);
LOG.verbose("ERROR: The following configuration errors prevented execution:");
for (ParameterException e : params.getErrors()) {
LOG.verbose(e.getMessage());
LOG.verbose("\n");
}
params.logUnusedParameters();
LOG.verbose("Stopping execution because of configuration errors above.");
System.exit(1);
}
params.logUnusedParameters();
task.run();
} catch (Exception e) {
printErrorMessage(e);
}
}
Aggregations