@Test public void testCompletionWithStaticOptions() throws Exception { TestConnection connection = new TestConnection(false); DynCommand1 cmd = new DynCommand1(); DynamicOptionsProvider provider = new DynamicOptionsProvider(); MapProcessedCommandBuilder builder = MapProcessedCommandBuilder.builder(); builder.command(cmd); builder.lookupAtCompletionOnly(true); builder.name("dyn1"); { ProcessedOptionBuilder optBuilder = ProcessedOptionBuilder.builder(); optBuilder.name("verbose"); optBuilder.hasValue(false); optBuilder.type(Boolean.class); builder.addOption(optBuilder.build()); } { ProcessedOptionBuilder optBuilder = ProcessedOptionBuilder.builder(); optBuilder.name("dir"); optBuilder.hasValue(true); optBuilder.type(String.class); builder.addOption(optBuilder.build()); } builder.optionProvider(provider); CommandRegistry registry = AeshCommandRegistryBuilder.builder() .command(builder.create()) .create(); Settings settings = SettingsBuilder.builder() .logging(true) .connection(connection) .commandRegistry(registry) .build(); ReadlineConsole console = new ReadlineConsole(settings); console.setPrompt(new Prompt("")); console.start(); connection.clearOutputBuffer(); connection.read("d"); connection.read(completeChar.getFirstValue()); assertEquals("dyn1 ", connection.getOutputBuffer()); connection.read(completeChar.getFirstValue()); assertEquals("dyn1 --", connection.getOutputBuffer()); connection.read("v"); connection.read(completeChar.getFirstValue()); assertEquals("dyn1 --verbose ", connection.getOutputBuffer()); connection.read("--"); connection.read(completeChar.getFirstValue()); assertEquals("dyn1 --verbose --dir=", connection.getOutputBuffer()); connection.read("toto"); connection.read(Config.getLineSeparator()); connection.clearOutputBuffer(); Thread.sleep(200); { String val = (String) cmd.options.get("dir"); assertEquals("toto", val); } assertTrue(cmd.contains("verbose")); provider.options = getOptions(); connection.read("dyn1 --verbose"); connection.read(completeChar.getFirstValue()); assertEquals("dyn1 --verbose ", connection.getOutputBuffer()); connection.read(completeChar.getFirstValue()); assertEquals("dyn1 --verbose --", connection.getOutputBuffer()); connection.read("opt-dyn1"); connection.read(completeChar.getFirstValue()); assertEquals("dyn1 --verbose --opt-dyn1-withvalue=", connection.getOutputBuffer()); connection.read("xxx "); connection.read(completeChar.getFirstValue()); assertEquals("dyn1 --verbose --opt-dyn1-withvalue=xxx --", connection.getOutputBuffer()); connection.read("d"); connection.read(completeChar.getFirstValue()); assertEquals("dyn1 --verbose --opt-dyn1-withvalue=xxx --dir=", connection.getOutputBuffer()); connection.read("tutu "); connection.read(completeChar.getFirstValue()); assertEquals("dyn1 --verbose --opt-dyn1-withvalue=xxx --dir=tutu --opt-dyn", connection.getOutputBuffer()); connection.read("2-withvalue=yyy --"); connection.read(completeChar.getFirstValue()); assertEquals("dyn1 --verbose --opt-dyn1-withvalue=xxx --dir=tutu --opt-dyn2-withvalue=yyy --opt-dyn3-novalue ", connection.getOutputBuffer()); connection.read(Config.getLineSeparator()); connection.clearOutputBuffer(); Thread.sleep(200); { String val = (String) cmd.options.get("dir"); assertEquals("tutu", val); } { String val = (String) cmd.options.get("opt-dyn1-withvalue"); assertEquals("xxx", val); } { String val = (String) cmd.options.get("opt-dyn2-withvalue"); assertEquals("yyy", val); } assertTrue(cmd.contains("verbose")); assertTrue(cmd.contains("opt-dyn3-novalue")); }
public boolean contains(String name) { return values.containsKey(name); }
MapCommand implements Command<T> { public boolean contains(String name) { return values.containsKey(name); } }
MapCommand implements Command<T> { public boolean contains(String name) { return values.containsKey(name); }  }
MapCommand implements Command<T> { public boolean contains(String name) { return values.containsKey(name); }  Object getValue(String name); void setValue(String name, Object value); void resetValue(String name); boolean contains(String name); Map<String, Object> getValues(); boolean checkForRequiredOptions(ParsedLine pl); }
MapCommand implements Command<T> { public boolean contains(String name) { return values.containsKey(name); }  Object getValue(String name); void setValue(String name, Object value); void resetValue(String name); boolean contains(String name); Map<String, Object> getValues(); boolean checkForRequiredOptions(ParsedLine pl);  }