GetResourceCommand extends AbstractCommand { public static GetResourceCommand parse(String cmd, ExecutionContext ctx) throws ODPSConsoleException { if (cmd == null || ctx == null) { return null; } Matcher prefix = PATTERN_PREFIX.matcher(cmd); boolean match = prefix.matches(); if (!match) { return null; } Matcher m = PATTERN.matcher(cmd); match = m.matches(); if (!match) { System.err.println("Usage: get resource [<project name>:]<resource name> <path>;"); throw new ODPSConsoleException("Bad command."); } String resourceName = m.group(1); String projectName = ctx.getProjectName(); if (resourceName.contains(":")) { String[] result = resourceName.split(":", 2); projectName = result[0]; resourceName = result[1]; } String path = FileUtil.expandUserHomeInPath(m.group(2)); return new GetResourceCommand(projectName, resourceName, path, cmd, ctx); } GetResourceCommand(String projectName, String resourceName, String path, String cmd,
      ExecutionContext ctx); static void printUsage(PrintStream out); static GetResourceCommand parse(String cmd, ExecutionContext ctx); @Override void run(); static final String[] HELP_TAGS; }
@Test public void testMultiSpaceAfterResourceName() throws ODPSConsoleException { ExecutionContext ctx = ExecutionContext.init(); GetResourceCommand cmd = GetResourceCommand.parse("get resource foo ./bar", ctx); Assert.assertEquals(cmd.resourceName, "foo"); cmd = GetResourceCommand.parse("get resource foo.txt ./bar.txt", ctx); Assert.assertEquals(cmd.resourceName, "foo.txt"); }