public void setProcessor(final CliProcessor processor) { assert processor != null; processor.setStopAtNonOption(true); }
public CliProcessor createProcessor(final CommandAction command) { assert command != null; CliProcessor clp = new CliProcessor(); clp.addBean(command); clp.addBean(this); AggregateMessageSource messages = new AggregateMessageSource(command.getMessages(), this.getMessages()); clp.setMessages(new PrefixingMessageSource(messages, COMMAND_DOT)); return clp; }
private void discoverDescriptors(final Object bean) { assert bean != null; // Recursively process all the methods/fields (@Inherited won't work here) for (Class<?> type = bean.getClass(); type != null; type = type.getSuperclass()) { for (Method method : type.getDeclaredMethods()) { discoverDescriptor(bean, method); } for (Field field : type.getDeclaredFields()) { discoverDescriptor(bean, field); } } // Sanity check the argument indexes for (int i = 0; i < argumentDescriptors.size(); i++) { if (argumentDescriptors.get(i) == null) { throw new IllegalAnnotationError(String.format("No @Argument for index: %d", i)); } } }
CliProcessor clp = new CliProcessor(); clp.addBean(this); clp.setMessages(messages); clp.setStopAtNonOption(true); clp.process(args);
arguments.addAll(processor.getArgumentDescriptors()); options.addAll(processor.getOptionDescriptors());
@SuppressWarnings("unused") public String getOptions() { if (clp.getOptionDescriptors().isEmpty()) { return ""; } PrintBuffer buff = new PrintBuffer(); printHeader(buff, "section.options"); printer.printOptions(buff, clp.getOptionDescriptors()); return buff.toString(); }
@SuppressWarnings("unused") public String getArguments() { if (clp.getArgumentDescriptors().isEmpty()) { return ""; } PrintBuffer buff = new PrintBuffer(); printHeader(buff, "section.arguments"); printer.printArguments(buff, clp.getArgumentDescriptors()); return buff.toString(); }
public void addBean(final Object bean) { discoverDescriptors(bean); if (bean instanceof CliProcessorAware) { ((CliProcessorAware) bean).setProcessor(this); } }
public HelpPrinter(final CliProcessor processor) { assert processor != null; this.processor = processor; // Add messages from the processor MessageSource messages = processor.getMessages(); if (messages != null) { addMessages(messages); } }
CommandHelpSupport help = new CommandHelpSupport(); CliProcessor clp = help.createProcessor(action); clp.process(Arguments.toStringArray(args));
cl = parser.parse(createOptions(), args, stopAtNonOption);