@Test public void testparseCommand_LineContainsSpacesOnly() throws IOException { String line = " "; String[] args = cliCommandInterface.parseCommand(line); assertThat(args).isEmpty(); }
public String[] parseCommand(String line) throws IOException { if (line == null) { return new String[0]; } List<String> matchList = new ArrayList<String>(); Pattern regex = Pattern.compile("[^\\s\"']+|\"([^\"]*)\"|'([^']*)'"); Matcher regexMatcher = regex.matcher(line); while (regexMatcher.find()) { if (regexMatcher.group(1) != null) { matchList.add(regexMatcher.group(1)); } else if (regexMatcher.group(2) != null) { matchList.add(regexMatcher.group(2)); } else { matchList.add(regexMatcher.group()); } } String[] args = new String[matchList.size()]; matchList.toArray(args); return args; }
CLICommandInterface { public String[] parseCommand(String line) throws IOException { if (line == null) { return new String[0]; } List<String> matchList = new ArrayList<String>(); Pattern regex = Pattern.compile("[^\\s\"']+|\"([^\"]*)\"|'([^']*)'"); Matcher regexMatcher = regex.matcher(line); while (regexMatcher.find()) { if (regexMatcher.group(1) != null) { matchList.add(regexMatcher.group(1)); } else if (regexMatcher.group(2) != null) { matchList.add(regexMatcher.group(2)); } else { matchList.add(regexMatcher.group()); } } String[] args = new String[matchList.size()]; matchList.toArray(args); return args; } }
CLICommandInterface { public String[] parseCommand(String line) throws IOException { if (line == null) { return new String[0]; } List<String> matchList = new ArrayList<String>(); Pattern regex = Pattern.compile("[^\\s\"']+|\"([^\"]*)\"|'([^']*)'"); Matcher regexMatcher = regex.matcher(line); while (regexMatcher.find()) { if (regexMatcher.group(1) != null) { matchList.add(regexMatcher.group(1)); } else if (regexMatcher.group(2) != null) { matchList.add(regexMatcher.group(2)); } else { matchList.add(regexMatcher.group()); } } String[] args = new String[matchList.size()]; matchList.toArray(args); return args; } CLICommandInterface(CLIContext ctx); }
CLICommandInterface { public String[] parseCommand(String line) throws IOException { if (line == null) { return new String[0]; } List<String> matchList = new ArrayList<String>(); Pattern regex = Pattern.compile("[^\\s\"']+|\"([^\"]*)\"|'([^']*)'"); Matcher regexMatcher = regex.matcher(line); while (regexMatcher.find()) { if (regexMatcher.group(1) != null) { matchList.add(regexMatcher.group(1)); } else if (regexMatcher.group(2) != null) { matchList.add(regexMatcher.group(2)); } else { matchList.add(regexMatcher.group()); } } String[] args = new String[matchList.size()]; matchList.toArray(args); return args; } CLICommandInterface(CLIContext ctx); List<String> getPrefixes(); void addPrefix(String prefix); void execCommand(String line); String[] parseCommand(String line); }
CLICommandInterface { public String[] parseCommand(String line) throws IOException { if (line == null) { return new String[0]; } List<String> matchList = new ArrayList<String>(); Pattern regex = Pattern.compile("[^\\s\"']+|\"([^\"]*)\"|'([^']*)'"); Matcher regexMatcher = regex.matcher(line); while (regexMatcher.find()) { if (regexMatcher.group(1) != null) { matchList.add(regexMatcher.group(1)); } else if (regexMatcher.group(2) != null) { matchList.add(regexMatcher.group(2)); } else { matchList.add(regexMatcher.group()); } } String[] args = new String[matchList.size()]; matchList.toArray(args); return args; } CLICommandInterface(CLIContext ctx); List<String> getPrefixes(); void addPrefix(String prefix); void execCommand(String line); String[] parseCommand(String line);  }