in odps-console-xflow/src/main/java/com/aliyun/openservices/odps/console/xflow/ReadOfflineModelCommand.java [130:192]
public static ReadOfflineModelCommand parse(String cmd, ExecutionContext ctx)
throws ODPSConsoleException {
if (cmd == null || ctx == null) {
return null;
}
Matcher m = PATTERN.matcher(cmd);
if (!m.matches()) {
return null;
}
String input = m.group(1);
String[] inputs = new AntlrObject(input).getTokenStringArray();
CommandLine commandLine = getCommandLine(inputs);
// get -p option if exist
String projectName = null;
if (commandLine.hasOption("p")) {
projectName = commandLine.getOptionValue("p");
}
int argSize = commandLine.getArgList().size();
if (argSize != 1 && argSize != 3) {
throw new ODPSConsoleException(ODPSConsoleConstants.BAD_COMMAND + "Model name not found.");
}
String modelName = null;
// read offlinemodel model_name
modelName = commandLine.getArgs()[0];
if (!modelName.matches("[.\\w]+")) {
throw new ODPSConsoleException(ODPSConsoleConstants.BAD_COMMAND + "Invalid model name.");
}
if (modelName.contains(".")) {
String[] result = modelName.split("\\.", 2);
if (projectName != null && (!result[0].equals(projectName))) {
throw new ODPSConsoleException(ODPSConsoleConstants.BAD_COMMAND + "Project name conflict.");
}
projectName = result[0];
modelName = result[1];
}
String volumeName = null;
String partitionName = null;
if (commandLine.getArgList().size() == 3) {
// read offlinemodel model_name as volume_name
if (commandLine.getArgs()[1].toUpperCase().compareTo("AS") != 0) {
throw new ODPSConsoleException(ODPSConsoleConstants.BAD_COMMAND + "Invalid command.");
}
volumeName = commandLine.getArgs()[2];
if (volumeName.contains(".")) {
String[] result = volumeName.split("\\.", 2);
volumeName = result[0];
partitionName = result[1];
}
}
if (projectName == null) {
projectName = ctx.getProjectName();
}
return new ReadOfflineModelCommand(projectName, modelName, volumeName, partitionName, cmd, ctx);
}