CommandParserUtils { public static String[] getCommandArgs(String[] args) throws ODPSConsoleException { if (args.length == 2 && args[0].trim().equalsIgnoreCase("-I")) { return getArgsFromTempFile(args[1]); } else { return args; } }  static String[] getCommandTokens(String cmd); static CommandLine getCommandLine(String[] args, Options opts); static CommandLine getCommandLine(String cmd, Options opts); static AbstractCommand parseOptions(String args[], ExecutionContext sessionContext); static void removeHook(List<String> optionList, ExecutionContext sessionContext); static AbstractCommand parseCommand(String commandLines, ExecutionContext sessionContext); static List<PluginPriorityCommand> getExtendedCommandList(); static Set<String> getAllCommandKeyWords(); static List<Completer> getCompleters(); static void printHelpInfo(List<String> keywords); static void loadPlugins(); static Class<? extends AbstractCommand> getClassFromPlugin(String commandName); static String[] getCommandArgs(String[] args);  }
@Test public void testGetCommandArgs() throws ODPSConsoleException { String negative[][] = {{"-G", "23"}, {"-G"}, {"23"}, {"-I"}, {"-i"}, {"-I ", "345", "-e"}, {}}; for (String[] neg : negative) { assertArrayEquals(neg, CommandParserUtils.getCommandArgs(neg)); } String invalidFd[][] = {{"-I ", "A23"}, {"-i \t", "cbd"}}; int count = 0; for (String[] invalid : invalidFd) { try { CommandParserUtils.getCommandArgs(invalid); } catch (ODPSConsoleException e) { count++; assertTrue(e.getCause() instanceof FileNotFoundException); } } assertEquals(count, invalidFd.length); File file = new File("args_test_file"); if (file.exists()) { file.delete(); } try { if (!file.createNewFile()) { throw new IOException(); } String args[] = {"-I", file.getPath()}; assertEquals(0, CommandParserUtils.getCommandArgs(args).length); String expect [] = {"-p", "user", "-u", "password", "--endpoint=http: "--project=test_project", "-e", "select * from dual;\n create table tt(name string); \r\n"}; FileWriter writer = new FileWriter(file); for (String word : expect) { writer.write(" "); writer.write("\0"); writer.write(word); writer.write("\0"); } writer.close(); String args1[] = {"-I", file.getPath()}; assertArrayEquals(expect, CommandParserUtils.getCommandArgs(args1)); } catch (IOException e) { fail(e.getMessage()); } }