DescribeResourceCommand extends AbstractCommand { public static DescribeResourceCommand 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 + " Invalid resource name."); } String resourceName = commandLine.getArgs()[0]; if (resourceName.contains(":")) { String[] result = resourceName.split(":", 2); if (projectName != null && (!result[0].equals(projectName))) { throw new ODPSConsoleException(ODPSConsoleConstants.BAD_COMMAND + " project name conflict."); } projectName = result[0]; resourceName = result[1]; } if (projectName == null) { projectName = ctx.getProjectName(); } return new DescribeResourceCommand(resourceName, projectName, cmd, ctx); } DescribeResourceCommand(String resourceName, String projectName, String cmd,
                                 ExecutionContext ctx); static void printUsage(PrintStream stream); @Override void run(); static DescribeResourceCommand parse(String cmd, ExecutionContext ctx); static final String[] HELP_TAGS; }
@Test public void postive() throws ODPSConsoleException, OdpsException { for (String cmd : positives) { cmd = cmd.replaceAll("\\*", odps.getDefaultProject()); System.out.println(cmd); AbstractCommand command = DescribeResourceCommand.parse(cmd, context); assertTrue(cmd, command instanceof DescribeResourceCommand); command.execute(); } }
@Test public void negative() throws Exception { int count = 0; for (String cmd : negatives) { cmd = cmd.replaceAll("\\*", odps.getDefaultProject()); System.out.println(cmd); try { AbstractCommand command = DescribeResourceCommand.parse(cmd, context); } catch (ODPSConsoleException e) { count ++; } } assertEquals(negatives.length, count); }