groovy-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Remko Popma (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (GROOVY-8592) Migrate command line tools to picocli version of CliBuilder
Date Fri, 25 May 2018 05:40:00 GMT

    [ https://issues.apache.org/jira/browse/GROOVY-8592?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16490258#comment-16490258
] 

Remko Popma commented on GROOVY-8592:
-------------------------------------

Darn, that is a bit faster than I anticipated. I have prior commitments this evening so may
not be able to provide a proper PR in time. However, this is roughly what I had in mind:

{noformat}
Index: subprojects/groovy-console/src/main/groovy/groovy/ui/Console.groovy
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- subprojects/groovy-console/src/main/groovy/groovy/ui/Console.groovy (revision )
+++ subprojects/groovy-console/src/main/groovy/groovy/ui/Console.groovy (revision )
@@ -18,6 +18,8 @@
  */
 package groovy.ui
 
+import groovy.cli.picocli.CliBuilder
+import groovy.cli.picocli.OptionAccessor
 import groovy.inspect.swingui.AstBrowser
 import groovy.inspect.swingui.ObjectBrowser
 import groovy.swing.SwingBuilder
@@ -191,16 +193,16 @@
     ConsolePreferences consolePreferences
 
     static void main(args) {
-        CliBuilder cli = new CliBuilder(usage: 'groovyConsole [options] [filename]', stopAtNonOption:
false)
+        CliBuilder cli = new CliBuilder(usage: 'groovyConsole [options] [filename]', stopAtNonOption:
false,
+            header: 'The Groovy Swing Console allows a user to enter and run Groovy scripts.')
         MessageSource messages = new MessageSource(Console)
         cli.with {
-            classpath(messages['cli.option.classpath.description'])
-            cp(longOpt: 'classpath', messages['cli.option.cp.description'])
+            _(names: ['-cp', '-classpath', '--classpath'], messages['cli.option.classpath.description'])
             h(longOpt: 'help', messages['cli.option.help.description'])
             V(longOpt: 'version', messages['cli.option.version.description'])
             pa(longOpt: 'parameters', messages['cli.option.parameters.description'])
             i(longOpt: 'indy', messages['cli.option.indy.description'])
-            D(longOpt: 'define', args: 2, argName: 'name=value', valueSeparator: '=', messages['cli.option.define.description'])
+            D(longOpt: 'define', type: Map, argName: 'name=value', messages['cli.option.define.description'])
             _(longOpt: 'configscript', args: 1, messages['cli.option.configscript.description'])
         }
         OptionAccessor options = cli.parse(args)
@@ -221,9 +223,7 @@
         }
 
         if (options.hasOption('D')) {
-            options.getOptionProperties('D')?.each { k, v ->
-                System.setProperty(k, v)
-            }
+            options.Ds.each { k, v -> System.setProperty(k, v) }
         }
 
         // full stack trace should not be logged to the output window - GROOVY-4663
{noformat}

{noformat}
Index: subprojects/groovy-console/build.gradle
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- subprojects/groovy-console/build.gradle (revision )
+++ subprojects/groovy-console/build.gradle (revision )
@@ -20,7 +20,7 @@
 
 dependencies {
     compile rootProject
-    compile project(':groovy-cli-commons')
+    compile project(':groovy-cli-picocli')
     compile project(':groovy-swing')
     compile project(':groovy-templates')
     testCompile project(':groovy-test')
{noformat}

{noformat}
Index: subprojects/groovy-groovysh/src/main/groovy/org/codehaus/groovy/tools/shell/Main.groovy
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- subprojects/groovy-groovysh/src/main/groovy/org/codehaus/groovy/tools/shell/Main.groovy
(revision )
+++ subprojects/groovy-groovysh/src/main/groovy/org/codehaus/groovy/tools/shell/Main.groovy
(revision )
@@ -18,8 +18,8 @@
  */
 package org.codehaus.groovy.tools.shell
 
-import groovy.cli.commons.CliBuilder
-import groovy.cli.commons.OptionAccessor
+import groovy.cli.picocli.CliBuilder
+import groovy.cli.picocli.OptionAccessor
 import jline.TerminalFactory
 import jline.UnixTerminal
 import jline.UnsupportedTerminal
@@ -76,11 +76,11 @@
      * @param main must have a Groovysh member that has an IO member.
      */
     static void main(final String[] args) {
-        CliBuilder cli = new CliBuilder(usage: 'groovysh [options] [...]', formatter: new
HelpFormatter(), stopAtNonOption: false)
+        CliBuilder cli = new CliBuilder(usage: 'groovysh [options] [...]', stopAtNonOption:
false,
+                header = 'The Groovy Shell, aka groovysh, is a command-line application which
allows easy access to evaluate Groovy expressions, define classes and run simple experiments.')
         MessageSource messages = new MessageSource(Main)
         cli.with {
-            classpath(messages['cli.option.classpath.description'])
-            cp(longOpt: 'classpath', messages['cli.option.cp.description'])
+            _(names: ['-cp', '-classpath', '--classpath'], messages['cli.option.classpath.description'])
             h(longOpt: 'help', messages['cli.option.help.description'])
             V(longOpt: 'version', messages['cli.option.version.description'])
             v(longOpt: 'verbose', messages['cli.option.verbose.description'])
@@ -88,7 +88,7 @@
             d(longOpt: 'debug', messages['cli.option.debug.description'])
             e(longOpt: 'evaluate', args: 1, argName: 'CODE', optionalArg: false, messages['cli.option.evaluate.description'])
             C(longOpt: 'color', args: 1, argName: 'FLAG', optionalArg: true, messages['cli.option.color.description'])
-            D(longOpt: 'define', args: 2, argName: 'name=value', valueSeparator: '=', messages['cli.option.define.description'])
+            D(longOpt: 'define', type: Map, argName: 'name=value', messages['cli.option.define.description'])
             T(longOpt: 'terminal', args: 1, argName: 'TYPE', messages['cli.option.terminal.description'])
             pa(longOpt: 'parameters', messages['cli.option.parameters.description'])
         }
@@ -134,9 +134,7 @@
         IO io = new IO()
 
         if (options.hasOption('D')) {
-            options.getOptionProperties('D')?.each { k, v ->
-                System.setProperty(k, v)
-            }
+            options.Ds.each { k, v -> System.setProperty(k, v) }
         }
 
         if (options.v) {
{noformat}

{noformat}
Index: subprojects/groovy-groovysh/build.gradle
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- subprojects/groovy-groovysh/build.gradle (revision )
+++ subprojects/groovy-groovysh/build.gradle (revision )
@@ -18,7 +18,7 @@
  */
 dependencies {
     compile rootProject
-    compile project(':groovy-cli-commons')
+    compile project(':groovy-cli-picocli')
     compile project(':groovy-console')
     testCompile project(':groovy-test')
     compile("jline:jline:$jlineVersion") {
{noformat}

{noformat}
Index: subprojects/groovy-groovydoc/src/main/groovy/org/codehaus/groovy/tools/groovydoc/Main.groovy
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- subprojects/groovy-groovydoc/src/main/groovy/org/codehaus/groovy/tools/groovydoc/Main.groovy
(revision )
+++ subprojects/groovy-groovydoc/src/main/groovy/org/codehaus/groovy/tools/groovydoc/Main.groovy
(revision )
@@ -18,7 +18,8 @@
  */
 package org.codehaus.groovy.tools.groovydoc
 
-import groovy.cli.commons.CliBuilder
+import groovy.cli.picocli.CliBuilder
+import groovy.cli.picocli.OptionAccessor
 import groovy.io.FileType
 import org.codehaus.groovy.tools.groovydoc.gstringTemplates.GroovyDocTemplateInfo
 import org.codehaus.groovy.tools.shell.IO
@@ -58,9 +59,10 @@
         IO io = new IO()
         Logger.io = io
 
-        def cli = new CliBuilder(usage : 'groovydoc [options] [packagenames] [sourcefiles]',
writer: io.out, posix:false)
+        def cli = new CliBuilder(usage : 'groovydoc [options] [packagenames] [sourcefiles]',
writer: io.out, posix:false,
+                header: 'GroovyDoc is a tool responsible for generating documentation from
your code. It acts like the Javadoc tool in the Java world but is capable of handling both
groovy and java files.')
 
-        cli.help(longOpt: 'help', messages['cli.option.help.description'])
+        _(names: ['-h', '-help', '--help'], messages['cli.option.help.description'])
         cli._(longOpt: 'version', messages['cli.option.version.description'])
         cli.verbose(messages['cli.option.verbose.description'])
         cli.quiet(messages['cli.option.quiet.description'])
{noformat}

{noformat}
Index: subprojects/groovy-groovydoc/build.gradle
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- subprojects/groovy-groovydoc/build.gradle (revision )
+++ subprojects/groovy-groovydoc/build.gradle (revision )
@@ -19,7 +19,7 @@
 dependencies {
     compile rootProject
     testCompile rootProject.sourceSets.test.runtimeClasspath
-    compile project(':groovy-cli-commons')
+    compile project(':groovy-cli-picocli')
     compile project(':groovy-templates')
     runtime project(':groovy-dateutil')
     testCompile project(':groovy-test')
{noformat}

> Migrate command line tools to picocli version of CliBuilder
> -----------------------------------------------------------
>
>                 Key: GROOVY-8592
>                 URL: https://issues.apache.org/jira/browse/GROOVY-8592
>             Project: Groovy
>          Issue Type: Improvement
>          Components: command line processing
>    Affects Versions: 2.5.0-rc-3
>            Reporter: Remko Popma
>            Priority: Major
>             Fix For: 2.5.0
>
>
> The following command line tools use either {{groovy.cli.commons.CliBuilder}} or implicitly
use {{groovy.util.CliBuilder}} which delegates to the commons-cli version of CliBuilder:
> * groovyConsole (groovy.ui.Console)
> * groovydoc (org.codehaus.groovy.tools.groovydoc.Main)
> * groovysh (org.codehaus.groovy.tools.shell.Main)
> This ticket proposes to use {{groovy.cli.picocli.CliBuilder}} instead, so that all command
line tools in the {{bin}} directory of the Groovy distribution show usage help in ANSI colors.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Mime
View raw message