DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=27575>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=27575

PatternOptionBuilder does not support required Options

           Summary: PatternOptionBuilder does not support required Options
           Product: Commons
           Version: unspecified
          Platform: PC
        OS/Version: Windows XP
            Status: NEW
          Severity: Normal
          Priority: Other
         Component: CLI
        AssignedTo: [EMAIL PROTECTED]
        ReportedBy: [EMAIL PROTECTED]


It seems like no required Options can be created via the
PatternOptionBuilder. That is for the following reason:

Usually "required" is being specified by including an "!"
into the pattern. E.g. like this "hc!<" which should make
the option "c" mandatory. But you always get an
IllegalArgumentException because the "!" is used to create
an Option. Here is the main loop...

  if (!isValueCode(ch))
  {
    if (opt != ' ')
    {
      options.addOption(
         OptionBuilder.hasArg(type != null)
                      .isRequired(required).withType(type)
                      .create(opt));
       required = false;
       type = null;
       opt = ' ';
    }
    opt = ch;
  }
  else if (ch == '!')
  {
    required = true;
  }
  else
  {
    type = getValueClass(ch);
  }

If you look at the code you can see the that "!"
case is only being reached in the else clause.
Which in turn means if isValueCode('!') is true.
If you look at "isValueCode"

  public static boolean isValueCode(char ch)
     {
         if ((ch != '@') && (ch != ':') && (ch != '%') && (ch != '+')
             && (ch != '#') && (ch != '<') && (ch != '>') && (ch != '*')
             && (ch != '/'))
         {
             return false;
         }
 
         return true;
     }

you can see that "isValueCode('!')" will always return
false and the else clause can never be reached.

Adding the "!" to the "isValueCode" method should
do the trick.

  public static boolean isValueCode(char ch)
     {
         if ((ch != '@') && (ch != ':') && (ch != '%') && (ch != '+')
             && (ch != '#') && (ch != '<') && (ch != '>') && (ch != '*')
             && (ch != '/') && (ch != '!'))
         {
             return false;
         }
 
         return true;
     }

Could someone please fix this?
Thanks, Torsten

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to