in odps-console-public/src/main/java/com/aliyun/openservices/odps/console/pub/TopInstanceCommand.java [291:365]
public static TopInstanceCommand parse(String commandString, ExecutionContext sessionContext)
throws ODPSConsoleException {
Matcher matcher = PATTERN.matcher(commandString);
String projectName = null;
Integer delay = null;
Boolean onlyOwner = null;
Integer number = null;
Instance.Status status = null;
if (matcher.matches()) {
if (!StringUtils.isNullOrEmpty(matcher.group(3))) {
CommandLine commandLine = getCommandLine(matcher.group(3));
if (!commandLine.getArgList().isEmpty()) {
throw new ODPSConsoleException(
ODPSConsoleConstants.BAD_COMMAND + "[too much parameters.]");
}
if (commandLine.hasOption(PROJECT_TAG)) {
projectName = commandLine.getOptionValue(PROJECT_TAG);
}
if (commandLine.hasOption(STATUS_TAG)) {
try {
status = Instance.Status.valueOf(commandLine.getOptionValue(STATUS_TAG).toUpperCase());
} catch (IllegalArgumentException e) {
throw new ODPSConsoleException(
ODPSConsoleConstants.BAD_COMMAND + "[bad status value.]");
}
}
if (commandLine.hasOption(LIMIT_TAG)) {
String val = commandLine.getOptionValue(LIMIT_TAG);
if (org.apache.commons.lang.StringUtils.isNumeric(val)) {
number = Integer.parseInt(val);
if (number <= 0) {
throw new ODPSConsoleException(ODPSConsoleConstants.BAD_COMMAND
+ "[bad limit value, limit number should bigger than zero.]");
}
} else {
throw new ODPSConsoleException(ODPSConsoleConstants.BAD_COMMAND + "[bad limit value.]");
}
}
if (commandLine.hasOption(DELAY_TAG)) {
String val = commandLine.getOptionValue(DELAY_TAG);
if (StringUtils.isNullOrEmpty(val)) {
delay = DEFAULT_DELAY;
} else if (org.apache.commons.lang.StringUtils.isNumeric(val)
&& Integer.parseInt(val) > 0) {
delay = Integer.parseInt(val);
} else {
throw new ODPSConsoleException(ODPSConsoleConstants.BAD_COMMAND + "[bad delay value.]");
}
}
if (commandLine.hasOption(ALL_TAG)) {
onlyOwner = false;
}
}
TopInstanceCommand
command =
new TopInstanceCommand(projectName, commandString, sessionContext);
command.setOnlyOwner(onlyOwner);
command.setStatus(status);
command.setDelay(delay);
command.setNubmer(number);
return command;
}
return null;
}