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

Passing invalid arguments to CliBuilder.parse does not result in any informative error msg or exception.


    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Not A Problem
    • Affects Version/s: 1.6-beta-2
    • Fix Version/s: None
    • Labels:
    • Environment:
      Windows vista 64 bit.


      When i pass garbage arguments as part of my command line i get no indication that anything is amiss...

      I think it would be better to have a mode in which command line processing is 'strict' and anything that is not specified as a valid option triggers some kind of informative err msg or exception...

      If you agree that this suggestion is worthwhile and you want help implementing the feature pls drop you a line and i can work on a patch...
      it seems like it should be pretty straight forward.


      Here is a test case that demonstrates the issue >>

      // Generated from archetype; please customize.

      package com.lackey

      import groovy.util.GroovyTestCase


      • Tests for the {@link Example}

        class NewTest extends GroovyTestCase
        protected static CliBuilder getOptionParser(PrintWriter print_writer)

        { def cli = new CliBuilder([writer: print_writer]); cli.r( argName: 'dir', longOpt: 'rootDirectory', args: 1, required: false, 'root directory from which to start the scan ' + '- Default: root (/) if not specified', ); return cli; }

      protected static OptionAccessor getParsedCommandLineOptions(
      String[] args,
      PrintWriter pw= new PrintWriter(System.out)) {
      // try/catch so we can gracefully handle NPEs in commons command line parsing library

      { final CliBuilder cli = getOptionParser() return cli.parse(args) }

      catch (Exception e)

      { return null; }


      void testBadArgHandling()

      { ByteArrayOutputStream baos = new ByteArrayOutputStream(); PrintWriter pwriter = new PrintWriter(baos); String[] bad_args1 = ["blah", "foo"] as String[] //String[] bad_args1 = ["-r", "-u"] as String[] OptionAccessor opts = FindFile.getParsedCommandLineOptions( bad_args1, pwriter); println "Note that no errors are printed.. no exceptions are thrown" println "there is nothing to inform the user that he/she is using invalid arguments " print "opts are = " + opts.toString() print "parse result = " + baos.toString() }





            • Assignee:
              chrisb206 chris bedford
            • Votes:
              0 Vote for this issue
              0 Start watching this issue


              • Created: