xapi.args.ArgHandlerLogLevel Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of xapi-dev Show documentation
Show all versions of xapi-dev Show documentation
Everything needed to run a comprehensive dev environment.
Just type X_ and pick a service from autocomplete;
new dev modules will be added as they are built.
The only dev service not included in the uber jar is xapi-dev-maven,
as it includes all runtime dependencies of maven, adding ~4 seconds to build time,
and 6 megabytes to the final output jar size (without xapi-dev-maven, it's ~1MB).
The newest version!
package xapi.args;
import xapi.log.api.LogLevel;
/**
* Argument handler for processing the log level flag.
*
* Based on original implementation from the GWT project.
*
* @author GWT team "gwtproject.org"
* @author James X. Nelson "[email protected]"
*
*/
public class ArgHandlerLogLevel extends ArgHandler {
private static final String OPTIONS_STRING = computeOptionsString();
private static String computeOptionsString() {
StringBuffer sb = new StringBuffer();
LogLevel[] values = LogLevel.values();
for (int i = 0, c = values.length; i < c; ++i) {
if (i > 0) {
sb.append(", ");
}
if (i + 1 == c) {
sb.append("or ");
}
sb.append(values[i].name());
}
return sb.toString();
}
private final OptionLogLevel options;
public ArgHandlerLogLevel(OptionLogLevel options) {
this.options = options;
}
@Override
public String[] getDefaultArgs() {
return new String[] {getTag(), getDefaultLogLevel().name()};
}
@Override
public String getPurpose() {
return "The level of logging detail: " + OPTIONS_STRING;
}
@Override
public String getTag() {
return "-logLevel";
}
@Override
public String[] getTagArgs() {
return new String[] {"level"};
}
@Override
public int handle(String[] args, int startIndex) {
if (startIndex + 1 < args.length) {
try {
LogLevel level = LogLevel.valueOf(args[startIndex + 1]);
options.setLogLevel(level);
return 1;
} catch (IllegalArgumentException e) {
// Argument did not match any enum value; fall through to error case.
}
}
System.err.println(getTag() + " should be followed by one of");
System.err.println(" " + OPTIONS_STRING);
return -1;
}
protected LogLevel getDefaultLogLevel() {
return LogLevel.INFO;
}
}