public static <T> HelpDescriptor<T> create(CommandDescriptor<T> descriptor) throws IntrospectionException { return new HelpDescriptor<T>(descriptor); }
subordinates.put(subordinate.getName(), new HelpDescriptor<T>(this, subordinate));
public static <T> HelpDescriptor<T> create(CommandDescriptorImpl<T> descriptor) { return new HelpDescriptor<T>(descriptor); }
public static <T> HelpDescriptor<T> create(CommandDescriptor<T> descriptor) throws IntrospectionException { return new HelpDescriptor<T>(descriptor); }
public void testMain1() throws Exception { CommandDescriptor<Instance<b>> desc = CommandFactory.DEFAULT.create(b.class); HelpDescriptor<Instance<b>> helpDesc = new HelpDescriptor<Instance<b>>(desc); OptionDescriptor optionDesc = helpDesc.getOption("-h"); assertNotNull(optionDesc); InvocationMatcher<Instance<b>> matcher = helpDesc.matcher(); // InvocationMatch<Instance<b>> match = matcher.parse("--help"); ParameterMatch<OptionDescriptor> helpMatch = match.getParameter(optionDesc); assertNotNull(helpMatch); CommandInvoker<Instance<b>, ?> invoker = match.getInvoker(); Help help = (Help)invoker.invoke(Util.wrap(new b())); assertNotNull(help); CommandDescriptor mainDescriptor = help.getDescriptor(); assertEquals("b", mainDescriptor.getName()); assertSame(null, mainDescriptor.getOwner()); } }
private HelpDescriptor(HelpDescriptor<T> owner, CommandDescriptorImpl<T> delegate) throws IntrospectionException { super(delegate.getName(), delegate.getDescription()); // for (ParameterDescriptor parameter : delegate.getParameters()) { addParameter(parameter); } // Override the help parameter only for the root level // otherwise it may be repeated several times if (owner == null) { addParameter(HELP_OPTION); } // Wrap subordinates LinkedHashMap<String, HelpDescriptor<T>> subordinates = new LinkedHashMap<String, HelpDescriptor<T>>(); for (CommandDescriptorImpl<T> subordinate : delegate.getSubordinates().values()) { subordinates.put(subordinate.getName(), new HelpDescriptor<T>(this, subordinate)); } // this.owner = owner; this.delegate = delegate; this.subordinates = subordinates; }
subordinates.put(subordinate.getName(), new HelpDescriptor<T>(this, subordinate));
public void testOption() throws Exception { // CommandDescriptor<Instance<A>> desc = CommandFactory.DEFAULT.create(A.class); HelpDescriptor<Instance<A>> helpDesc = new HelpDescriptor<Instance<A>>(desc); OptionDescriptor optionDesc = helpDesc.getOption("-h"); assertNotNull(optionDesc); OptionDescriptor foo = helpDesc.getOption("-f"); assertNotNull(foo); InvocationMatcher<Instance<A>> matcher = helpDesc.matcher(); // InvocationMatch<Instance<A>> match = matcher.parse("--help"); ParameterMatch<OptionDescriptor> helpMatch = match.getParameter(optionDesc); assertNotNull(helpMatch); CommandInvoker<Instance<A>, ?> invoker = match.getInvoker(); Help help = (Help)invoker.invoke(Util.wrap(new A())); assertNotNull(help); assertSame(desc, help.getDescriptor().getDelegate()); // match = matcher.parse(""); invoker = match.getInvoker(); invoker.invoke(Util.wrap(new A())); match = matcher.parse("-f foo_value bar"); invoker = match.getInvoker(); assertEquals("invoked:foo_value", invoker.invoke(Util.wrap(new A()))); }