Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lenient mode for extracting annotations #316

Closed
remkop opened this issue Mar 27, 2018 · 1 comment
Closed

Lenient mode for extracting annotations #316

remkop opened this issue Mar 27, 2018 · 1 comment

Comments

@remkop
Copy link
Owner

remkop commented Mar 27, 2018

Needed for #258.

CommandSpec.forAnnotatedObject requires at least one picocli annotation on the specified object.

To allow mixing groovy.cli and picocli annotations, a factory method is needed that allows picocli annotation to be optional.

@remkop remkop added this to the 3.0 milestone Mar 27, 2018
remkop added a commit that referenced this issue Mar 29, 2018
@remkop
Copy link
Owner Author

remkop commented Mar 30, 2018

Index: src/test/java/picocli/CommandLineModelTest.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- src/test/java/picocli/CommandLineModelTest.java	(revision )
+++ src/test/java/picocli/CommandLineModelTest.java	(revision )
@@ -906,4 +906,37 @@
         assertTrue(spec.options().isEmpty());
         assertFalse(spec.mixinStandardHelpOptions());
     }
+
+    @Test
+    public void testCommandSpec_forAnnotatedObject_requiresPicocliAnnotation() {
+        try {
+            CommandSpec.forAnnotatedObject(new Object());
+            fail("Expected error");
+        } catch (InitializationException ok) {
+            assertEquals("java.lang.Object is not a command: it has no @Command, @Option, @Parameters or @Unmatched annotations", ok.getMessage());
+        }
+    }
+
+    @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());
+    }
 }

@remkop remkop closed this as completed in 5035471 Mar 30, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant