Return-Path: Delivered-To: apmail-jakarta-commons-dev-archive@apache.org Received: (qmail 86380 invoked from network); 10 Dec 2002 09:49:51 -0000 Received: from unknown (HELO nagoya.betaversion.org) (192.18.49.131) by daedalus.apache.org with SMTP; 10 Dec 2002 09:49:51 -0000 Received: (qmail 14302 invoked by uid 97); 10 Dec 2002 09:51:09 -0000 Delivered-To: qmlist-jakarta-archive-commons-dev@jakarta.apache.org Received: (qmail 14286 invoked by uid 97); 10 Dec 2002 09:51:08 -0000 Mailing-List: contact commons-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Jakarta Commons Developers List" Reply-To: "Jakarta Commons Developers List" Delivered-To: mailing list commons-dev@jakarta.apache.org Received: (qmail 14268 invoked by uid 98); 10 Dec 2002 09:51:07 -0000 X-Antivirus: nagoya (v4218 created Aug 14 2002) Message-ID: <002b01c2a031$7b6eb610$6d8ca8c0@acure.net> From: "Max Rydahl Andersen" To: "Jakarta Commons Developers List" , "Mike McLean" References: <064501c2a028$c4640360$9865fea9@spiritsoft.com> Subject: Re: [cli] library change suggestion Date: Tue, 10 Dec 2002 10:49:50 +0100 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 5.50.4522.1200 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300 X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N Suggestion: Make it perform the validation on to an interface instead of just a raw list or regular expression. e.g. CLIValidArgumentsValidator valueWeekdays = new WeirdWeekdaysValidator() { String valid[] = {"Monday","Tuesday","Wednesday","Thursday"}; boolean validateArgument(String argument) { if argument in valid then return true else return false; } } Option weekday = OptionBuilder.withArgName( "Weekday" ) .withLongOpt( "weekday" ) .withDescription( "Weekday to generate. Monday to Thursday or Auto" ) .hasArg() .hasArgs(1) .isRequired() .withValidArguments(valueWeekdays) .create("w"); Or something like that thus CLI won't be limited on to string arrays and regexp.......CLI could ofcourse come with prebuilt StringArrayValidators and RegExpValidators.... idea: Maybe the validateArgument should thrown an exception with info on why it failed which CLI could understand and provide it as an message to the user... Just a thought... /max ----- Original Message ----- From: "James Strachan" To: "Mike McLean" ; "Jakarta Commons Developers" Sent: Tuesday, December 10, 2002 9:47 AM Subject: [cli] library change suggestion > Forwarding to the list.... > > ----- Original Message ----- > From: "Mike McLean" > To: > > I started using the CLI library and found it really nice. One thing I > though might be missing for my needs was a way to validate the arguments > given to a parameter. In other words, if my args[0] looks like -w > Monday, I want to be sure that Monday is a valid value for the w Option. > > So I figured I'd give it a shot. I downloaded the source code and have > made the modifications to suit my needs. I've done limited testing, but > it works for my needs. I figured I'd send you guys the small changes I > made in case you find the idea ok. > > Here are the changes that were made: > - OptionBuilder: > Added the validArguments String array memeber along with the > withValidArguments method. Changed the reset method to reset > validArguments. > > - Option: > Added the validArguments member along with the accessor methods. Also > changed the clone method to clone the new field. > > - Parser: > I added a checkArgValidity method. The method throws a > InvalidArgumentException. The reason I didn't want to throw just a > ParseException is that I didn't find the message usefull. If the > argument isn't valid, then I throw that exception. The call to > checkArgValidity is made from the processArgs method. > > - InvalidArgumentException: > As I mentionned, this is a new class that extends ParseException so no > change in code to throw new exception types. > > Here's how I use it: > String[] valueWeekdays = {"Monday","Tuesday","Wednesday","Thursday"}; > Option weekday = OptionBuilder.withArgName( "Weekday" ) > .withLongOpt( "weekday" ) > .withDescription( "Weekday to generate. > Monday to Thursday or Auto" ) > .hasArg() > .hasArgs(1) > .isRequired() > .withValidArguments(valueWeekdays) > .create("w"); > > If my w param is Monday (or monday), then no problem. If it's Friday, > then it throws an exception. > > As I've mentionned, the testing I've done is limited. I figured that you > guys are probably setup with Junit and have all your tests setup. > > If you like the idea and intend to use it, let me know and I'll try to > whip up a regexp version of it where (well you guessed it), the argument > could be validated against a regular expression. > > Mike. > > ---------------------------------------------------------------------------- ---- > -- > To unsubscribe, e-mail: > For additional commands, e-mail: -- To unsubscribe, e-mail: For additional commands, e-mail: