ShowOfflineModelsCommand extends AbstractCommand { public static ShowOfflineModelsCommand parse(String cmd, ExecutionContext ctx) throws ODPSConsoleException { if (cmd == null || ctx == null) { return null; } Matcher matcher = PATTERN.matcher(cmd); if (!matcher.matches()) { return null; } String input = matcher.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 + "Invalid command."); } String modelNamePrefix = null; if (commandLine.getArgList().size() == 1) { modelNamePrefix = commandLine.getArgs()[0]; if (!modelNamePrefix.matches("[.\\w]+")) { throw new ODPSConsoleException(ODPSConsoleConstants.BAD_COMMAND + "Invalid model prefix."); } } if (projectName == null) { projectName = ctx.getProjectName(); } ShowOfflineModelsCommand command = new ShowOfflineModelsCommand(projectName, modelNamePrefix, cmd, ctx); return command; } ShowOfflineModelsCommand(String projectName, String modelNamePrefix, String cmd, ExecutionContext ctx); static void printUsage(PrintStream stream); @Override void run(); static ShowOfflineModelsCommand parse(String cmd, ExecutionContext ctx); static final String[] HELP_TAGS; }
@Test public void testShowOffLineModelsInvalidFilter() throws ODPSConsoleException, OdpsException { ExecutionContext context = ExecutionContext.init(); String cmd = "show offlinemodels prefix-error"; expectEx.expect(ODPSConsoleException.class); expectEx.expectMessage(ODPSConsoleConstants.BAD_COMMAND + "Invalid model prefix."); ShowOfflineModelsCommand.parse(cmd, context); }
@Test public void testShowOffLineModelsTooManyParams() throws ODPSConsoleException, OdpsException { ExecutionContext context = ExecutionContext.init(); String cmd = "show offlinemodels a b"; expectEx.expect(ODPSConsoleException.class); expectEx.expectMessage(ODPSConsoleConstants.BAD_COMMAND + "Invalid command."); ShowOfflineModelsCommand.parse(cmd, context); }