You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by bu...@apache.org on 2004/03/10 17:50:12 UTC

DO NOT REPLY [Bug 27575] New: - PatternOptionBuilder does not support required Options

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: commons-dev@jakarta.apache.org
        ReportedBy: tcurdt@apache.org


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: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Re: DO NOT REPLY [Bug 27575] New: - PatternOptionBuilder does not support required Options

Posted by Torsten Curdt <tc...@vafer.org>.
 > http://issues.apache.org/bugzilla/show_bug.cgi?id=27575

Can someone at least confirm this?

I am writing an article and I don't
write something wrong.

cheers
--
Torsten



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org