@Test public void testExecution() throws Exception { TestConnection connection = new TestConnection(false); DynCommand1 cmd = new DynCommand1(); DynamicOptionsProvider provider = new DynamicOptionsProvider(); MapProcessedCommandBuilder builder = MapProcessedCommandBuilder.builder(); builder.command(cmd); builder.lookupAtCompletionOnly(false); 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("dyn1"); connection.read(Config.getLineSeparator()); connection.clearOutputBuffer(); Thread.sleep(200); assertFalse(cmd.contains("verbose")); assertFalse(cmd.contains("dir")); connection.read("dyn1 --verbose"); connection.read(Config.getLineSeparator()); connection.clearOutputBuffer(); Thread.sleep(200); assertTrue(cmd.contains("verbose")); assertFalse(cmd.contains("dir")); connection.read("dyn1 --dir=toto"); connection.read(Config.getLineSeparator()); connection.clearOutputBuffer(); Thread.sleep(200); assertFalse(cmd.contains("verbose")); assertTrue(cmd.contains("dir")); assertFalse(cmd.contains("opt-dyn1-withvalue")); provider.options = getOptions(); connection.read("dyn1 --opt-dyn1-withvalue=foo"); connection.read(Config.getLineSeparator()); connection.clearOutputBuffer(); Thread.sleep(200); assertFalse(cmd.contains("verbose")); assertFalse(cmd.contains("dir")); assertTrue(cmd.contains("opt-dyn1-withvalue")); assertFalse(cmd.contains("opt-dyn2-withvalue")); assertFalse(cmd.contains("opt-dyn3-novalue")); provider.options = getOptionsRequired(); connection.read("dyn1"); connection.read(Config.getLineSeparator()); Thread.sleep(200); assertTrue(connection.getOutputBuffer().contains("Option: --opt-dyn1-required is required for this command")); connection.clearOutputBuffer(); connection.read("dyn1 --opt-dyn1-required=xxx"); connection.read(Config.getLineSeparator()); Thread.sleep(200); assertTrue(connection.getOutputBuffer().contains("Option: --opt-dyn2-required is required for this command")); connection.clearOutputBuffer(); connection.read("dyn1 --opt-dyn1-required=xxx --opt-dyn2-required=yyy"); connection.read(Config.getLineSeparator()); connection.clearOutputBuffer(); Thread.sleep(200); assertTrue(connection.getOutputBuffer(), cmd.contains("opt-dyn1-required")); assertTrue(connection.getOutputBuffer(), cmd.contains("opt-dyn2-required")); assertFalse(cmd.contains("opt-dyn1-withvalue")); assertFalse(cmd.contains("opt-dyn2-withvalue")); assertFalse(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);  }