Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-4066

Groovy clibuilder doesn't take the parameter when the longOpt name ends with character "s"

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.7.0
    • 1.7.2, 1.8-beta-1
    • None
    • None
    • Linux, Mac

    Description

      When the clibuilder creates a command line option whose longOpt ends with character "s", such as "seconds", the parser can't get the parameter, it is null.

      Here's a simple groovy script that demonstrates the problem. Note that the long option ending with an 's' gets enabled when the non-s option is given.

      $> ./cli.groovy -s
      options.s evaluates to true
      options.seconds evaluates to false
      options.e evaluates to false
      options.second evaluates to false

      $> ./cli.groovy -e
      options.s evaluates to false
      options.seconds evaluates to true
      options.e evaluates to true
      options.second evaluates to true

      def cli = new CliBuilder()
      cli.s longOpt:'seconds', 'a long arg that ends with an "s"'
      cli.e longOpt:'second', 'a long arg that does not end with an "s"'

      def options = cli.parse( args )
      if( null == options )
      {
      return
      }

      if( args.length == 0 || options.h )
      {
      cli.usage()
      }

      println "options.s evaluates to " + (options.s as boolean)
      println "options.seconds evaluates to " + (options.seconds as boolean)
      println "options.e evaluates to " + (options.e as boolean)
      println "options.second evaluates to " + (options.second as boolean)

      Attachments

        Activity

          People

            roshandawrani Roshan Dawrani
            miwang mingran wang
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: