private CommandSpec getOrCreateCommandSpecForArg(Map.Entry<Element, ?> argElement, Map<Element, CommandSpec> commands) { Element key = argElement.getKey().getEnclosingElement(); CommandSpec commandSpec = commands.get(key); if (commandSpec == null) { logger.fine("Element " + argElement.getKey() + " is enclosed by " + key + " which does not have a @Command annotation"); commandSpec = CommandSpec.forAnnotatedObjectLenient(key); commands.put(key, commandSpec); } return commandSpec; }
@Test public void testCommandSpec_forAnnotatedObjectLenient_doesNotRequirePicocliAnnotation() { CommandSpec.forAnnotatedObjectLenient(new Object()); // no error }
@Test public void testCommandSpec_forAnnotatedObjectLenient_returnsEmptyCommandSpec() { CommandSpec spec = CommandSpec.forAnnotatedObjectLenient(new Object()); assertTrue(spec.optionsMap().isEmpty()); assertTrue(spec.posixOptionsMap().isEmpty()); assertTrue(spec.options().isEmpty()); assertTrue(spec.positionalParameters().isEmpty()); assertTrue(spec.unmatchedArgsBindings().isEmpty()); assertTrue(spec.subcommands().isEmpty()); assertTrue(spec.mixins().isEmpty()); assertTrue(spec.requiredArgs().isEmpty()); assertFalse(spec.mixinStandardHelpOptions()); assertFalse(spec.helpCommand()); assertEquals("<main class>", spec.name()); assertArrayEquals(new String[0], spec.version()); assertNull(spec.versionProvider()); }
@Test public void testCommandSpec_forAnnotatedObjectLenient_returnsEmptyCommandSpec() { CommandSpec spec = CommandSpec.forAnnotatedObjectLenient(new Object()); assertTrue(spec.optionsMap().isEmpty()); assertTrue(spec.posixOptionsMap().isEmpty()); assertTrue(spec.options().isEmpty()); assertTrue(spec.positionalParameters().isEmpty()); assertTrue(spec.unmatchedArgsBindings().isEmpty()); assertTrue(spec.subcommands().isEmpty()); assertTrue(spec.mixins().isEmpty()); assertTrue(spec.requiredArgs().isEmpty()); assertFalse(spec.mixinStandardHelpOptions()); assertFalse(spec.helpCommand()); assertEquals("<main class>", spec.name()); assertArrayEquals(new String[0], spec.version()); assertNull(spec.versionProvider()); }
@Test public void testCommandSpec_forAnnotatedObjectLenient_doesNotRequirePicocliAnnotation() { CommandSpec.forAnnotatedObjectLenient(new Object()); // no error }
/** Creates and returns a new {@code CommandSpec} initialized from the specified associated user object. If the specified * user object has no {@link Command}, {@link Option} or {@link Parameters} annotations, an empty {@code CommandSpec} is returned. * @param userObject the user object annotated with {@link Command}, {@link Option} and/or {@link Parameters} annotations. * @throws InitializationException if the specified object has invalid annotations */ public static CommandSpec forAnnotatedObjectLenient(Object userObject) { return forAnnotatedObjectLenient(userObject, new DefaultFactory()); }
/** Creates and returns a new {@code CommandSpec} initialized from the specified associated user object. If the specified * user object has no {@link Command}, {@link Option} or {@link Parameters} annotations, an empty {@code CommandSpec} is returned. * @param userObject the user object annotated with {@link Command}, {@link Option} and/or {@link Parameters} annotations. * @throws InitializationException if the specified object has invalid annotations */ public static CommandSpec forAnnotatedObjectLenient(Object userObject) { return forAnnotatedObjectLenient(userObject, new DefaultFactory()); }