DescribeOnlineModelCommand extends AbstractCommand { public static DescribeOnlineModelCommand parse(String cmd, ExecutionContext ctx) throws ODPSConsoleException { if (cmd == null || ctx == null) { return null; } Matcher m = PATTERN.matcher(cmd); boolean match = m.matches(); if (!match) { return null; } String input = m.group(2); String[] inputs = new AntlrObject(input).getTokenStringArray(); CommandLine commandLine = getCommandLine(inputs); String projectName = null; if (commandLine.hasOption("p")) { projectName = commandLine.getOptionValue("p"); } if (commandLine.getArgList().size() != 1) { throw new ODPSConsoleException(ODPSConsoleConstants.BAD_COMMAND + "Model name is ambiguous."); } String 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]; } if (projectName == null) { projectName = ctx.getProjectName(); } return new DescribeOnlineModelCommand(projectName, modelName, cmd, ctx); } DescribeOnlineModelCommand(String projectName, String modelName, String cmd,
                                    ExecutionContext ctx); static void printUsage(PrintStream stream); @Override void run(); static void PrintModelInfo(DefaultOutputWriter writer, OnlineModel model); static DescribeOnlineModelCommand parse(String cmd, ExecutionContext ctx); static final String[] HELP_TAGS; }
@Test public void testDescribeOnLineModelMatchNone() throws ODPSConsoleException, OdpsException { ExecutionContext context = ExecutionContext.init(); String cmd = "desc onlinemodel"; DescribeOnlineModelCommand command = DescribeOnlineModelCommand.parse(cmd, context); assertNull(command); }
@Test public void testDescribeOnLineModelConflictPrjName() throws ODPSConsoleException, OdpsException { ExecutionContext context = ExecutionContext.init(); String cmd = "desc onlinemodel -p prj1 prj2.model"; expectEx.expect(ODPSConsoleException.class); expectEx.expectMessage(ODPSConsoleConstants.BAD_COMMAND + "Project name conflict."); DescribeOnlineModelCommand.parse(cmd, context); }
@Test public void testDescribeOnLineModelNoModel() throws ODPSConsoleException, OdpsException { ExecutionContext context = ExecutionContext.init(); String cmd = "desc onlinemodel -p prj "; expectEx.expect(ODPSConsoleException.class); expectEx.expectMessage(ODPSConsoleConstants.BAD_COMMAND + "Model name is ambiguous."); DescribeOnlineModelCommand.parse(cmd, context); }
@Test public void testDescribeOnLineModelInvalidModelName() throws ODPSConsoleException, OdpsException { ExecutionContext context = ExecutionContext.init(); String cmd = "desc onlinemodel model-error"; expectEx.expect(ODPSConsoleException.class); expectEx.expectMessage(ODPSConsoleConstants.BAD_COMMAND + "Invalid model name."); DescribeOnlineModelCommand.parse(cmd, context); }