You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by ro...@apache.org on 2005/07/06 23:34:30 UTC
svn commit: r209516 [3/4] - in
/jakarta/commons/proper/cli/branches/CLI_1_BRANCH: ./ src/conf/
src/java/org/apache/commons/cli/ src/media/
src/test/org/apache/commons/cli/ xdocs/ xdocs/images/ xdocs/style/
Modified: jakarta/commons/proper/cli/branches/CLI_1_BRANCH/src/java/org/apache/commons/cli/OptionBuilder.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/cli/branches/CLI_1_BRANCH/src/java/org/apache/commons/cli/OptionBuilder.java?rev=209516&r1=209515&r2=209516&view=diff
==============================================================================
--- jakarta/commons/proper/cli/branches/CLI_1_BRANCH/src/java/org/apache/commons/cli/OptionBuilder.java (original)
+++ jakarta/commons/proper/cli/branches/CLI_1_BRANCH/src/java/org/apache/commons/cli/OptionBuilder.java Wed Jul 6 14:34:26 2005
@@ -1,112 +1,80 @@
/*
- * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//cli/src/java/org/apache/commons/cli/OptionBuilder.java,v 1.13 2002/11/18 08:41:26 jkeyes Exp $
- * $Revision: 1.13 $
- * $Date$
- *
- * ====================================================================
- *
- * The Apache Software License, Version 1.1
- *
- * Copyright (c) 1999-2001 The Apache Software Foundation. All rights
- * reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * 3. The end-user documentation included with the redistribution, if
- * any, must include the following acknowlegement:
- * "This product includes software developed by the
- * Apache Software Foundation (http://www.apache.org/)."
- * Alternately, this acknowlegement may appear in the software itself,
- * if and wherever such third-party acknowlegements normally appear.
- *
- * 4. The names "The Jakarta Project", "Commons", and "Apache Software
- * Foundation" must not be used to endorse or promote products derived
- * from this software without prior written permission. For written
- * permission, please contact apache@apache.org.
- *
- * 5. Products derived from this software may not be called "Apache"
- * nor may "Apache" appear in their names without prior written
- * permission of the Apache Group.
- *
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
- * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
- * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation. For more
- * information on the Apache Software Foundation, please see
- * <http://www.apache.org/>.
- *
+ * Copyright 1999-2001,2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
*/
-
package org.apache.commons.cli;
/**
* <p>OptionBuilder allows the user to create Options using descriptive
* methods.</p>
* <p>Details on the Builder pattern can be found at
- * <a href="http://c2.com/cgi-bin/wiki?BuilderPattern">http://c2.com/cgi-bin/wiki?BuilderPattern</a>.</p>
+ * <a href="http://c2.com/cgi-bin/wiki?BuilderPattern">
+ * http://c2.com/cgi-bin/wiki?BuilderPattern</a>.</p>
*
- * @author John Keyes ( john at integralsource.com )
+ * @author John Keyes (john at integralsource.com)
* @since 1.0
*/
public class OptionBuilder {
/** long option */
private static String longopt;
+
/** option description */
private static String description;
+
/** argument name */
private static String argName;
+
/** is required? */
private static boolean required;
+
/** the number of arguments */
private static int numberOfArgs = Option.UNINITIALIZED;
+
/** option type */
private static Object type;
+
/** option can have an optional argument value */
private static boolean optionalArg;
+
/** value separator for argument value */
private static char valuesep;
/** option builder instance */
private static OptionBuilder instance = new OptionBuilder();
- // private constructor
- private OptionBuilder() {
+ /**
+ * private constructor to prevent instances being created
+ */
+ private OptionBuilder()
+ {
+ // hide the constructor
}
/**
* <p>Resets the member variables to their default values.</p>
*/
- private static void reset() {
+ private static void reset()
+ {
description = null;
- argName = null;
+ argName = "arg";
longopt = null;
type = null;
required = false;
numberOfArgs = Option.UNINITIALIZED;
+
// PMM 9/6/02 - these were missing
optionalArg = false;
valuesep = (char) 0;
@@ -115,11 +83,13 @@
/**
* <p>The next Option created will have the following long option value.</p>
*
- * @param longopt the long option value
+ * @param newLongopt the long option value
* @return the OptionBuilder instance
*/
- public static OptionBuilder withLongOpt( String longopt ) {
- instance.longopt = longopt;
+ public static OptionBuilder withLongOpt(String newLongopt)
+ {
+ OptionBuilder.longopt = newLongopt;
+
return instance;
}
@@ -128,8 +98,10 @@
*
* @return the OptionBuilder instance
*/
- public static OptionBuilder hasArg( ) {
- instance.numberOfArgs = 1;
+ public static OptionBuilder hasArg()
+ {
+ OptionBuilder.numberOfArgs = 1;
+
return instance;
}
@@ -140,8 +112,10 @@
* @param hasArg if true then the Option has an argument value
* @return the OptionBuilder instance
*/
- public static OptionBuilder hasArg( boolean hasArg ) {
- instance.numberOfArgs = ( hasArg == true ) ? 1 : Option.UNINITIALIZED;
+ public static OptionBuilder hasArg(boolean hasArg)
+ {
+ OptionBuilder.numberOfArgs = (hasArg == true) ? 1 : Option.UNINITIALIZED;
+
return instance;
}
@@ -152,8 +126,10 @@
* @param name the name for the argument value
* @return the OptionBuilder instance
*/
- public static OptionBuilder withArgName( String name ) {
- instance.argName = name;
+ public static OptionBuilder withArgName(String name)
+ {
+ OptionBuilder.argName = name;
+
return instance;
}
@@ -162,8 +138,10 @@
*
* @return the OptionBuilder instance
*/
- public static OptionBuilder isRequired( ) {
- instance.required = true;
+ public static OptionBuilder isRequired()
+ {
+ OptionBuilder.required = true;
+
return instance;
}
@@ -173,18 +151,22 @@
*
* <b>Example:</b>
* <pre>
- * Option opt = OptionBuilder.withValueSeparator( ':' )
- * .create( 'D' );
+ * Option opt = OptionBuilder.withValueSeparator(':')
+ * .create('D');
*
- * CommandLine line = parser.parse( args );
- * String propertyName = opt.getValue( 0 );
- * String propertyValue = opt.getValue( 1 );
+ * CommandLine line = parser.parse(args);
+ * String propertyName = opt.getValue(0);
+ * String propertyValue = opt.getValue(1);
* </pre>
*
+ * @param sep The value separator to be used for the argument values.
+ *
* @return the OptionBuilder instance
*/
- public static OptionBuilder withValueSeparator( char sep ) {
- instance.valuesep = sep;
+ public static OptionBuilder withValueSeparator(char sep)
+ {
+ OptionBuilder.valuesep = sep;
+
return instance;
}
@@ -194,18 +176,20 @@
*
* <b>Example:</b>
* <pre>
- * Option opt = OptionBuilder.withValueSeparator( )
- * .create( 'D' );
+ * Option opt = OptionBuilder.withValueSeparator()
+ * .create('D');
*
- * CommandLine line = parser.parse( args );
- * String propertyName = opt.getValue( 0 );
- * String propertyValue = opt.getValue( 1 );
+ * CommandLine line = parser.parse(args);
+ * String propertyName = opt.getValue(0);
+ * String propertyValue = opt.getValue(1);
* </pre>
*
* @return the OptionBuilder instance
*/
- public static OptionBuilder withValueSeparator( ) {
- instance.valuesep = '=';
+ public static OptionBuilder withValueSeparator()
+ {
+ OptionBuilder.valuesep = '=';
+
return instance;
}
@@ -213,11 +197,13 @@
* <p>The next Option created will be required if <code>required</code>
* is true.</p>
*
- * @param required if true then the Option is required
+ * @param newRequired if true then the Option is required
* @return the OptionBuilder instance
*/
- public static OptionBuilder isRequired( boolean required ) {
- instance.required = required;
+ public static OptionBuilder isRequired(boolean newRequired)
+ {
+ OptionBuilder.required = newRequired;
+
return instance;
}
@@ -226,8 +212,10 @@
*
* @return the OptionBuilder instance
*/
- public static OptionBuilder hasArgs( ) {
- instance.numberOfArgs = Option.UNLIMITED_VALUES;
+ public static OptionBuilder hasArgs()
+ {
+ OptionBuilder.numberOfArgs = Option.UNLIMITED_VALUES;
+
return instance;
}
@@ -238,8 +226,10 @@
* @param num the number of args that the option can have
* @return the OptionBuilder instance
*/
- public static OptionBuilder hasArgs( int num ) {
- instance.numberOfArgs = num;
+ public static OptionBuilder hasArgs(int num)
+ {
+ OptionBuilder.numberOfArgs = num;
+
return instance;
}
@@ -248,9 +238,11 @@
*
* @return the OptionBuilder instance
*/
- public static OptionBuilder hasOptionalArg( ) {
- instance.numberOfArgs = 1;
- instance.optionalArg = true;
+ public static OptionBuilder hasOptionalArg()
+ {
+ OptionBuilder.numberOfArgs = 1;
+ OptionBuilder.optionalArg = true;
+
return instance;
}
@@ -260,9 +252,11 @@
*
* @return the OptionBuilder instance
*/
- public static OptionBuilder hasOptionalArgs( ) {
- instance.numberOfArgs = Option.UNLIMITED_VALUES;
- instance.optionalArg = true;
+ public static OptionBuilder hasOptionalArgs()
+ {
+ OptionBuilder.numberOfArgs = Option.UNLIMITED_VALUES;
+ OptionBuilder.optionalArg = true;
+
return instance;
}
@@ -274,9 +268,11 @@
* the next Option created can have.
* @return the OptionBuilder instance
*/
- public static OptionBuilder hasOptionalArgs( int numArgs ) {
- instance.numberOfArgs = numArgs;
- instance.optionalArg = true;
+ public static OptionBuilder hasOptionalArgs(int numArgs)
+ {
+ OptionBuilder.numberOfArgs = numArgs;
+ OptionBuilder.optionalArg = true;
+
return instance;
}
@@ -284,22 +280,26 @@
* <p>The next Option created will have a value that will be an instance
* of <code>type</code>.</p>
*
- * @param type the type of the Options argument value
+ * @param newType the type of the Options argument value
* @return the OptionBuilder instance
*/
- public static OptionBuilder withType( Object type ) {
- instance.type = type;
+ public static OptionBuilder withType(Object newType)
+ {
+ OptionBuilder.type = newType;
+
return instance;
}
/**
* <p>The next Option created will have the specified description</p>
*
- * @param description a description of the Option's purpose
+ * @param newDescription a description of the Option's purpose
* @return the OptionBuilder instance
*/
- public static OptionBuilder withDescription( String description ) {
- instance.description = description;
+ public static OptionBuilder withDescription(String newDescription)
+ {
+ OptionBuilder.description = newDescription;
+
return instance;
}
@@ -312,10 +312,10 @@
* @throws IllegalArgumentException if <code>opt</code> is not
* a valid character. See Option.
*/
- public static Option create( char opt )
- throws IllegalArgumentException
+ public static Option create(char opt)
+ throws IllegalArgumentException
{
- return create( String.valueOf( opt ) );
+ return create(String.valueOf(opt));
}
/**
@@ -325,14 +325,15 @@
* @throws IllegalArgumentException if <code>longOpt</code> has
* not been set.
*/
- public static Option create()
- throws IllegalArgumentException
+ public static Option create()
+ throws IllegalArgumentException
{
- if( longopt == null ) {
- throw new IllegalArgumentException( "must specify longopt" );
+ if (longopt == null)
+ {
+ throw new IllegalArgumentException("must specify longopt");
}
- return create( null );
+ return create(null);
}
/**
@@ -345,22 +346,25 @@
* @throws IllegalArgumentException if <code>opt</code> is not
* a valid character. See Option.
*/
- public static Option create( String opt )
- throws IllegalArgumentException
+ public static Option create(String opt)
+ throws IllegalArgumentException
{
// create the option
- Option option = new Option( opt, description );
+ Option option = new Option(opt, description);
+
// set the option properties
- option.setLongOpt( longopt );
- option.setRequired( required );
- option.setOptionalArg( optionalArg );
- option.setArgs( numberOfArgs );
- option.setType( type );
- option.setValueSeparator( valuesep );
- option.setArgName( argName );
+ option.setLongOpt(longopt);
+ option.setRequired(required);
+ option.setOptionalArg(optionalArg);
+ option.setArgs(numberOfArgs);
+ option.setType(type);
+ option.setValueSeparator(valuesep);
+ option.setArgName(argName);
+
+
// reset the OptionBuilder properties
- instance.reset();
+ OptionBuilder.reset();
// return the Option instance
return option;
Propchange: jakarta/commons/proper/cli/branches/CLI_1_BRANCH/src/java/org/apache/commons/cli/OptionBuilder.java
------------------------------------------------------------------------------
--- svn:keywords (original)
+++ svn:keywords Wed Jul 6 14:34:26 2005
@@ -1 +1 @@
-author date id revision
+Date Author Id Revision HeadURL
Modified: jakarta/commons/proper/cli/branches/CLI_1_BRANCH/src/java/org/apache/commons/cli/OptionGroup.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/cli/branches/CLI_1_BRANCH/src/java/org/apache/commons/cli/OptionGroup.java?rev=209516&r1=209515&r2=209516&view=diff
==============================================================================
--- jakarta/commons/proper/cli/branches/CLI_1_BRANCH/src/java/org/apache/commons/cli/OptionGroup.java (original)
+++ jakarta/commons/proper/cli/branches/CLI_1_BRANCH/src/java/org/apache/commons/cli/OptionGroup.java Wed Jul 6 14:34:26 2005
@@ -1,64 +1,18 @@
/*
- * $Header: /home/cvs/jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli/OptionGroup.java,v 1.2 2002/06/06 09:37:26 jstrachan Exp $
- * $Revision: 1.2 $
- * $Date: 2002/06/06 09:37:26 $
- *
- * ====================================================================
- *
- * The Apache Software License, Version 1.1
- *
- * Copyright (c) 1999-2001 The Apache Software Foundation. All rights
- * reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * 3. The end-user documentation included with the redistribution, if
- * any, must include the following acknowlegement:
- * "This product includes software developed by the
- * Apache Software Foundation (http://www.apache.org/)."
- * Alternately, this acknowlegement may appear in the software itself,
- * if and wherever such third-party acknowlegements normally appear.
- *
- * 4. The names "The Jakarta Project", "Commons", and "Apache Software
- * Foundation" must not be used to endorse or promote products derived
- * from this software without prior written permission. For written
- * permission, please contact apache@apache.org.
- *
- * 5. Products derived from this software may not be called "Apache"
- * nor may "Apache" appear in their names without prior written
- * permission of the Apache Group.
- *
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
- * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
- * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation. For more
- * information on the Apache Software Foundation, please see
- * <http://www.apache.org/>.
- *
+ * Copyright 1999-2001,2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
*/
-
package org.apache.commons.cli;
import java.util.Collection;
@@ -68,7 +22,7 @@
/**
* A group of mutually exclusive options.
* @author John Keyes ( john at integralsource.com )
- * @version $Revision: 1.2 $
+ * @version $Revision$
*/
public class OptionGroup {
@@ -87,10 +41,12 @@
* @param opt the option to add to this group
* @return this option group with opt added
*/
- public OptionGroup addOption(Option opt) {
+ public OptionGroup addOption(Option opt)
+ {
// key - option name
// value - the option
- optionMap.put( opt.getKey(), opt );
+ optionMap.put(opt.getKey(), opt);
+
return this;
}
@@ -98,7 +54,8 @@
* @return the names of the options in this group as a
* <code>Collection</code>
*/
- public Collection getNames() {
+ public Collection getNames()
+ {
// the key set is the collection of names
return optionMap.keySet();
}
@@ -106,7 +63,8 @@
/**
* @return the options in this group as a <code>Collection</code>
*/
- public Collection getOptions() {
+ public Collection getOptions()
+ {
// the values are the collection of options
return optionMap.values();
}
@@ -117,41 +75,47 @@
* @throws AlreadySelectedException if an option from this group has
* already been selected.
*/
- public void setSelected(Option opt) throws AlreadySelectedException {
+ public void setSelected(Option opt)
+ throws AlreadySelectedException
+ {
// if no option has already been selected or the
// same option is being reselected then set the
// selected member variable
-
- if ( this.selected == null || this.selected.equals( opt.getOpt() ) ) {
+ if ((this.selected == null) || this.selected.equals(opt.getOpt()))
+ {
this.selected = opt.getOpt();
}
- else {
- throw new AlreadySelectedException( "an option from this group has " +
- "already been selected: '" +
- selected + "'");
+ else
+ {
+ throw new AlreadySelectedException("an option from this group has "
+ + "already been selected: '"
+ + selected + "'");
}
}
/**
* @return the selected option name
*/
- public String getSelected() {
+ public String getSelected()
+ {
return selected;
}
/**
* @param required specifies if this group is required
*/
- public void setRequired( boolean required ) {
+ public void setRequired(boolean required)
+ {
this.required = required;
}
/**
* Returns whether this option group is required.
*
- * @returns whether this option group is required
+ * @return whether this option group is required
*/
- public boolean isRequired() {
+ public boolean isRequired()
+ {
return this.required;
}
@@ -159,32 +123,40 @@
* <p>Returns the stringified version of this OptionGroup.</p>
* @return the stringified representation of this group
*/
- public String toString() {
+ public String toString()
+ {
StringBuffer buff = new StringBuffer();
Iterator iter = getOptions().iterator();
- buff.append( "[" );
- while( iter.hasNext() ) {
- Option option = (Option)iter.next();
-
- if( option.getOpt() != null ) {
- buff.append( "-" );
- buff.append( option.getOpt() );
+ buff.append("[");
+
+ while (iter.hasNext())
+ {
+ Option option = (Option) iter.next();
+
+ if (option.getOpt() != null)
+ {
+ buff.append("-");
+ buff.append(option.getOpt());
}
- else {
- buff.append( "--" );
- buff.append( option.getLongOpt() );
+ else
+ {
+ buff.append("--");
+ buff.append(option.getLongOpt());
}
- buff.append( " " );
- buff.append( option.getDescription( ) );
- if( iter.hasNext() ) {
- buff.append( ", " );
+ buff.append(" ");
+ buff.append(option.getDescription());
+
+ if (iter.hasNext())
+ {
+ buff.append(", ");
}
}
- buff.append( "]" );
+
+ buff.append("]");
return buff.toString();
}
-}
+}
\ No newline at end of file
Propchange: jakarta/commons/proper/cli/branches/CLI_1_BRANCH/src/java/org/apache/commons/cli/OptionGroup.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Modified: jakarta/commons/proper/cli/branches/CLI_1_BRANCH/src/java/org/apache/commons/cli/OptionValidator.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/cli/branches/CLI_1_BRANCH/src/java/org/apache/commons/cli/OptionValidator.java?rev=209516&r1=209515&r2=209516&view=diff
==============================================================================
--- jakarta/commons/proper/cli/branches/CLI_1_BRANCH/src/java/org/apache/commons/cli/OptionValidator.java (original)
+++ jakarta/commons/proper/cli/branches/CLI_1_BRANCH/src/java/org/apache/commons/cli/OptionValidator.java Wed Jul 6 14:34:26 2005
@@ -1,62 +1,17 @@
/*
- * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//cli/src/java/org/apache/commons/cli/OptionValidator.java,v 1.1 2002/11/18 08:41:26 jkeyes Exp $
- * $Revision: 1.1 $
- * $Date: 2002/11/18 08:41:26 $
- *
- * ====================================================================
- *
- * The Apache Software License, Version 1.1
- *
- * Copyright (c) 1999-2001 The Apache Software Foundation. All rights
- * reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * 3. The end-user documentation included with the redistribution, if
- * any, must include the following acknowlegement:
- * "This product includes software developed by the
- * Apache Software Foundation (http://www.apache.org/)."
- * Alternately, this acknowlegement may appear in the software itself,
- * if and wherever such third-party acknowlegements normally appear.
- *
- * 4. The names "The Jakarta Project", "Commons", and "Apache Software
- * Foundation" must not be used to endorse or promote products derived
- * from this software without prior written permission. For written
- * permission, please contact apache@apache.org.
- *
- * 5. Products derived from this software may not be called "Apache"
- * nor may "Apache" appear in their names without prior written
- * permission of the Apache Group.
- *
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
- * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
- * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation. For more
- * information on the Apache Software Foundation, please see
- * <http://www.apache.org/>.
- *
+ * Copyright 1999-2001,2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
*/
package org.apache.commons.cli;
@@ -82,27 +37,39 @@
* @param opt The option string to validate
* @throws IllegalArgumentException if the Option is not valid.
*/
- static void validateOption( String opt )
- throws IllegalArgumentException
+ static void validateOption(String opt)
+ throws IllegalArgumentException
{
// check that opt is not NULL
- if( opt == null ) {
+ if (opt == null)
+ {
return;
}
+
// handle the single character opt
- else if( opt.length() == 1 ) {
- char ch = opt.charAt( 0 );
- if ( !isValidOpt( ch ) ) {
- throw new IllegalArgumentException( "illegal option value '"
- + ch + "'" );
+ else if (opt.length() == 1)
+ {
+ char ch = opt.charAt(0);
+
+ if (!isValidOpt(ch))
+ {
+ throw new IllegalArgumentException("illegal option value '" + ch
+ + "'");
}
}
+
// handle the multi character opt
- else {
+ else
+ {
char[] chars = opt.toCharArray();
- for( int i = 0; i < chars.length; i++ ) {
- if( !isValidChar( chars[i] ) ) {
- throw new IllegalArgumentException( "opt contains illegal character value '" + chars[i] + "'" );
+
+ for (int i = 0; i < chars.length; i++)
+ {
+ if (!isValidChar(chars[i]))
+ {
+ throw new IllegalArgumentException(
+ "opt contains illegal character value '" + chars[i]
+ + "'");
}
}
}
@@ -112,10 +79,12 @@
* <p>Returns whether the specified character is a valid Option.</p>
*
* @param c the option to validate
- * @return true if <code>c</code> is a letter, ' ', '?' or '@', otherwise false.
+ * @return true if <code>c</code> is a letter, ' ', '?' or '@',
+ * otherwise false.
*/
- private static boolean isValidOpt( char c ) {
- return ( isValidChar( c ) || c == ' ' || c == '?' || c == '@' );
+ private static boolean isValidOpt(char c)
+ {
+ return (isValidChar(c) || (c == ' ') || (c == '?') || c == '@');
}
/**
@@ -124,7 +93,8 @@
* @param c the character to validate
* @return true if <code>c</code> is a letter.
*/
- private static boolean isValidChar( char c ) {
- return Character.isJavaIdentifierPart( c );
+ private static boolean isValidChar(char c)
+ {
+ return Character.isJavaIdentifierPart(c);
}
}
Propchange: jakarta/commons/proper/cli/branches/CLI_1_BRANCH/src/java/org/apache/commons/cli/OptionValidator.java
------------------------------------------------------------------------------
--- svn:keywords (original)
+++ svn:keywords Wed Jul 6 14:34:26 2005
@@ -1 +1 @@
-author date id revision
+Date Author Id Revision HeadURL
Modified: jakarta/commons/proper/cli/branches/CLI_1_BRANCH/src/java/org/apache/commons/cli/Options.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/cli/branches/CLI_1_BRANCH/src/java/org/apache/commons/cli/Options.java?rev=209516&r1=209515&r2=209516&view=diff
==============================================================================
--- jakarta/commons/proper/cli/branches/CLI_1_BRANCH/src/java/org/apache/commons/cli/Options.java (original)
+++ jakarta/commons/proper/cli/branches/CLI_1_BRANCH/src/java/org/apache/commons/cli/Options.java Wed Jul 6 14:34:26 2005
@@ -1,64 +1,18 @@
/*
- * $Header: /home/cvs/jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli/Options.java,v 1.5 2002/06/06 22:32:37 bayard Exp $
- * $Revision: 1.5 $
- * $Date: 2002/06/06 22:32:37 $
- *
- * ====================================================================
- *
- * The Apache Software License, Version 1.1
- *
- * Copyright (c) 1999-2001 The Apache Software Foundation. All rights
- * reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * 3. The end-user documentation included with the redistribution, if
- * any, must include the following acknowlegement:
- * "This product includes software developed by the
- * Apache Software Foundation (http://www.apache.org/)."
- * Alternately, this acknowlegement may appear in the software itself,
- * if and wherever such third-party acknowlegements normally appear.
- *
- * 4. The names "The Jakarta Project", "Commons", and "Apache Software
- * Foundation" must not be used to endorse or promote products derived
- * from this software without prior written permission. For written
- * permission, please contact apache@apache.org.
- *
- * 5. Products derived from this software may not be called "Apache"
- * nor may "Apache" appear in their names without prior written
- * permission of the Apache Group.
- *
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
- * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
- * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation. For more
- * information on the Apache Software Foundation, please see
- * <http://www.apache.org/>.
- *
+ * Copyright 1999-2001,2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
*/
-
package org.apache.commons.cli;
import java.util.ArrayList;
@@ -68,7 +22,6 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
-import java.util.*;
/** <p>Main entry-point into the library.</p>
*
@@ -83,25 +36,27 @@
*
* @author bob mcwhirter (bob @ werken.com)
* @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
- * @version $Revision: 1.5 $
+ * @version $Revision$
*/
public class Options {
/** a map of the options with the character key */
- private Map shortOpts = new HashMap();
+ private Map shortOpts = new HashMap();
/** a map of the options with the long key */
- private Map longOpts = new HashMap();
+ private Map longOpts = new HashMap();
/** a map of the required options */
private List requiredOpts = new ArrayList();
-
+
/** a map of the option groups */
- private Map optionGroups = new HashMap();
+ private Map optionGroups = new HashMap();
/** <p>Construct a new Options descriptor</p>
*/
- public Options() {
+ public Options()
+ {
+ // nothing to do
}
/**
@@ -110,22 +65,27 @@
* @param group the OptionGroup that is to be added
* @return the resulting Options instance
*/
- public Options addOptionGroup( OptionGroup group ) {
+ public Options addOptionGroup(OptionGroup group)
+ {
Iterator options = group.getOptions().iterator();
- if( group.isRequired() ) {
- requiredOpts.add( group );
+ if (group.isRequired())
+ {
+ requiredOpts.add(group);
}
- while( options.hasNext() ) {
- Option option = (Option)options.next();
+ while (options.hasNext())
+ {
+ Option option = (Option) options.next();
+
+
// an Option cannot be required if it is in an
// OptionGroup, either the group is required or
// nothing is required
- option.setRequired( false );
- addOption( option );
+ option.setRequired(false);
+ addOption(option);
- optionGroups.put( option.getKey(), group );
+ optionGroups.put(option.getKey(), group);
}
return this;
@@ -139,11 +99,13 @@
* @param description Self-documenting description
* @return the resulting Options instance
*/
- public Options addOption(String opt, boolean hasArg, String description) {
- addOption( opt, null, hasArg, description );
+ public Options addOption(String opt, boolean hasArg, String description)
+ {
+ addOption(opt, null, hasArg, description);
+
return this;
}
-
+
/** <p>Add an option that contains a short-name and a long-name</p>
* <p>It may be specified as requiring an argument.</p>
*
@@ -153,8 +115,11 @@
* @param description Self-documenting description
* @return the resulting Options instance
*/
- public Options addOption(String opt, String longOpt, boolean hasArg, String description) {
- addOption( new Option( opt, longOpt, hasArg, description ) );
+ public Options addOption(String opt, String longOpt, boolean hasArg,
+ String description)
+ {
+ addOption(new Option(opt, longOpt, hasArg, description));
+
return this;
}
@@ -164,30 +129,37 @@
* @param opt the option that is to be added
* @return the resulting Options instance
*/
- public Options addOption(Option opt) {
- String shortOpt = opt.getOpt();
-
+ public Options addOption(Option opt)
+ {
+ String key = opt.getKey();
+
// add it to the long option list
- if ( opt.hasLongOpt() ) {
- longOpts.put( opt.getLongOpt(), opt );
+ if (opt.hasLongOpt())
+ {
+ longOpts.put(opt.getLongOpt(), opt);
}
-
+
// if the option is required add it to the required list
- if ( opt.isRequired() ) {
- requiredOpts.add( opt.getKey() );
+ if (opt.isRequired() )
+ {
+ if( requiredOpts.contains(key) ) {
+ requiredOpts.remove( requiredOpts.indexOf(key) );
+ }
+ requiredOpts.add(key);
}
- shortOpts.put( shortOpt, opt );
-
+ shortOpts.put(key, opt);
+
return this;
}
-
+
/** <p>Retrieve a read-only list of options in this set</p>
*
* @return read-only Collection of {@link Option} objects in this descriptor
*/
- public Collection getOptions() {
- return Collections.unmodifiableCollection( helpOptions() );
+ public Collection getOptions()
+ {
+ return Collections.unmodifiableCollection(helpOptions());
}
/**
@@ -195,21 +167,25 @@
*
* @return the List of Options
*/
- List helpOptions() {
- List opts = new ArrayList( shortOpts.values() );
+ List helpOptions()
+ {
+ List opts = new ArrayList(shortOpts.values());
// now look through the long opts to see if there are any Long-opt
// only options
Iterator iter = longOpts.values().iterator();
+
while (iter.hasNext())
{
Object item = iter.next();
+
if (!opts.contains(item))
{
opts.add(item);
}
}
- return new ArrayList( opts );
+
+ return new ArrayList(opts);
}
/** <p>Returns the required options as a
@@ -217,23 +193,26 @@
*
* @return Collection of required options
*/
- public List getRequiredOptions() {
+ public List getRequiredOptions()
+ {
return requiredOpts;
}
-
+
/** <p>Retrieve the named {@link Option}</p>
*
* @param opt short or long name of the {@link Option}
* @return the option represented by opt
*/
- public Option getOption( String opt ) {
-
- opt = Util.stripLeadingHyphens( opt );
+ public Option getOption(String opt)
+ {
+ opt = Util.stripLeadingHyphens(opt);
- if( shortOpts.containsKey( opt ) ) {
- return (Option) shortOpts.get( opt );
+ if (shortOpts.containsKey(opt))
+ {
+ return (Option) shortOpts.get(opt);
}
- return (Option) longOpts.get( opt );
+
+ return (Option) longOpts.get(opt);
}
/**
@@ -244,9 +223,11 @@
* @return true if the named {@link Option} is a member
* of this {@link Options}
*/
- public boolean hasOption( String opt ) {
- opt = Util.stripLeadingHyphens( opt );
- return shortOpts.containsKey( opt ) || longOpts.containsKey( opt );
+ public boolean hasOption(String opt)
+ {
+ opt = Util.stripLeadingHyphens(opt);
+
+ return shortOpts.containsKey(opt) || longOpts.containsKey(opt);
}
/** <p>Returns the OptionGroup the <code>opt</code>
@@ -256,23 +237,25 @@
* @return the OptionGroup if <code>opt</code> is part
* of an OptionGroup, otherwise return null
*/
- public OptionGroup getOptionGroup( Option opt ) {
- return (OptionGroup)optionGroups.get( opt.getKey() );
+ public OptionGroup getOptionGroup(Option opt)
+ {
+ return (OptionGroup) optionGroups.get(opt.getKey());
}
-
+
/** <p>Dump state, suitable for debugging.</p>
*
* @return Stringified form of this object
*/
- public String toString() {
+ public String toString()
+ {
StringBuffer buf = new StringBuffer();
-
+
buf.append("[ Options: [ short ");
- buf.append( shortOpts.toString() );
- buf.append( " ] [ long " );
- buf.append( longOpts );
- buf.append( " ]");
-
+ buf.append(shortOpts.toString());
+ buf.append(" ] [ long ");
+ buf.append(longOpts);
+ buf.append(" ]");
+
return buf.toString();
}
-}
+}
\ No newline at end of file
Propchange: jakarta/commons/proper/cli/branches/CLI_1_BRANCH/src/java/org/apache/commons/cli/Options.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Modified: jakarta/commons/proper/cli/branches/CLI_1_BRANCH/src/java/org/apache/commons/cli/ParseException.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/cli/branches/CLI_1_BRANCH/src/java/org/apache/commons/cli/ParseException.java?rev=209516&r1=209515&r2=209516&view=diff
==============================================================================
--- jakarta/commons/proper/cli/branches/CLI_1_BRANCH/src/java/org/apache/commons/cli/ParseException.java (original)
+++ jakarta/commons/proper/cli/branches/CLI_1_BRANCH/src/java/org/apache/commons/cli/ParseException.java Wed Jul 6 14:34:26 2005
@@ -1,82 +1,36 @@
/*
- * $Header: /home/cvs/jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli/ParseException.java,v 1.2 2002/06/06 09:37:26 jstrachan Exp $
- * $Revision: 1.2 $
- * $Date: 2002/06/06 09:37:26 $
- *
- * ====================================================================
- *
- * The Apache Software License, Version 1.1
- *
- * Copyright (c) 1999-2001 The Apache Software Foundation. All rights
- * reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * 3. The end-user documentation included with the redistribution, if
- * any, must include the following acknowlegement:
- * "This product includes software developed by the
- * Apache Software Foundation (http://www.apache.org/)."
- * Alternately, this acknowlegement may appear in the software itself,
- * if and wherever such third-party acknowlegements normally appear.
- *
- * 4. The names "The Jakarta Project", "Commons", and "Apache Software
- * Foundation" must not be used to endorse or promote products derived
- * from this software without prior written permission. For written
- * permission, please contact apache@apache.org.
- *
- * 5. Products derived from this software may not be called "Apache"
- * nor may "Apache" appear in their names without prior written
- * permission of the Apache Group.
- *
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
- * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
- * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation. For more
- * information on the Apache Software Foundation, please see
- * <http://www.apache.org/>.
- *
+ * Copyright 1999-2001,2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
*/
-
package org.apache.commons.cli;
/**
* <p>Base for Exceptions thrown during parsing of a command-line.</p>
*
* @author bob mcwhirter (bob @ werken.com)
- * @version $Revision: 1.2 $
+ * @version $Revision$
*/
-public class ParseException extends Exception
-{
-
+public class ParseException extends Exception {
+
/**
* <p>Construct a new <code>ParseException</code>
* with the specified detail message.</p>
*
* @param message the detail message
*/
- public ParseException( String message ) {
- super( message );
+ public ParseException(String message)
+ {
+ super(message);
}
-}
+}
\ No newline at end of file
Propchange: jakarta/commons/proper/cli/branches/CLI_1_BRANCH/src/java/org/apache/commons/cli/ParseException.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Modified: jakarta/commons/proper/cli/branches/CLI_1_BRANCH/src/java/org/apache/commons/cli/Parser.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/cli/branches/CLI_1_BRANCH/src/java/org/apache/commons/cli/Parser.java?rev=209516&r1=209515&r2=209516&view=diff
==============================================================================
--- jakarta/commons/proper/cli/branches/CLI_1_BRANCH/src/java/org/apache/commons/cli/Parser.java (original)
+++ jakarta/commons/proper/cli/branches/CLI_1_BRANCH/src/java/org/apache/commons/cli/Parser.java Wed Jul 6 14:34:26 2005
@@ -1,64 +1,18 @@
/*
- * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//cli/src/java/org/apache/commons/cli/Parser.java,v 1.8 2002/11/18 08:41:26 jkeyes Exp $
- * $Revision: 1.8 $
- * $Date$
- *
- * ====================================================================
- *
- * The Apache Software License, Version 1.1
- *
- * Copyright (c) 1999-2001 The Apache Software Foundation. All rights
- * reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * 3. The end-user documentation included with the redistribution, if
- * any, must include the following acknowlegement:
- * "This product includes software developed by the
- * Apache Software Foundation (http://www.apache.org/)."
- * Alternately, this acknowlegement may appear in the software itself,
- * if and wherever such third-party acknowlegements normally appear.
- *
- * 4. The names "The Jakarta Project", "Commons", and "Apache Software
- * Foundation" must not be used to endorse or promote products derived
- * from this software without prior written permission. For written
- * permission, please contact apache@apache.org.
- *
- * 5. Products derived from this software may not be called "Apache"
- * nor may "Apache" appear in their names without prior written
- * permission of the Apache Group.
- *
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
- * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
- * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation. For more
- * information on the Apache Software Foundation, please see
- * <http://www.apache.org/>.
- *
+ * Copyright 1999-2001,2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
*/
-
package org.apache.commons.cli;
import java.util.Arrays;
@@ -66,7 +20,6 @@
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
-import java.util.Map;
import java.util.Properties;
/**
@@ -74,14 +27,16 @@
*
* @author John Keyes (john at integralsource.com)
* @see Parser
- * @version $Revision: 1.8 $
+ * @version $Revision$
*/
public abstract class Parser implements CommandLineParser {
/** commandline instance */
private CommandLine cmd;
+
/** current Options */
private Options options;
+
/** list of required options strings */
private List requiredOptions;
@@ -91,14 +46,13 @@
* method.</p>
*
* @param opts The Options to parse the arguments by.
- * @param args The arguments that have to be flattened.
+ * @param arguments The arguments that have to be flattened.
* @param stopAtNonOption specifies whether to stop
* flattening when a non option has been encountered
* @return a String array of the flattened arguments
*/
- abstract protected String[] flatten( Options opts,
- String[] arguments,
- boolean stopAtNonOption );
+ protected abstract String[] flatten(Options opts, String[] arguments,
+ boolean stopAtNonOption);
/**
* <p>Parses the specified <code>arguments</code>
@@ -110,11 +64,10 @@
* @throws ParseException if an error occurs when parsing the
* arguments.
*/
- public CommandLine parse( Options options,
- String[] arguments )
- throws ParseException
+ public CommandLine parse(Options options, String[] arguments)
+ throws ParseException
{
- return parse( options, arguments, null, false );
+ return parse(options, arguments, null, false);
}
/**
@@ -129,12 +82,11 @@
* @throws ParseException if there are any problems encountered
* while parsing the command line tokens.
*/
- public CommandLine parse( Options options,
- String[] arguments,
- Properties properties )
- throws ParseException
+ public CommandLine parse(Options options, String[] arguments,
+ Properties properties)
+ throws ParseException
{
- return parse( options, arguments, properties, false );
+ return parse(options, arguments, properties, false);
}
/**
@@ -152,12 +104,11 @@
* @throws ParseException if an error occurs when parsing the
* arguments.
*/
- public CommandLine parse( Options options,
- String[] arguments,
- boolean stopAtNonOption )
- throws ParseException
+ public CommandLine parse(Options options, String[] arguments,
+ boolean stopAtNonOption)
+ throws ParseException
{
- return parse( options, arguments, null, stopAtNonOption );
+ return parse(options, arguments, null, stopAtNonOption);
}
/**
@@ -167,98 +118,156 @@
* @param options the specified Options
* @param arguments the command line arguments
* @param properties command line option name-value pairs
+ * @param stopAtNonOption stop parsing the arguments when the first
+ * non option is encountered.
+ *
* @return the list of atomic option and value tokens
*
* @throws ParseException if there are any problems encountered
* while parsing the command line tokens.
*/
- public CommandLine parse( Options opts,
- String[] arguments,
- Properties properties,
- boolean stopAtNonOption )
- throws ParseException
+ public CommandLine parse(Options options, String[] arguments,
+ Properties properties, boolean stopAtNonOption)
+ throws ParseException
{
// initialise members
- options = opts;
+ this.options = options;
requiredOptions = options.getRequiredOptions();
cmd = new CommandLine();
boolean eatTheRest = false;
- if( arguments == null ) {
+ if (arguments == null)
+ {
arguments = new String[0];
}
- List tokenList = Arrays.asList( flatten( opts, arguments, stopAtNonOption ) );
+ List tokenList = Arrays.asList(flatten(this.options,
+ arguments,
+ stopAtNonOption));
+
ListIterator iterator = tokenList.listIterator();
// process each flattened token
- while( iterator.hasNext() ) {
- String t = (String)iterator.next();
+ while (iterator.hasNext())
+ {
+ String t = (String) iterator.next();
// the value is the double-dash
- if( "--".equals( t ) ) {
+ if ("--".equals(t))
+ {
eatTheRest = true;
}
+
// the value is a single dash
- else if( "-".equals( t ) ) {
- if( stopAtNonOption ) {
+ else if ("-".equals(t))
+ {
+ if (stopAtNonOption)
+ {
eatTheRest = true;
}
- else {
- cmd.addArg(t );
+ else
+ {
+ cmd.addArg(t);
}
}
+
// the value is an option
- else if( t.startsWith( "-" ) ) {
- if ( stopAtNonOption && !options.hasOption( t ) ) {
+ else if (t.startsWith("-"))
+ {
+ if (stopAtNonOption && !options.hasOption(t))
+ {
eatTheRest = true;
- cmd.addArg( t );
+ cmd.addArg(t);
}
- else {
- processOption( t, iterator );
+ else
+ {
+ processOption(t, iterator);
}
}
+
// the value is an argument
- else {
- cmd.addArg( t );
- if( stopAtNonOption ) {
+ else
+ {
+ cmd.addArg(t);
+
+ if (stopAtNonOption)
+ {
eatTheRest = true;
}
}
// eat the remaining tokens
- if( eatTheRest ) {
- while( iterator.hasNext() ) {
- String str = (String)iterator.next();
+ if (eatTheRest)
+ {
+ while (iterator.hasNext())
+ {
+ String str = (String) iterator.next();
+
// ensure only one double-dash is added
- if( !"--".equals( str ) ) {
- cmd.addArg( str );
+ if (!"--".equals(str))
+ {
+ cmd.addArg(str);
}
}
}
}
- processProperties( properties );
+
+ processProperties(properties);
checkRequiredOptions();
+
return cmd;
}
/**
- * <p>Sets the values of Options using the values in <code>properties</code>.</p>
+ * <p>Sets the values of Options using the values in
+ * <code>properties</code>.</p>
+ *
+ * @param properties The value properties to be processed.
*/
- private void processProperties( Properties properties ) {
- if( properties == null ) {
+ private void processProperties(Properties properties)
+ {
+ if (properties == null)
+ {
return;
}
- for( Enumeration e = properties.propertyNames(); e.hasMoreElements(); ) {
+ for (Enumeration e = properties.propertyNames(); e.hasMoreElements();)
+ {
String option = e.nextElement().toString();
- if( !cmd.hasOption( option ) ) {
- Option opt = options.getOption( option );
- if( opt.getValues() == null || opt.getValues().length == 0 ) {
- opt.addValue( properties.getProperty( option ) );
+
+ if (!cmd.hasOption(option))
+ {
+ Option opt = options.getOption(option);
+
+ // get the value from the properties instance
+ String value = properties.getProperty(option);
+
+ if (opt.hasArg())
+ {
+ if ((opt.getValues() == null)
+ || (opt.getValues().length == 0))
+ {
+ try
+ {
+ opt.addValue(value);
+ }
+ catch (RuntimeException exp)
+ {
+ // if we cannot add the value don't worry about it
+ }
+ }
}
- cmd.addOption( opt );
+ else if (!("yes".equalsIgnoreCase(value)
+ || "true".equalsIgnoreCase(value)
+ || "1".equalsIgnoreCase(value)))
+ {
+ // if the value is not yes, true or 1 then don't add the
+ // option to the CommandLine
+ break;
+ }
+
+ cmd.addOption(opt);
}
}
}
@@ -266,88 +275,132 @@
/**
* <p>Throws a {@link MissingOptionException} if all of the
* required options are no present.</p>
+ *
+ * @throws MissingOptionException if any of the required Options
+ * are not present.
*/
private void checkRequiredOptions()
- throws MissingOptionException
+ throws MissingOptionException
{
-
// if there are required options that have not been
// processsed
- if( requiredOptions.size() > 0 ) {
+ if (requiredOptions.size() > 0)
+ {
Iterator iter = requiredOptions.iterator();
StringBuffer buff = new StringBuffer();
// loop through the required options
- while( iter.hasNext() ) {
- buff.append( iter.next() );
+ while (iter.hasNext())
+ {
+ buff.append(iter.next());
}
- throw new MissingOptionException( buff.toString() );
+ throw new MissingOptionException(buff.toString());
}
}
- public void processArgs( Option opt, ListIterator iter )
- throws ParseException
+ /**
+ * <p>Process the argument values for the specified Option
+ * <code>opt</code> using the values retrieved from the
+ * specified iterator <code>iter</code>.
+ *
+ * @param opt The current Option
+ * @param iter The iterator over the flattened command line
+ * Options.
+ *
+ * @throws ParseException if an argument value is required
+ * and it is has not been found.
+ */
+ public void processArgs(Option opt, ListIterator iter)
+ throws ParseException
{
// loop until an option is found
- while( iter.hasNext() ) {
- String str = (String)iter.next();
-
- // found an Option
- if( options.hasOption( str ) ) {
+ while (iter.hasNext())
+ {
+ String str = (String) iter.next();
+
+ // found an Option, not an argument
+ if (options.hasOption(str) && str.startsWith("-"))
+ {
iter.previous();
break;
}
+
// found a value
- else if( !opt.addValue( str ) ) {
+ try
+ {
+ opt.addValue( Util.stripLeadingAndTrailingQuotes(str) );
+ }
+ catch (RuntimeException exp)
+ {
iter.previous();
break;
}
}
- if( opt.getValues() == null && !opt.hasOptionalArg() ) {
- throw new MissingArgumentException( "no argument for:" + opt.getKey() );
+ if ((opt.getValues() == null) && !opt.hasOptionalArg())
+ {
+ throw new MissingArgumentException("no argument for:"
+ + opt.getKey());
}
}
- private void processOption( String arg, ListIterator iter )
- throws ParseException
+ /**
+ * <p>Process the Option specified by <code>arg</code>
+ * using the values retrieved from the specfied iterator
+ * <code>iter</code>.
+ *
+ * @param arg The String value representing an Option
+ * @param iter The iterator over the flattened command
+ * line arguments.
+ *
+ * @throws ParseException if <code>arg</code> does not
+ * represent an Option
+ */
+ private void processOption(String arg, ListIterator iter)
+ throws ParseException
{
- // get the option represented by arg
- Option opt = null;
-
- boolean hasOption = options.hasOption( arg );
+ boolean hasOption = options.hasOption(arg);
// if there is no option throw an UnrecognisedOptionException
- if( !hasOption ) {
- throw new UnrecognizedOptionException("Unrecognized option: " + arg);
- }
- else {
- opt = (Option) options.getOption( arg );
+ if (!hasOption)
+ {
+ throw new UnrecognizedOptionException("Unrecognized option: "
+ + arg);
}
+
+ // get the option represented by arg
+ final Option opt = options.getOption(arg);
// if the option is a required option remove the option from
// the requiredOptions list
- if ( opt.isRequired() ) {
- requiredOptions.remove( opt.getKey() );
+ if (opt.isRequired())
+ {
+ requiredOptions.remove(opt.getKey());
}
// if the option is in an OptionGroup make that option the selected
// option of the group
- if ( options.getOptionGroup( opt ) != null ) {
- OptionGroup group = ( OptionGroup ) options.getOptionGroup( opt );
- if( group.isRequired() ) {
- requiredOptions.remove( group );
+ if (options.getOptionGroup(opt) != null)
+ {
+ OptionGroup group = options.getOptionGroup(opt);
+
+ if (group.isRequired())
+ {
+ requiredOptions.remove(group);
}
- group.setSelected( opt );
+
+ group.setSelected(opt);
}
// if the option takes an argument value
- if ( opt.hasArg() ) {
- processArgs( opt, iter );
+ if (opt.hasArg())
+ {
+ processArgs(opt, iter);
}
+
// set the option on the command line
- cmd.addOption( opt );
+ cmd.addOption(opt);
}
}
Propchange: jakarta/commons/proper/cli/branches/CLI_1_BRANCH/src/java/org/apache/commons/cli/Parser.java
------------------------------------------------------------------------------
--- svn:keywords (original)
+++ svn:keywords Wed Jul 6 14:34:26 2005
@@ -1 +1 @@
-author date id revision
+Date Author Id Revision HeadURL
Modified: jakarta/commons/proper/cli/branches/CLI_1_BRANCH/src/java/org/apache/commons/cli/PatternOptionBuilder.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/cli/branches/CLI_1_BRANCH/src/java/org/apache/commons/cli/PatternOptionBuilder.java?rev=209516&r1=209515&r2=209516&view=diff
==============================================================================
--- jakarta/commons/proper/cli/branches/CLI_1_BRANCH/src/java/org/apache/commons/cli/PatternOptionBuilder.java (original)
+++ jakarta/commons/proper/cli/branches/CLI_1_BRANCH/src/java/org/apache/commons/cli/PatternOptionBuilder.java Wed Jul 6 14:34:26 2005
@@ -1,99 +1,82 @@
/*
- * $Header: /home/cvs/jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli/PatternOptionBuilder.java,v 1.2 2002/06/06 22:49:36 bayard Exp $
- * $Revision: 1.2 $
- * $Date: 2002/06/06 22:49:36 $
- *
- * ====================================================================
- *
- * The Apache Software License, Version 1.1
- *
- * Copyright (c) 1999-2001 The Apache Software Foundation. All rights
- * reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * 3. The end-user documentation included with the redistribution, if
- * any, must include the following acknowlegement:
- * "This product includes software developed by the
- * Apache Software Foundation (http://www.apache.org/)."
- * Alternately, this acknowlegement may appear in the software itself,
- * if and wherever such third-party acknowlegements normally appear.
- *
- * 4. The names "The Jakarta Project", "Commons", and "Apache Software
- * Foundation" must not be used to endorse or promote products derived
- * from this software without prior written permission. For written
- * permission, please contact apache@apache.org.
- *
- * 5. Products derived from this software may not be called "Apache"
- * nor may "Apache" appear in their names without prior written
- * permission of the Apache Group.
- *
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
- * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
- * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation. For more
- * information on the Apache Software Foundation, please see
- * <http://www.apache.org/>.
- *
+ * Copyright 1999-2001,2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
*/
-
package org.apache.commons.cli;
/**
+ * <p>
* Allows Options to be created from a single String.
- *
+ * The pattern contains various single character flags and via
+ * an optional punctuation character, their expected type.
+ * </p>
+ *
+ * <table border="1">
+ * <tr><td>a</td><td>-a flag</td></tr>
+ * <tr><td>b@</td><td>-b [classname]</td></tr>
+ * <tr><td>c></td><td>-c [filename]</td></tr>
+ * <tr><td>d+</td><td>-d [classname] (creates object via empty contructor)</td></tr>
+ * <tr><td>e%</td><td>-e [number] (creates Number instance)</td></tr>
+ * <tr><td>f/</td><td>-f [url]</td></tr>
+ * </table>
+ *
+ * <p>
+ * For example, the following allows command line flags of '-v -p string-value -f /dir/file'.
+ * </p>
+ * <code>Options options = PatternOptionBuilder.parsePattern("vp:f/");</code>
+ *
+ * <p>
+ * TODO These need to break out to OptionType and also
+ * to be pluggable.
+ * </p>
*
* @author Henri Yandell (bayard @ generationjava.com)
- * @version $Revision: 1.2 $
+ * @version $Revision$
*/
public class PatternOptionBuilder {
- /// TODO: These need to break out to OptionType and also to be pluggable.
-
/** String class */
- public static final Class STRING_VALUE = java.lang.String.class;
+ public static final Class STRING_VALUE = java.lang.String.class;
+
/** Object class */
- public static final Class OBJECT_VALUE = java.lang.Object.class;
+ public static final Class OBJECT_VALUE = java.lang.Object.class;
+
/** Number class */
- public static final Class NUMBER_VALUE = java.lang.Number.class;
+ public static final Class NUMBER_VALUE = java.lang.Number.class;
+
/** Date class */
- public static final Class DATE_VALUE = java.util.Date.class;
+ public static final Class DATE_VALUE = java.util.Date.class;
+
/** Class class */
- public static final Class CLASS_VALUE = java.lang.Class.class;
+ public static final Class CLASS_VALUE = java.lang.Class.class;
+
+ /// can we do this one??
+ // is meant to check that the file exists, else it errors.
+ // ie) it's for reading not writing.
-/// can we do this one??
-// is meant to check that the file exists, else it errors.
-// ie) it's for reading not writing.
/** FileInputStream class */
- public static final Class EXISTING_FILE_VALUE = java.io.FileInputStream.class;
+ public static final Class EXISTING_FILE_VALUE =
+ java.io.FileInputStream.class;
+
/** File class */
- public static final Class FILE_VALUE = java.io.File.class;
+ public static final Class FILE_VALUE = java.io.File.class;
+
/** File array class */
- public static final Class FILES_VALUE = java.io.File[].class;
+ public static final Class FILES_VALUE = java.io.File[].class;
+
/** URL class */
- public static final Class URL_VALUE = java.net.URL.class;
+ public static final Class URL_VALUE = java.net.URL.class;
/**
* <p>Retrieve the class that <code>ch</code> represents.</p>
@@ -101,29 +84,48 @@
* @param ch the specified character
* @return The class that <code>ch</code> represents
*/
- public static Object getValueClass(char ch) {
- if (ch == '@') {
+ public static Object getValueClass(char ch)
+ {
+ if (ch == '@')
+ {
return PatternOptionBuilder.OBJECT_VALUE;
- } else if (ch == ':') {
+ }
+ else if (ch == ':')
+ {
return PatternOptionBuilder.STRING_VALUE;
- } else if (ch == '%') {
+ }
+ else if (ch == '%')
+ {
return PatternOptionBuilder.NUMBER_VALUE;
- } else if (ch == '+') {
+ }
+ else if (ch == '+')
+ {
return PatternOptionBuilder.CLASS_VALUE;
- } else if (ch == '#') {
+ }
+ else if (ch == '#')
+ {
return PatternOptionBuilder.DATE_VALUE;
- } else if (ch == '<') {
+ }
+ else if (ch == '<')
+ {
return PatternOptionBuilder.EXISTING_FILE_VALUE;
- } else if (ch == '>') {
+ }
+ else if (ch == '>')
+ {
return PatternOptionBuilder.FILE_VALUE;
- } else if (ch == '*') {
+ }
+ else if (ch == '*')
+ {
return PatternOptionBuilder.FILES_VALUE;
- } else if (ch == '/') {
+ }
+ else if (ch == '/')
+ {
return PatternOptionBuilder.URL_VALUE;
}
+
return null;
}
-
+
/**
* <p>Returns whether <code>ch</code> is a value code, i.e.
* whether it represents a class in a pattern.</p>
@@ -131,23 +133,18 @@
* @param ch the specified character
* @return true if <code>ch</code> is a value code, otherwise false.
*/
- public static boolean isValueCode(char ch) {
- if( (ch != '@') &&
- (ch != ':') &&
- (ch != '%') &&
- (ch != '+') &&
- (ch != '#') &&
- (ch != '<') &&
- (ch != '>') &&
- (ch != '*') &&
- (ch != '/')
- )
+ public static boolean isValueCode(char ch)
+ {
+ if ((ch != '@') && (ch != ':') && (ch != '%') && (ch != '+')
+ && (ch != '#') && (ch != '<') && (ch != '>') && (ch != '*')
+ && (ch != '/') && (ch != '!'))
{
return false;
}
+
return true;
- }
-
+ }
+
/**
* <p>Returns the {@link Options} instance represented by
* <code>pattern</code>.</p>
@@ -155,7 +152,8 @@
* @param pattern the pattern string
* @return The {@link Options} instance
*/
- public static Options parsePattern(String pattern) {
+ public static Options parsePattern(String pattern)
+ {
int sz = pattern.length();
char opt = ' ';
@@ -164,41 +162,50 @@
Object type = null;
Options options = new Options();
-
- for(int i=0; i<sz; i++) {
+
+ for (int i = 0; i < sz; i++)
+ {
ch = pattern.charAt(i);
// a value code comes after an option and specifies
// details about it
- if(!isValueCode(ch)) {
- if(opt != ' ') {
+ if (!isValueCode(ch))
+ {
+ if (opt != ' ')
+ {
+ OptionBuilder.hasArg(type != null);
+ OptionBuilder.isRequired(required);
+ OptionBuilder.withType(type);
+
// we have a previous one to deal with
- options.addOption( OptionBuilder.hasArg( type != null )
- .isRequired( required )
- .withType( type )
- .create( opt ) );
+ options.addOption(OptionBuilder.create(opt));
required = false;
type = null;
opt = ' ';
}
+
opt = ch;
- } else
- if(ch == '!') {
+ }
+ else if (ch == '!')
+ {
required = true;
- } else {
+ }
+ else
+ {
type = getValueClass(ch);
}
}
- if(opt != ' ') {
+ if (opt != ' ')
+ {
+ OptionBuilder.hasArg(type != null);
+ OptionBuilder.isRequired(required);
+ OptionBuilder.withType(type);
+
// we have a final one to deal with
- options.addOption( OptionBuilder.hasArg( type != null )
- .isRequired( required )
- .withType( type )
- .create( opt ) );
+ options.addOption(OptionBuilder.create(opt));
}
return options;
}
-
}
Propchange: jakarta/commons/proper/cli/branches/CLI_1_BRANCH/src/java/org/apache/commons/cli/PatternOptionBuilder.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org