private void initCmdInterface(String[] completionPrefixes, History history) throws IOException { completionPrefixes = completionPrefixes == null ? getCompletionPrefixes() : completionPrefixes; cmdInterface = new CLICommandInterface(ctx); for (String s : completionPrefixes) { cmdInterface.addPrefix(s); } cmdInterface.addPrefix("org.jpos.q2.cli.builtin."); if (terminal != null) { reader = buildReader(terminal, completionPrefixes, history); ctx.setReader(reader); } }
String n = st.nextToken().replace (ESCAPED_SEMICOLON, ";"); try { String[] args = cmdInterface.parseCommand(n); if (args.length > 0 && args[0].contains(":")) { String prefixCommand = args[0].substring(0, args[0].indexOf(":")); cmdInterface.execCommand(prefixCommand); n = n.substring(prefixCommand.length() + 1); exit = true; cmdInterface.execCommand(n); } catch (IOException e) { ctx.printThrowable(e); if (exit) { try { cmdInterface.execCommand("exit"); } catch (IOException e) { ctx.printThrowable(e);
@Test public void testparseCommand_DoubleQuotesArmuredArgWithoutSpacesWithin() throws IOException { String line = "arg1 \"arg2\" arg3"; String[] args = cliCommandInterface.parseCommand(line); assertThat(Arrays.asList(args)) .containsSequence("arg1", "arg2", "arg3"); }
public void execCommand(String line) throws IOException { String args[] = parseCommand(line); if (args.length == 0) { return; Object cmd = getCommand(className); if (cmd != null) { try {
@Before public void setUp() { CLIContext ctx = mock(CLIContext.class); cliCommandInterface = new CLICommandInterface(ctx); }
@Test public void testparseCommand_NoQuotes() throws IOException { String line = "arg1 arg2 arg3"; String[] args = cliCommandInterface.parseCommand(line); assertThat(Arrays.asList(args)) .containsSequence("arg1", "arg2", "arg3"); }
@Test public void testparseCommand_SimpleQuotesArmuredArgWithSpacesWithin() throws IOException { String line = "arg1 'arg2 with spaces within' arg3"; String[] args = cliCommandInterface.parseCommand(line); assertThat(Arrays.asList(args)).containsSequence("arg1", "arg2 with spaces within", "arg3"); }
@Test public void testparseCommand_SimpleQuotesArmuredArgWithSpacesAndDoubleQuotesWithin() throws IOException { String line = "arg1 'arg2 with spaces and \"double quotes\" within' arg3"; String[] args = cliCommandInterface.parseCommand(line); assertThat(Arrays.asList(args)).containsSequence("arg1", "arg2 with spaces and \"double quotes\" within", "arg3"); }
@Test public void testparseCommand_DoubleQuotesArmuredEmptyArg() throws IOException { String line = "arg1 \"\" arg3"; String[] args = cliCommandInterface.parseCommand(line); assertThat(Arrays.asList(args)) .containsSequence("arg1", "", "arg3"); }
@Test public void testparseCommand_DoubleQuotesArmuredArgWithSpacesAndSimplequotesWithin() throws IOException { String line = "arg1 \"arg2 with spaces and 'simple quotes' within\" arg3"; String[] args = cliCommandInterface.parseCommand(line); assertThat(Arrays.asList(args)).containsSequence("arg1", "arg2 with spaces and 'simple quotes' within", "arg3"); }
@Test public void testparseCommand_SimpleQuotesArmuredArgWithoutSpaceWithin() throws IOException { String line = "arg1 'arg2' arg3"; String[] args = cliCommandInterface.parseCommand(line); assertThat(Arrays.asList(args)) .containsSequence("arg1", "arg2", "arg3"); }
@Test public void testparseCommand_DoubleQuotesArmuredArgWithSpacesWithin() throws IOException { String line = "arg1 \"arg2 with spaces within\" arg3"; String[] args = cliCommandInterface.parseCommand(line); assertThat(Arrays.asList(args)).containsSequence("arg1", "arg2 with spaces within", "arg3"); }
@Test public void testparseCommand_SimpleQuotesArmuredEmptyArg() throws IOException { String line = "arg1 '' arg3"; String[] args = cliCommandInterface.parseCommand(line); assertThat(Arrays.asList(args)) .containsSequence("arg1", "", "arg3"); }
@Test public void testparseCommand_LineContainsSpacesOnly() throws IOException { String line = " "; String[] args = cliCommandInterface.parseCommand(line); assertThat(args).isEmpty(); }
@Test public void testparseCommand_LineIsNull() throws IOException { String[] args = cliCommandInterface.parseCommand(null); assertThat(args).isEmpty(); }