groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pa...@apache.org
Subject [1/2] groovy git commit: GROOVY-8520 bugfix: fix issues raised after previous PR (closes #701)
Date Fri, 18 May 2018 11:13:43 GMT
Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_6_X 71915d6c6 -> fea8d87d3


GROOVY-8520 bugfix: fix issues raised after previous PR (closes #701)


Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/270b5d25
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/270b5d25
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/270b5d25

Branch: refs/heads/GROOVY_2_6_X
Commit: 270b5d25b48c2a8da92c395a8426caf738344781
Parents: 71915d6
Author: Remko Popma <remkop@yahoo.com>
Authored: Mon May 7 00:07:35 2018 +0200
Committer: Paul King <paulk@asert.com.au>
Committed: Fri May 18 21:13:05 2018 +1000

----------------------------------------------------------------------
 .../groovy/groovy/cli/picocli/CliBuilder.groovy |  6 ++--
 .../src/spec/test/builder/CliBuilderTest.groovy | 22 +++++++++++--
 .../groovy/cli/picocli/CliBuilderTest.groovy    | 33 +++++++++++++++++++-
 3 files changed, 55 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/270b5d25/subprojects/groovy-cli-picocli/src/main/groovy/groovy/cli/picocli/CliBuilder.groovy
----------------------------------------------------------------------
diff --git a/subprojects/groovy-cli-picocli/src/main/groovy/groovy/cli/picocli/CliBuilder.groovy
b/subprojects/groovy-cli-picocli/src/main/groovy/groovy/cli/picocli/CliBuilder.groovy
index aacd832..e0377b3 100644
--- a/subprojects/groovy-cli-picocli/src/main/groovy/groovy/cli/picocli/CliBuilder.groovy
+++ b/subprojects/groovy-cli-picocli/src/main/groovy/groovy/cli/picocli/CliBuilder.groovy
@@ -378,6 +378,7 @@ class CliBuilder {
      * <code>true</code> if the parser should recognize long options with both
      * a single hyphen and a double hyphen prefix. The default is <code>false</code>,
      * so only long options with a double hypen prefix (<code>--option</code>)
are recognized.
+     * @since 2.5
      */
     boolean acceptLongOptionsWithSingleHyphen = false
 
@@ -512,9 +513,9 @@ class CliBuilder {
      * used by the underlying library.
      * @param posix whether to allow clustered short options
      */
-    void setPosix(boolean posix) {
+    void setPosix(Boolean posix) {
         this.posix = posix
-        parser.posixClusteredShortOptionsAllowed(posix)
+        parser.posixClusteredShortOptionsAllowed(posix ?: false)
     }
 
     /**
@@ -804,6 +805,7 @@ class CliBuilder {
         if (attr.type)           { builder.type(attr.type) } // cannot set type to null
         if (attr.auxiliaryTypes) { builder.auxiliaryTypes(attr.auxiliaryTypes) } // cannot
set aux types to null
         builder.arity(arity)
+        builder.description(unparsed.description())
         builder.paramLabel("<$attr.label>")
         builder.getter(attr.getter)
         builder.setter(attr.setter)

http://git-wip-us.apache.org/repos/asf/groovy/blob/270b5d25/subprojects/groovy-cli-picocli/src/spec/test/builder/CliBuilderTest.groovy
----------------------------------------------------------------------
diff --git a/subprojects/groovy-cli-picocli/src/spec/test/builder/CliBuilderTest.groovy b/subprojects/groovy-cli-picocli/src/spec/test/builder/CliBuilderTest.groovy
index 302bef6..195ac0d 100644
--- a/subprojects/groovy-cli-picocli/src/spec/test/builder/CliBuilderTest.groovy
+++ b/subprojects/groovy-cli-picocli/src/spec/test/builder/CliBuilderTest.groovy
@@ -40,7 +40,7 @@ class CliBuilderTest extends GroovyTestCase {
     interface GreeterI {
         @Option(shortName='h', description='display usage') Boolean help()        // <1>
         @Option(shortName='a', description='greeting audience') String audience() // <2>
-        @Unparsed List remaining()                                                // <3>
+        @Unparsed(description = "positional parameters") List remaining()         // <3>
     }
     // end::annotationInterfaceSpec[]
 
@@ -56,14 +56,14 @@ class CliBuilderTest extends GroovyTestCase {
         }
         String getAudience() { audience }
 
-        @Unparsed
+        @Unparsed(description = "positional parameters")
         List remaining                      // <3>
     }
     // end::annotationClassSpec[]
 
     void testAnnotationsInterface() {
         // tag::annotationInterface[]
-        def cli = new CliBuilder(usage: 'groovy Greeter [option]')  // <1>
+        def cli = new CliBuilder(name: 'groovy Greeter')  // <1>
         def argz = '--audience Groovologist'.split()
         def options = cli.parseFromSpec(GreeterI, argz)             // <2>
         assert options.audience() == 'Groovologist'                 // <3>
@@ -73,6 +73,22 @@ class CliBuilderTest extends GroovyTestCase {
         assert options.help()
         assert options.remaining() == ['Some', 'Other', 'Args']     // <5>
         // end::annotationInterface[]
+
+        options = cli.parseFromSpec(GreeterI, ['-h', 'Some', 'Other', 'Args'] as String[])
+        assert options.help()
+        assert options.remaining() == ['Some', 'Other', 'Args']
+        StringWriter sw = new StringWriter()
+        cli.writer = new PrintWriter(sw)
+        cli.usage()
+
+        String expected = '''\
+Usage: groovy Greeter [-h] [-a=<audience>] [<remaining>...]
+      [<remaining>...]   positional parameters
+  -a, --audience=<audience>
+                         greeting audience
+  -h, --help             display usage
+'''
+        assert expected.normalize() == sw.toString().normalize()
     }
 
     void testAnnotationsClass() {

http://git-wip-us.apache.org/repos/asf/groovy/blob/270b5d25/subprojects/groovy-cli-picocli/src/test/groovy/groovy/cli/picocli/CliBuilderTest.groovy
----------------------------------------------------------------------
diff --git a/subprojects/groovy-cli-picocli/src/test/groovy/groovy/cli/picocli/CliBuilderTest.groovy
b/subprojects/groovy-cli-picocli/src/test/groovy/groovy/cli/picocli/CliBuilderTest.groovy
index e6a0e7a..be8b5f9 100644
--- a/subprojects/groovy-cli-picocli/src/test/groovy/groovy/cli/picocli/CliBuilderTest.groovy
+++ b/subprojects/groovy-cli-picocli/src/test/groovy/groovy/cli/picocli/CliBuilderTest.groovy
@@ -20,7 +20,6 @@ package groovy.cli.picocli
 
 import groovy.cli.Option
 import groovy.cli.Unparsed
-import groovy.cli.picocli.CliBuilder
 import groovy.transform.ToString
 import groovy.transform.TypeChecked
 import picocli.CommandLine.DuplicateOptionAnnotationsException
@@ -123,6 +122,38 @@ class CliBuilderTest extends GroovyTestCase {
         groovy.util.GroovyTestCase.assertEquals(['1', '2'], options.args)
     }
 
+    void testPosixNullValueHandledCorrectly_inConstructor() {
+        def cli = new CliBuilder()
+        assert cli.posix == true
+        assert cli.parser.posixClusteredShortOptionsAllowed()
+
+        cli = new CliBuilder(posix: false)
+        assert cli.posix == false
+        assert !cli.parser.posixClusteredShortOptionsAllowed()
+
+        cli = new CliBuilder(posix: null)
+        assert cli.posix == null
+        assert !cli.parser.posixClusteredShortOptionsAllowed()
+    }
+
+    void testPosixNullValueHandledCorrectly_inSetter() {
+        def cli = new CliBuilder()
+        assert cli.posix == true
+        assert cli.parser.posixClusteredShortOptionsAllowed()
+
+        cli.posix = false
+        assert cli.posix == false
+        assert !cli.parser.posixClusteredShortOptionsAllowed()
+
+        cli = new CliBuilder()
+        assert cli.posix == true
+        assert cli.parser.posixClusteredShortOptionsAllowed()
+
+        cli.posix = null
+        assert cli.posix == null
+        assert !cli.parser.posixClusteredShortOptionsAllowed()
+    }
+
     void testFailedParsePrintsUsage() {
         def cli = new CliBuilder(writer: printWriter)
         cli.x(required: true, 'message')


Mime
View raw message