You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by br...@apache.org on 2017/06/08 17:38:02 UTC
[13/40] commons-cli git commit: An Avalon implementation of a commons
vargs codebase - split onto its own branch so we can start focusing on the
CLI parts individually
An Avalon implementation of a commons vargs codebase - split onto its own branch so we can start focusing on the CLI parts individually
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/cli/branches/avalon-implementation@417069 13f79535-47bb-0310-9956-ffa450edef68
Project: http://git-wip-us.apache.org/repos/asf/commons-cli/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-cli/commit/9e65354f
Tree: http://git-wip-us.apache.org/repos/asf/commons-cli/tree/9e65354f
Diff: http://git-wip-us.apache.org/repos/asf/commons-cli/diff/9e65354f
Branch: refs/heads/avalon-implementation
Commit: 9e65354f1bdce4d47b42dd9d18d7d46a3ec05631
Parents: 3ac60ae
Author: Henri Yandell <ba...@apache.org>
Authored: Sun Jun 25 20:33:16 2006 +0000
Committer: Henri Yandell <ba...@apache.org>
Committed: Sun Jun 25 20:33:16 2006 +0000
----------------------------------------------------------------------
maven.xml | 6 -
project.xml | 9 +-
.../commons/cli/AlreadySelectedException.java | 38 -
.../org/apache/commons/cli/BasicParser.java | 46 -
.../org/apache/commons/cli/CLI2Converter.java | 190 ----
.../org/apache/commons/cli/CommandLine.java | 319 -------
.../apache/commons/cli/CommandLineParser.java | 90 --
src/java/org/apache/commons/cli/GnuParser.java | 173 ----
.../org/apache/commons/cli/HelpFormatter.java | 908 -------------------
.../commons/cli/MissingArgumentException.java | 38 -
.../commons/cli/MissingOptionException.java | 37 -
src/java/org/apache/commons/cli/Option.java | 599 ------------
.../org/apache/commons/cli/OptionBuilder.java | 372 --------
.../org/apache/commons/cli/OptionGroup.java | 162 ----
.../org/apache/commons/cli/OptionValidator.java | 100 --
src/java/org/apache/commons/cli/Options.java | 277 ------
.../org/apache/commons/cli/ParseException.java | 36 -
src/java/org/apache/commons/cli/Parser.java | 406 ---------
.../commons/cli/PatternOptionBuilder.java | 211 -----
.../org/apache/commons/cli/PosixParser.java | 309 -------
.../org/apache/commons/cli/TypeHandler.java | 257 ------
.../cli/UnrecognizedOptionException.java | 38 -
src/java/org/apache/commons/cli/Util.java | 66 --
src/java/org/apache/commons/cli/overview.html | 28 -
src/java/org/apache/commons/cli/package.html | 6 -
src/java/org/apache/commons/cli2/Argument.java | 106 ---
.../org/apache/commons/cli2/CommandLine.java | 214 -----
.../org/apache/commons/cli2/DisplaySetting.java | 154 ----
src/java/org/apache/commons/cli2/Group.java | 64 --
src/java/org/apache/commons/cli2/HelpLine.java | 52 --
src/java/org/apache/commons/cli2/Option.java | 196 ----
.../apache/commons/cli2/OptionException.java | 106 ---
src/java/org/apache/commons/cli2/Parent.java | 40 -
.../commons/cli2/WriteableCommandLine.java | 75 --
.../commons/cli2/builder/ArgumentBuilder.java | 285 ------
.../commons/cli2/builder/CommandBuilder.java | 186 ----
.../cli2/builder/DefaultOptionBuilder.java | 214 -----
.../commons/cli2/builder/GroupBuilder.java | 117 ---
.../commons/cli2/builder/PatternBuilder.java | 201 ----
.../commons/cli2/builder/SwitchBuilder.java | 193 ----
.../cli2/commandline/CommandLineImpl.java | 119 ---
.../cli2/commandline/DefaultingCommandLine.java | 171 ----
.../apache/commons/cli2/commandline/Parser.java | 177 ----
.../commandline/PreferencesCommandLine.java | 169 ----
.../cli2/commandline/PropertiesCommandLine.java | 154 ----
.../commandline/WriteableCommandLineImpl.java | 225 -----
.../commons/cli2/option/ArgumentImpl.java | 374 --------
.../org/apache/commons/cli2/option/Command.java | 174 ----
.../commons/cli2/option/DefaultOption.java | 220 -----
.../apache/commons/cli2/option/GroupImpl.java | 516 -----------
.../commons/cli2/option/HelpLineImpl.java | 109 ---
.../apache/commons/cli2/option/OptionImpl.java | 158 ----
.../apache/commons/cli2/option/ParentImpl.java | 250 -----
.../commons/cli2/option/PropertyOption.java | 166 ----
.../commons/cli2/option/SourceDestArgument.java | 137 ---
.../org/apache/commons/cli2/option/Switch.java | 247 -----
.../resource/CLIMessageBundle_en_US.properties | 57 --
.../cli2/resource/ResourceConstants.java | 67 --
.../commons/cli2/resource/ResourceHelper.java | 159 ----
.../apache/commons/cli2/util/Comparators.java | 455 ----------
.../apache/commons/cli2/util/HelpFormatter.java | 637 -------------
.../commons/cli2/validation/ClassValidator.java | 200 ----
.../commons/cli2/validation/DateValidator.java | 312 -------
.../commons/cli2/validation/EnumValidator.java | 119 ---
.../commons/cli2/validation/FileValidator.java | 264 ------
.../validation/InvalidArgumentException.java | 33 -
.../cli2/validation/NumberValidator.java | 199 ----
.../commons/cli2/validation/UrlValidator.java | 114 ---
.../commons/cli2/validation/Validator.java | 42 -
.../apache/commons/cli2/validation/package.html | 16 -
.../org/apache/commons/cli/ApplicationTest.java | 130 ---
.../commons/cli/ArgumentIsOptionTest.java | 99 --
src/test/org/apache/commons/cli/BugsTest.java | 536 -----------
src/test/org/apache/commons/cli/BuildTest.java | 101 ---
.../apache/commons/cli/CLI2ConverterTest.java | 132 ---
.../org/apache/commons/cli/GnuParseTest.java | 269 ------
.../commons/cli/HelpFormatterExamples.java | 112 ---
.../apache/commons/cli/LongOptionWithShort.java | 113 ---
.../apache/commons/cli/OptionBuilderTest.java | 164 ----
.../org/apache/commons/cli/OptionGroupTest.java | 280 ------
.../org/apache/commons/cli/OptionsTest.java | 99 --
.../apache/commons/cli/ParseRequiredTest.java | 116 ---
src/test/org/apache/commons/cli/ParseTest.java | 290 ------
.../commons/cli/PatternOptionBuilderTest.java | 86 --
.../apache/commons/cli/TestHelpFormatter.java | 176 ----
src/test/org/apache/commons/cli/ValueTest.java | 426 ---------
src/test/org/apache/commons/cli/ValuesTest.java | 253 ------
.../apache/commons/cli/bug/BugCLI18Test.java | 42 -
.../org/apache/commons/cli2/CLITestCase.java | 84 --
.../commons/cli2/CommandLineDefaultsTest.java | 250 -----
.../commons/cli2/CommandLineTestCase.java | 511 -----------
.../apache/commons/cli2/DocumentationTest.java | 444 ---------
.../org/apache/commons/cli2/PrecedenceTest.java | 412 ---------
.../cli2/WriteableCommandLineTestCase.java | 91 --
.../commons/cli2/application/AntTest.java | 197 ----
.../apache/commons/cli2/application/CpTest.java | 470 ----------
.../commons/cli2/application/CvsTest.java | 311 -------
.../apache/commons/cli2/application/LsTest.java | 223 -----
.../apache/commons/cli2/bug/Bug13886Test.java | 88 --
.../apache/commons/cli2/bug/Bug13935Test.java | 59 --
.../apache/commons/cli2/bug/Bug15046Test.java | 81 --
.../apache/commons/cli2/bug/Bug15648Test.java | 59 --
.../apache/commons/cli2/bug/Bug27575Test.java | 40 -
.../apache/commons/cli2/bug/Bug28005Test.java | 78 --
.../apache/commons/cli2/bug/Bug32533Test.java | 47 -
.../apache/commons/cli2/bug/BugCLI18Test.java | 59 --
.../cli2/bug/BugLoopingOptionLookAlikeTest.java | 76 --
.../cli2/builder/ArgumentBuilderTest.java | 251 -----
.../cli2/builder/DefaultOptionBuilderTest.java | 199 ----
.../commandline/DefaultingCommandLineTest.java | 150 ---
.../commons/cli2/commandline/ParserTest.java | 124 ---
.../commandline/PreferencesCommandLineTest.java | 105 ---
.../commandline/PropertiesCommandLineTest.java | 100 --
.../WriteableCommandLineImplTest.java | 35 -
.../commons/cli2/jdepend/JDependTest.java | 108 ---
.../commons/cli2/option/ArgumentTest.java | 645 -------------
.../commons/cli2/option/ArgumentTestCase.java | 27 -
.../apache/commons/cli2/option/CommandTest.java | 248 -----
.../commons/cli2/option/DefaultOptionTest.java | 226 -----
.../apache/commons/cli2/option/GroupTest.java | 439 ---------
.../commons/cli2/option/GroupTestCase.java | 30 -
.../commons/cli2/option/NestedGroupTest.java | 191 ----
.../commons/cli2/option/OptionTestCase.java | 54 --
.../apache/commons/cli2/option/ParentTest.java | 418 ---------
.../commons/cli2/option/ParentTestCase.java | 25 -
.../commons/cli2/option/PropertyOptionTest.java | 232 -----
.../apache/commons/cli2/option/SwitchTest.java | 307 -------
.../cli2/resource/ResourceHelperTest.java | 81 --
.../commons/cli2/resource/TestBundle.properties | 10 -
.../commons/cli2/util/ComparatorsTest.java | 220 -----
.../commons/cli2/util/HelpFormatterTest.java | 542 -----------
.../cli2/validation/ClassValidatorTest.java | 247 -----
.../cli2/validation/DateValidatorTest.java | 216 -----
.../cli2/validation/EnumValidatorTest.java | 65 --
.../cli2/validation/FileValidatorTest.java | 195 ----
.../cli2/validation/NumberValidatorTest.java | 167 ----
.../cli2/validation/TimeZoneTestSuite.java | 45 -
.../cli2/validation/UrlValidatorTest.java | 92 --
.../cli2/validation/protect/ProtectedClass.java | 22 -
139 files changed, 5 insertions(+), 25779 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-cli/blob/9e65354f/maven.xml
----------------------------------------------------------------------
diff --git a/maven.xml b/maven.xml
index 30381ed..3c75b35 100644
--- a/maven.xml
+++ b/maven.xml
@@ -31,12 +31,6 @@ limitations under the License.
</copy>
</preGoal>
- <postGoal name="test:test-resources">
- <echo>Moving test bundle.</echo>
- <copy file="src/test/org/apache/commons/cli2/resource/TestBundle.properties"
- tofile="target/test-classes/org/apache/commons/cli2/resource/TestBundle.properties"/>
- </postGoal>
-
<preGoal name="dist:prepare-bin-filesystem">
<attainGoal name="ant:generate-build"/>
</preGoal>
http://git-wip-us.apache.org/repos/asf/commons-cli/blob/9e65354f/project.xml
----------------------------------------------------------------------
diff --git a/project.xml b/project.xml
index 6ec86d4..de83d1a 100644
--- a/project.xml
+++ b/project.xml
@@ -18,12 +18,13 @@
<groupId>org.apache.commons</groupId>
<artifactId>commons-cli</artifactId>
<name>CLI</name>
- <currentVersion>2.0-SNAPSHOT</currentVersion>
+ <currentVersion>avalon-implementation-SNAPSHOT</currentVersion>
<inceptionYear>2002</inceptionYear>
- <shortDescription>Commons CLI</shortDescription>
+ <shortDescription>Commons CLI - Avalon Implementation</shortDescription>
<description>
- Commons CLI provides a simple API for presenting, proecessing and
- validating a command line interface.
+ Commons CLI provides a simple API for presenting, processing and
+ validating a command line interface. This is an implementation from
+ Avalon's code base.
</description>
<logo>/images/logo.png</logo>
http://git-wip-us.apache.org/repos/asf/commons-cli/blob/9e65354f/src/java/org/apache/commons/cli/AlreadySelectedException.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/commons/cli/AlreadySelectedException.java b/src/java/org/apache/commons/cli/AlreadySelectedException.java
deleted file mode 100644
index 69389fe..0000000
--- a/src/java/org/apache/commons/cli/AlreadySelectedException.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/**
- * 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>Thrown when more than one option in an option group
- * has been provided.</p>
- *
- * @author John Keyes ( john at integralsource.com )
- * @see ParseException
- */
-public class AlreadySelectedException
- extends ParseException {
-
- /**
- * <p>Construct a new <code>AlreadySelectedException</code>
- * with the specified detail message.</p>
- *
- * @param message the detail message
- */
- public AlreadySelectedException(String message)
- {
- super(message);
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/commons-cli/blob/9e65354f/src/java/org/apache/commons/cli/BasicParser.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/commons/cli/BasicParser.java b/src/java/org/apache/commons/cli/BasicParser.java
deleted file mode 100644
index 2becdb9..0000000
--- a/src/java/org/apache/commons/cli/BasicParser.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/**
- * 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;
-
-/**
- * The class BasicParser provides a very simple implementation of
- * the {@link Parser#flatten(Options,String[],boolean) flatten} method.
- *
- * @author John Keyes (john at integralsource.com)
- * @see Parser
- */
-public class BasicParser extends Parser {
-
- /**
- * <p>A simple implementation of {@link Parser}'s abstract
- * {@link Parser#flatten(Options,String[],boolean) flatten} method.</p>
- *
- * <p><b>Note:</b> <code>options</code> and <code>stopAtNonOption</code>
- * are not used in this <code>flatten</code> method.</p>
- *
- * @param options The command line {@link Options}
- * @param arguments The command line arguments to be parsed
- * @param stopAtNonOption Specifies whether to stop flattening
- * when an non option is found.
- * @return The <code>arguments</code> String array.
- */
- protected String[] flatten(Options options, String[] arguments,
- boolean stopAtNonOption)
- {
- // just echo the arguments
- return arguments;
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/commons-cli/blob/9e65354f/src/java/org/apache/commons/cli/CLI2Converter.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/commons/cli/CLI2Converter.java b/src/java/org/apache/commons/cli/CLI2Converter.java
deleted file mode 100644
index 517b48e..0000000
--- a/src/java/org/apache/commons/cli/CLI2Converter.java
+++ /dev/null
@@ -1,190 +0,0 @@
-/**
- * Copyright 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.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.ListIterator;
-import java.util.Set;
-
-import org.apache.commons.cli2.Group;
-import org.apache.commons.cli2.Option;
-import org.apache.commons.cli2.builder.ArgumentBuilder;
-import org.apache.commons.cli2.builder.DefaultOptionBuilder;
-import org.apache.commons.cli2.builder.GroupBuilder;
-import org.apache.commons.cli2.validation.InvalidArgumentException;
-import org.apache.commons.cli2.validation.Validator;
-
-/**
- * A utility class for converting data structures version 1 to
- * version 2 Option instances.
- */
-public class CLI2Converter {
-
- private CLI2Converter(){
- // prevent creation of static utility class
- }
-
- /**
- * Creates a version 2 Option instance from a version 1 Option instance.
- *
- * @param option1 the version 1 Option to convert
- * @return a version 2 Option
- */
- public static Option option(final org.apache.commons.cli.Option option1){
-
- final DefaultOptionBuilder obuilder = new DefaultOptionBuilder();
- obuilder.withRequired(option1.isRequired());
-
- final String shortName = option1.getOpt();
- if(shortName!=null && !" ".equals(shortName)){
- obuilder.withShortName(shortName);
- }
-
- final String longName = option1.getLongOpt();
- if(longName!=null){
- obuilder.withLongName(longName);
- }
- obuilder.withId(option1.getId());
-
- final String description = option1.getDescription();
- if(description!=null){
- obuilder.withDescription(description);
- }
-
- if(option1.hasArg()){
- final ArgumentBuilder abuilder = new ArgumentBuilder();
- final String argName = option1.getArgName();
- abuilder.withName(argName);
- abuilder.withMaximum(option1.getArgs());
- if(option1.hasValueSeparator()){
- abuilder.withSubsequentSeparator(option1.getValueSeparator());
- }
- if(option1.hasOptionalArg()){
- abuilder.withMinimum(0);
- }
- else{
- //TODO check what non-optional arg means
- abuilder.withMinimum(option1.getArgs());
- }
-
- final Object type = option1.getType();
- if(type!=null){
- abuilder.withValidator(new TypeHandlerValidator(type));
- }
-
- obuilder.withArgument(abuilder.create());
- }
-
- return obuilder.create();
- }
-
- /**
- * Creates a version 2 Group instance from a version 1 OptionGroup instance.
- *
- * @param optionGroup1 the version 1 OptionGroup to convert
- * @return a version 2 Group
- */
- public static Group group(final OptionGroup optionGroup1){
-
- final GroupBuilder gbuilder = new GroupBuilder();
-
- for(final Iterator i = optionGroup1.getOptions().iterator();i.hasNext();){
- final org.apache.commons.cli.Option option1 = (org.apache.commons.cli.Option)i.next();
- final Option option2 = option(option1);
- gbuilder.withOption(option2);
- }
-
- gbuilder.withMaximum(1);
-
- if(optionGroup1.isRequired()){
- gbuilder.withMinimum(1);
- }
-
- return gbuilder.create();
- }
-
- /**
- * Creates a version 2 Group instance from a version 1 Options instance.
- *
- * @param options1 the version 1 Options to convert
- * @return a version 2 Group
- */
- public static Group group(final Options options1){
-
- final GroupBuilder gbuilder = new GroupBuilder();
-
- final Set optionGroups = new HashSet();
-
- for(final Iterator i = options1.getOptionGroups().iterator();i.hasNext();){
- final OptionGroup optionGroup1 = (OptionGroup)i.next();
- Group group = group(optionGroup1);
- gbuilder.withOption(group);
- optionGroups.add(optionGroup1);
- }
-
- for(final Iterator i = options1.getOptions().iterator();i.hasNext();){
- final org.apache.commons.cli.Option option1 = (org.apache.commons.cli.Option)i.next();
- if(!optionInAGroup(option1,optionGroups)){
- final Option option2 = option(option1);
- gbuilder.withOption(option2);
- }
- }
-
- return gbuilder.create();
- }
-
- private static boolean optionInAGroup(final org.apache.commons.cli.Option option1, final Set optionGroups) {
- for (Iterator i = optionGroups.iterator(); i.hasNext();) {
- OptionGroup group = (OptionGroup) i.next();
- if(group.getOptions().contains(option1)){
- return true;
- }
- }
- return false;
- }
-}
-
-class TypeHandlerValidator implements Validator{
-
- private final Object type;
-
- /**
- * Creates a new Validator using the TypeHandler class.
- *
- * @see TypeHandler
- * @param type The required type for valid elements
- */
- public TypeHandlerValidator(final Object type){
- this.type = type;
- }
-
- /* (non-Javadoc)
- * @see org.apache.commons.cli2.validation.Validator#validate(java.util.List)
- */
- public void validate(final List values) throws InvalidArgumentException {
- final ListIterator i = values.listIterator();
- while(i.hasNext()){
- final String value = (String)i.next();
- final Object converted = TypeHandler.createValue(value,type);
- if(converted==null){
- throw new InvalidArgumentException("Unable to understand value: " + value);
- }
- i.set(converted);
- }
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/commons-cli/blob/9e65354f/src/java/org/apache/commons/cli/CommandLine.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/commons/cli/CommandLine.java b/src/java/org/apache/commons/cli/CommandLine.java
deleted file mode 100644
index 6c1c278..0000000
--- a/src/java/org/apache/commons/cli/CommandLine.java
+++ /dev/null
@@ -1,319 +0,0 @@
-/**
- * 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;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-
-/**
- * <p>Represents list of arguments parsed against
- * a {@link Options} descriptor.<p>
- *
- * <p>It allows querying of a boolean {@link #hasOption(String opt)},
- * in addition to retrieving the {@link #getOptionValue(String opt)}
- * for options requiring arguments.</p>
- *
- * <p>Additionally, any left-over or unrecognized arguments,
- * are available for further processing.</p>
- *
- * @author bob mcwhirter (bob @ werken.com)
- * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
- * @author John Keyes (john at integralsource.com)
- */
-public class CommandLine {
-
- /** the unrecognised options/arguments */
- private List args = new LinkedList();
-
- /** the processed options */
- private Map options = new HashMap();
-
- /** the option name map */
- private Map names = new HashMap();
-
- /** Map of unique options for ease to get complete list of options */
- private Map hashcodeMap = new HashMap();
-
- /** the processed options */
- private Option[] optionsArray;
-
- /**
- * Creates a command line.
- */
- CommandLine()
- {
- // nothing to do
- }
-
- /**
- * Query to see if an option has been set.
- *
- * @param opt Short name of the option
- * @return true if set, false if not
- */
- public boolean hasOption(String opt)
- {
- return options.containsKey(opt);
- }
-
- /**
- * Query to see if an option has been set.
- *
- * @param opt character name of the option
- * @return true if set, false if not
- */
- public boolean hasOption(char opt)
- {
- return hasOption(String.valueOf(opt));
- }
-
- /**
- * Return the <code>Object</code> type of this <code>Option</code>.
- *
- * @param opt the name of the option
- * @return the type of this <code>Option</code>
- */
- public Object getOptionObject(String opt)
- {
- String res = getOptionValue(opt);
-
- if (!options.containsKey(opt))
- {
- return null;
- }
-
- Object type = ((Option) options.get(opt)).getType();
-
- return (res == null) ? null : TypeHandler.createValue(res, type);
- }
-
- /**
- * Return the <code>Object</code> type of this <code>Option</code>.
- *
- * @param opt the name of the option
- * @return the type of opt
- */
- public Object getOptionObject(char opt)
- {
- return getOptionObject(String.valueOf(opt));
- }
-
- /**
- * Retrieve the argument, if any, of this option.
- *
- * @param opt the name of the option
- * @return Value of the argument if option is set, and has an argument,
- * otherwise null.
- */
- public String getOptionValue(String opt)
- {
- String[] values = getOptionValues(opt);
-
- return (values == null) ? null : values[0];
- }
-
- /**
- * Retrieve the argument, if any, of this option.
- *
- * @param opt the character name of the option
- * @return Value of the argument if option is set, and has an argument,
- * otherwise null.
- */
- public String getOptionValue(char opt)
- {
- return getOptionValue(String.valueOf(opt));
- }
-
- /**
- * Retrieves the array of values, if any, of an option.
- *
- * @param opt string name of the option
- * @return Values of the argument if option is set, and has an argument,
- * otherwise null.
- */
- public String[] getOptionValues(String opt)
- {
- opt = Util.stripLeadingHyphens(opt);
-
- String key = opt;
-
- if (names.containsKey(opt))
- {
- key = (String) names.get(opt);
- }
-
- if (options.containsKey(key))
- {
- return ((Option) options.get(key)).getValues();
- }
-
- return null;
- }
-
- /**
- * Retrieves the array of values, if any, of an option.
- *
- * @param opt character name of the option
- * @return Values of the argument if option is set, and has an argument,
- * otherwise null.
- */
- public String[] getOptionValues(char opt)
- {
- return getOptionValues(String.valueOf(opt));
- }
-
- /**
- * Retrieve the argument, if any, of an option.
- *
- * @param opt name of the option
- * @param defaultValue is the default value to be returned if the option
- * is not specified
- * @return Value of the argument if option is set, and has an argument,
- * otherwise <code>defaultValue</code>.
- */
- public String getOptionValue(String opt, String defaultValue)
- {
- String answer = getOptionValue(opt);
-
- return (answer != null) ? answer : defaultValue;
- }
-
- /**
- * Retrieve the argument, if any, of an option.
- *
- * @param opt character name of the option
- * @param defaultValue is the default value to be returned if the option
- * is not specified
- * @return Value of the argument if option is set, and has an argument,
- * otherwise <code>defaultValue</code>.
- */
- public String getOptionValue(char opt, String defaultValue)
- {
- return getOptionValue(String.valueOf(opt), defaultValue);
- }
-
- /**
- * Retrieve any left-over non-recognized options and arguments
- *
- * @return remaining items passed in but not parsed as an array
- */
- public String[] getArgs()
- {
- String[] answer = new String[args.size()];
-
- args.toArray(answer);
-
- return answer;
- }
-
- /**
- * Retrieve any left-over non-recognized options and arguments
- *
- * @return remaining items passed in but not parsed as a <code>List</code>.
- */
- public List getArgList()
- {
- return args;
- }
-
- /**
- * jkeyes
- * - commented out until it is implemented properly
- * <p>Dump state, suitable for debugging.</p>
- *
- * @return Stringified form of this object
- */
-
- /*
- public String toString() {
- StringBuffer buf = new StringBuffer();
-
- buf.append("[ CommandLine: [ options: ");
- buf.append(options.toString());
- buf.append(" ] [ args: ");
- buf.append(args.toString());
- buf.append(" ] ]");
-
- return buf.toString();
- }
- */
-
- /**
- * Add left-over unrecognized option/argument.
- *
- * @param arg the unrecognised option/argument.
- */
- void addArg(String arg)
- {
- args.add(arg);
- }
-
- /**
- * Add an option to the command line. The values of
- * the option are stored.
- *
- * @param opt the processed option
- */
- void addOption(Option opt)
- {
- hashcodeMap.put(new Integer(opt.hashCode()), opt);
-
- String key = opt.getKey();
-
- if (key == null)
- {
- key = opt.getLongOpt();
- }
- else
- {
- names.put(opt.getLongOpt(), key);
- }
-
- options.put(key, opt);
- }
-
- /**
- * Returns an iterator over the Option members of CommandLine.
- *
- * @return an <code>Iterator</code> over the processed {@link Option}
- * members of this {@link CommandLine}
- */
- public Iterator iterator()
- {
- return hashcodeMap.values().iterator();
- }
-
- /**
- * Returns an array of the processed {@link Option}s.
- *
- * @return an array of the processed {@link Option}s.
- */
- public Option[] getOptions()
- {
- Collection processed = options.values();
-
-
- // reinitialise array
- optionsArray = new Option[processed.size()];
-
- // return the array
- return (Option[]) processed.toArray(optionsArray);
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/commons-cli/blob/9e65354f/src/java/org/apache/commons/cli/CommandLineParser.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/commons/cli/CommandLineParser.java b/src/java/org/apache/commons/cli/CommandLineParser.java
deleted file mode 100644
index ae59f6a..0000000
--- a/src/java/org/apache/commons/cli/CommandLineParser.java
+++ /dev/null
@@ -1,90 +0,0 @@
-/**
- * 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.Properties;
-
-/**
- * A class that implements the <code>CommandLineParser</code> interface
- * can parse a String array according to the {@link Options} specified
- * and return a {@link CommandLine}.
- *
- * @author John Keyes (john at integralsource.com)
- */
-public interface CommandLineParser {
-
- /**
- * Parse the arguments according to the specified options.
- *
- * @param options the specified Options
- * @param arguments the command line arguments
- * @return the list of atomic option and value tokens
- *
- * @throws ParseException if there are any problems encountered
- * while parsing the command line tokens.
- */
- CommandLine parse(Options options, String[] arguments)
- throws ParseException;
-
- /**
- * Parse the arguments according to the specified options and
- * properties.
- *
- * @param options the specified Options
- * @param arguments the command line arguments
- * @param properties command line option name-value pairs
- * @return the list of atomic option and value tokens
- *
- * @throws ParseException if there are any problems encountered
- * while parsing the command line tokens.
- */
- CommandLine parse(Options options, String[] arguments,
- Properties properties)
- throws ParseException;
-
- /**
- * Parse the arguments according to the specified options.
- *
- * @param options the specified Options
- * @param arguments the command line arguments
- * @param stopAtNonOption specifies whether to continue parsing the
- * arguments if a 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.
- */
- CommandLine parse(Options options, String[] arguments,
- boolean stopAtNonOption)
- throws ParseException;
-
- /**
- * Parse the arguments according to the specified options and
- * properties.
- *
- * @param options the specified Options
- * @param arguments the command line arguments
- * @param properties command line option name-value pairs
- * @param stopAtNonOption specifies whether to continue parsing the
- *
- * @return the list of atomic option and value tokens
- * @throws ParseException if there are any problems encountered
- * while parsing the command line tokens.
- */
- CommandLine parse(Options options, String[] arguments,
- Properties properties, boolean stopAtNonOption)
- throws ParseException;
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/commons-cli/blob/9e65354f/src/java/org/apache/commons/cli/GnuParser.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/commons/cli/GnuParser.java b/src/java/org/apache/commons/cli/GnuParser.java
deleted file mode 100644
index b510037..0000000
--- a/src/java/org/apache/commons/cli/GnuParser.java
+++ /dev/null
@@ -1,173 +0,0 @@
-/**
- * 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;
-
-/**
- * The class GnuParser provides an implementation of the
- * {@link Parser#flatten(Options,String[],boolean) flatten} method.
- *
- * @author John Keyes (john at integralsource.com)
- * @see Parser
- * @version $Revision$
- */
-public class GnuParser extends Parser {
-
- /** holder for flattened tokens */
- private ArrayList tokens = new ArrayList();
-
- /**
- * <p>Resets the members to their original state i.e. remove
- * all of <code>tokens</code> entries.
- */
- private void init()
- {
- tokens.clear();
- }
-
- /**
- * <p>This flatten method does so using the following rules:
- * <ol>
- * <li>If an {@link Option} exists for the first character of
- * the <code>arguments</code> entry <b>AND</b> an {@link Option}
- * does not exist for the whole <code>argument</code> then
- * add the first character as an option to the processed tokens
- * list e.g. "-D" and add the rest of the entry to the also.</li>
- * <li>Otherwise just add the token to the processed tokens list.
- * </li>
- * </ol>
- * </p>
- *
- * @param options The Options to parse the arguments by.
- * @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
- */
- protected String[] flatten(Options options, String[] arguments,
- boolean stopAtNonOption)
- {
- init();
-
- boolean eatTheRest = false;
- Option currentOption = null;
-
- for (int i = 0; i < arguments.length; i++)
- {
- if ("--".equals(arguments[i]))
- {
- eatTheRest = true;
- tokens.add("--");
- }
- else if ("-".equals(arguments[i]))
- {
- tokens.add("-");
- }
- else if (arguments[i].startsWith("-"))
- {
- Option option = options.getOption(arguments[i]);
-
- // this is not an Option
- if (option == null)
- {
- // handle special properties Option
- Option specialOption =
- options.getOption(arguments[i].substring(0, 2));
-
- if (specialOption != null)
- {
- tokens.add(arguments[i].substring(0, 2));
- tokens.add(arguments[i].substring(2));
- }
- else if (stopAtNonOption)
- {
- eatTheRest = true;
- tokens.add(arguments[i]);
- }
- else
- {
- tokens.add(arguments[i]);
- }
- }
- else
- {
- currentOption = option;
-
- // special option
- Option specialOption =
- options.getOption(arguments[i].substring(0, 2));
-
- if ((specialOption != null) && (option == null))
- {
- tokens.add(arguments[i].substring(0, 2));
- tokens.add(arguments[i].substring(2));
- }
- else if ((currentOption != null) && currentOption.hasArg())
- {
- if (currentOption.hasArg())
- {
- tokens.add(arguments[i]);
- currentOption = null;
- }
- else if (currentOption.hasArgs())
- {
- tokens.add(arguments[i]);
- }
- else if (stopAtNonOption)
- {
- eatTheRest = true;
- tokens.add("--");
- tokens.add(arguments[i]);
- }
- else
- {
- tokens.add(arguments[i]);
- }
- }
- else if (currentOption != null)
- {
- tokens.add(arguments[i]);
- }
- else if (stopAtNonOption)
- {
- eatTheRest = true;
- tokens.add("--");
- tokens.add(arguments[i]);
- }
- else
- {
- tokens.add(arguments[i]);
- }
- }
- }
- else
- {
- tokens.add(arguments[i]);
- }
-
- if (eatTheRest)
- {
- for (i++; i < arguments.length; i++)
- {
- tokens.add(arguments[i]);
- }
- }
- }
-
- return (String[]) tokens.toArray(new String[] { });
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/commons-cli/blob/9e65354f/src/java/org/apache/commons/cli/HelpFormatter.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/commons/cli/HelpFormatter.java b/src/java/org/apache/commons/cli/HelpFormatter.java
deleted file mode 100644
index ebee9fe..0000000
--- a/src/java/org/apache/commons/cli/HelpFormatter.java
+++ /dev/null
@@ -1,908 +0,0 @@
-/**
- * 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.io.PrintWriter;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.Iterator;
-import java.util.List;
-
-/**
- * A formatter of help messages for the current command line options
- *
- * @author Slawek Zachcial
- * @author John Keyes (john at integralsource.com)
- **/
-public class HelpFormatter {
- // --------------------------------------------------------------- Constants
-
- /** default number of characters per line */
- public static final int DEFAULT_WIDTH = 74;
-
- /** default padding to the left of each line */
- public static final int DEFAULT_LEFT_PAD = 1;
-
- /** ?? */
- public static final int DEFAULT_DESC_PAD = 3;
-
- /** the string to display at the begining of the usage statement */
- public static final String DEFAULT_SYNTAX_PREFIX = "usage: ";
-
- /** default prefix for shortOpts */
- public static final String DEFAULT_OPT_PREFIX = "-";
-
- /** default prefix for long Option */
- public static final String DEFAULT_LONG_OPT_PREFIX = "--";
-
- /** default name for an argument */
- public static final String DEFAULT_ARG_NAME = "arg";
-
- // -------------------------------------------------------------- Attributes
-
- /** number of characters per line */
- private int defaultWidth = DEFAULT_WIDTH;
-
- /** amount of padding to the left of each line */
- private int defaultLeftPad = DEFAULT_LEFT_PAD;
-
- /** ?? */
- private int defaultDescPad = DEFAULT_DESC_PAD;
-
- /** the string to display at the begining of the usage statement */
- private String defaultSyntaxPrefix = DEFAULT_SYNTAX_PREFIX;
-
- /** the new line character/string ?? */
- private String defaultNewLine = System.getProperty("line.separator");
-
- /** the shortOpt prefix */
- private String defaultOptPrefix = DEFAULT_OPT_PREFIX;
-
- /** the long Opt prefix */
- private String defaultLongOptPrefix = DEFAULT_LONG_OPT_PREFIX;
-
- /** the name of the argument */
- private String defaultArgName = DEFAULT_ARG_NAME;
-
- /**
- * Sets the 'width'.
- *
- * @param width the new value of 'width'
- */
- public void setWidth(int width)
- {
- this.defaultWidth = width;
- }
-
- /**
- * Returns the 'width'.
- *
- * @return the 'width'
- */
- public int getWidth()
- {
- return this.defaultWidth;
- }
-
- /**
- * Sets the 'leftPadding'.
- *
- * @param padding the new value of 'leftPadding'
- */
- public void setLeftPadding(int padding)
- {
- this.defaultLeftPad = padding;
- }
-
- /**
- * Returns the 'leftPadding'.
- *
- * @return the 'leftPadding'
- */
- public int getLeftPadding()
- {
- return this.defaultLeftPad;
- }
-
- /**
- * Sets the 'descPadding'.
- *
- * @param padding the new value of 'descPadding'
- */
- public void setDescPadding(int padding)
- {
- this.defaultDescPad = padding;
- }
-
- /**
- * Returns the 'descPadding'.
- *
- * @return the 'descPadding'
- */
- public int getDescPadding()
- {
- return this.defaultDescPad;
- }
-
- /**
- * Sets the 'syntaxPrefix'.
- *
- * @param prefix the new value of 'syntaxPrefix'
- */
- public void setSyntaxPrefix(String prefix)
- {
- this.defaultSyntaxPrefix = prefix;
- }
-
- /**
- * Returns the 'syntaxPrefix'.
- *
- * @return the 'syntaxPrefix'
- */
- public String getSyntaxPrefix()
- {
- return this.defaultSyntaxPrefix;
- }
-
- /**
- * Sets the 'newLine'.
- *
- * @param newline the new value of 'newLine'
- */
- public void setNewLine(String newline)
- {
- this.defaultNewLine = newline;
- }
-
- /**
- * Returns the 'newLine'.
- *
- * @return the 'newLine'
- */
- public String getNewLine()
- {
- return this.defaultNewLine;
- }
-
- /**
- * Sets the 'optPrefix'.
- *
- * @param prefix the new value of 'optPrefix'
- */
- public void setOptPrefix(String prefix)
- {
- this.defaultOptPrefix = prefix;
- }
-
- /**
- * Returns the 'optPrefix'.
- *
- * @return the 'optPrefix'
- */
- public String getOptPrefix()
- {
- return this.defaultOptPrefix;
- }
-
- /**
- * Sets the 'longOptPrefix'.
- *
- * @param prefix the new value of 'longOptPrefix'
- */
- public void setLongOptPrefix(String prefix)
- {
- this.defaultLongOptPrefix = prefix;
- }
-
- /**
- * Returns the 'longOptPrefix'.
- *
- * @return the 'longOptPrefix'
- */
- public String getLongOptPrefix()
- {
- return this.defaultLongOptPrefix;
- }
-
- /**
- * Sets the 'argName'.
- *
- * @param name the new value of 'argName'
- */
- public void setArgName(String name)
- {
- this.defaultArgName = name;
- }
-
- /**
- * Returns the 'argName'.
- *
- * @return the 'argName'
- */
- public String getArgName()
- {
- return this.defaultArgName;
- }
-
-
- // ------------------------------------------------------------------ Public
-
- /**
- * <p>Print the help for <code>options</code> with the specified
- * command line syntax. This method prints help information to
- * System.out.</p>
- *
- * @param cmdLineSyntax the syntax for this application
- * @param options the Options instance
- */
- public void printHelp(String cmdLineSyntax, Options options)
- {
- printHelp(defaultWidth, cmdLineSyntax, null, options, null, false);
- }
-
- /**
- * <p>Print the help for <code>options</code> with the specified
- * command line syntax. This method prints help information to
- * System.out.</p>
- *
- * @param cmdLineSyntax the syntax for this application
- * @param options the Options instance
- * @param autoUsage whether to print an automatically generated
- * usage statement
- */
- public void printHelp(String cmdLineSyntax, Options options,
- boolean autoUsage)
- {
- printHelp(defaultWidth, cmdLineSyntax, null, options, null, autoUsage);
- }
-
- /**
- * <p>Print the help for <code>options</code> with the specified
- * command line syntax. This method prints help information to
- * System.out.</p>
- *
- * @param cmdLineSyntax the syntax for this application
- * @param header the banner to display at the begining of the help
- * @param options the Options instance
- * @param footer the banner to display at the end of the help
- */
- public void printHelp(String cmdLineSyntax, String header, Options options,
- String footer)
- {
- printHelp(cmdLineSyntax, header, options, footer, false);
- }
-
- /**
- * <p>Print the help for <code>options</code> with the specified
- * command line syntax. This method prints help information to
- * System.out.</p>
- *
- * @param cmdLineSyntax the syntax for this application
- * @param header the banner to display at the begining of the help
- * @param options the Options instance
- * @param footer the banner to display at the end of the help
- * @param autoUsage whether to print an automatically generated
- * usage statement
- */
- public void printHelp(String cmdLineSyntax, String header, Options options,
- String footer, boolean autoUsage)
- {
- printHelp(defaultWidth, cmdLineSyntax, header, options, footer,
- autoUsage);
- }
-
- /**
- * <p>Print the help for <code>options</code> with the specified
- * command line syntax. This method prints help information to
- * System.out.</p>
- *
- * @param width the number of characters to be displayed on each line
- * @param cmdLineSyntax the syntax for this application
- * @param header the banner to display at the begining of the help
- * @param options the Options instance
- * @param footer the banner to display at the end of the help
- */
- public void printHelp(int width, String cmdLineSyntax, String header,
- Options options, String footer)
- {
- printHelp(width, cmdLineSyntax, header, options, footer, false);
- }
-
- /**
- * <p>Print the help for <code>options</code> with the specified
- * command line syntax. This method prints help information to
- * System.out.</p>
- *
- * @param width the number of characters to be displayed on each line
- * @param cmdLineSyntax the syntax for this application
- * @param header the banner to display at the begining of the help
- * @param options the Options instance
- * @param footer the banner to display at the end of the help
- * @param autoUsage whether to print an automatically generated
- * usage statement
- */
- public void printHelp(int width, String cmdLineSyntax, String header,
- Options options, String footer, boolean autoUsage)
- {
- PrintWriter pw = new PrintWriter(System.out);
-
- printHelp(pw, width, cmdLineSyntax, header, options, defaultLeftPad,
- defaultDescPad, footer, autoUsage);
- pw.flush();
- }
-
- /**
- * <p>Print the help for <code>options</code> with the specified
- * command line syntax.</p>
- *
- * @param pw the writer to which the help will be written
- * @param width the number of characters to be displayed on each line
- * @param cmdLineSyntax the syntax for this application
- * @param header the banner to display at the begining of the help
- * @param options the Options instance
- * @param leftPad the number of characters of padding to be prefixed
- * to each line
- * @param descPad the number of characters of padding to be prefixed
- * to each description line
- * @param footer the banner to display at the end of the help
- */
- public void printHelp(PrintWriter pw, int width, String cmdLineSyntax,
- String header, Options options, int leftPad,
- int descPad, String footer)
- {
- printHelp(pw, width, cmdLineSyntax, header, options, leftPad, descPad,
- footer, false);
- }
-
-
- /**
- * <p>Print the help for <code>options</code> with the specified
- * command line syntax.</p>
- *
- * @param pw the writer to which the help will be written
- * @param width the number of characters to be displayed on each line
- * @param cmdLineSyntax the syntax for this application
- * @param header the banner to display at the begining of the help
- * @param options the Options instance
- * @param leftPad the number of characters of padding to be prefixed
- * to each line
- * @param descPad the number of characters of padding to be prefixed
- * to each description line
- * @param footer the banner to display at the end of the help
- * @param autoUsage whether to print an automatically generated
- * usage statement
- */
- public void printHelp(PrintWriter pw, int width, String cmdLineSyntax,
- String header, Options options, int leftPad,
- int descPad, String footer, boolean autoUsage)
- {
- if ((cmdLineSyntax == null) || (cmdLineSyntax.length() == 0))
- {
- throw new IllegalArgumentException("cmdLineSyntax not provided");
- }
-
- if (autoUsage)
- {
- printUsage(pw, width, cmdLineSyntax, options);
- }
- else
- {
- printUsage(pw, width, cmdLineSyntax);
- }
-
- if ((header != null) && (header.trim().length() > 0))
- {
- printWrapped(pw, width, header);
- }
-
- printOptions(pw, width, options, leftPad, descPad);
-
- if ((footer != null) && (footer.trim().length() > 0))
- {
- printWrapped(pw, width, footer);
- }
- }
-
- /**
- * <p>Prints the usage statement for the specified application.</p>
- *
- * @param pw The PrintWriter to print the usage statement
- * @param width The number of characters to display per line
- * @param app The application name
- * @param options The command line Options
- *
- */
- public void printUsage(PrintWriter pw, int width, String app,
- Options options)
- {
- // initialise the string buffer
- StringBuffer buff = new StringBuffer(defaultSyntaxPrefix).append(app)
- .append(" ");
-
- // create a list for processed option groups
- final Collection processedGroups = new ArrayList();
-
- // temp variable
- Option option;
-
- // iterate over the options
- for (Iterator i = options.getOptions().iterator(); i.hasNext();)
- {
- // get the next Option
- option = (Option) i.next();
-
- // check if the option is part of an OptionGroup
- OptionGroup group = options.getOptionGroup(option);
-
- // if the option is part of a group
- if (group != null)
- {
- // and if the group has not already been processed
- if (!processedGroups.contains(group))
- {
- // add the group to the processed list
- processedGroups.add(group);
-
-
- // add the usage clause
- appendOptionGroup(buff, group);
- }
-
- // otherwise the option was displayed in the group
- // previously so ignore it.
- }
-
- // if the Option is not part of an OptionGroup
- else
- {
- appendOption(buff, option, option.isRequired());
- }
-
- if (i.hasNext())
- {
- buff.append(" ");
- }
- }
-
-
- // call printWrapped
- printWrapped(pw, width, buff.toString().indexOf(' ') + 1,
- buff.toString());
- }
-
- /**
- * Appends the usage clause for an OptionGroup to a StringBuffer.
- * The clause is wrapped in square brackets if the group is required.
- * The display of the options is handled by appendOption
- * @param buff the StringBuffer to append to
- * @param group the group to append
- * @see #appendOption(StringBuffer,Option,boolean)
- */
- private static void appendOptionGroup(final StringBuffer buff,
- final OptionGroup group)
- {
- if (!group.isRequired())
- {
- buff.append("[");
- }
-
- // for each option in the OptionGroup
- for (Iterator i = group.getOptions().iterator(); i.hasNext();)
- {
- // whether the option is required or not is handled at group level
- appendOption(buff, (Option) i.next(), true);
-
- if (i.hasNext())
- {
- buff.append(" | ");
- }
- }
-
- if (!group.isRequired())
- {
- buff.append("]");
- }
- }
-
- /**
- * Appends the usage clause for an Option to a StringBuffer.
- *
- * @param buff the StringBuffer to append to
- * @param option the Option to append
- * @param required whether the Option is required or not
- */
- private static void appendOption(final StringBuffer buff,
- final Option option,
- final boolean required)
- {
- if (!required)
- {
- buff.append("[");
- }
-
- if (option.getOpt() != null)
- {
- buff.append("-").append(option.getOpt());
- }
- else
- {
- buff.append("--").append(option.getLongOpt());
- }
-
- // if the Option has a value
- if (option.hasArg() && (option.getArgName() != null))
- {
- buff.append(" <").append(option.getArgName()).append(">");
- }
-
- // if the Option is not a required option
- if (!required)
- {
- buff.append("]");
- }
- }
-
- /**
- * <p>Print the cmdLineSyntax to the specified writer, using the
- * specified width.</p>
- *
- * @param pw The printWriter to write the help to
- * @param width The number of characters per line for the usage statement.
- * @param cmdLineSyntax The usage statement.
- */
- public void printUsage(PrintWriter pw, int width, String cmdLineSyntax)
- {
- int argPos = cmdLineSyntax.indexOf(' ') + 1;
-
- printWrapped(pw, width, defaultSyntaxPrefix.length() + argPos,
- defaultSyntaxPrefix + cmdLineSyntax);
- }
-
- /**
- * <p>Print the help for the specified Options to the specified writer,
- * using the specified width, left padding and description padding.</p>
- *
- * @param pw The printWriter to write the help to
- * @param width The number of characters to display per line
- * @param options The command line Options
- * @param leftPad the number of characters of padding to be prefixed
- * to each line
- * @param descPad the number of characters of padding to be prefixed
- * to each description line
- */
- public void printOptions(PrintWriter pw, int width, Options options,
- int leftPad, int descPad)
- {
- StringBuffer sb = new StringBuffer();
-
- renderOptions(sb, width, options, leftPad, descPad);
- pw.println(sb.toString());
- }
-
- /**
- * <p>Print the specified text to the specified PrintWriter.</p>
- *
- * @param pw The printWriter to write the help to
- * @param width The number of characters to display per line
- * @param text The text to be written to the PrintWriter
- */
- public void printWrapped(PrintWriter pw, int width, String text)
- {
- printWrapped(pw, width, 0, text);
- }
-
- /**
- * <p>Print the specified text to the specified PrintWriter.</p>
- *
- * @param pw The printWriter to write the help to
- * @param width The number of characters to display per line
- * @param nextLineTabStop The position on the next line for the first tab.
- * @param text The text to be written to the PrintWriter
- */
- public void printWrapped(PrintWriter pw, int width, int nextLineTabStop,
- String text)
- {
- StringBuffer sb = new StringBuffer(text.length());
-
- renderWrappedText(sb, width, nextLineTabStop, text);
- pw.println(sb.toString());
- }
-
- // --------------------------------------------------------------- Protected
-
- /**
- * <p>Render the specified Options and return the rendered Options
- * in a StringBuffer.</p>
- *
- * @param sb The StringBuffer to place the rendered Options into.
- * @param width The number of characters to display per line
- * @param options The command line Options
- * @param leftPad the number of characters of padding to be prefixed
- * to each line
- * @param descPad the number of characters of padding to be prefixed
- * to each description line
- *
- * @return the StringBuffer with the rendered Options contents.
- */
- protected StringBuffer renderOptions(StringBuffer sb, int width,
- Options options, int leftPad,
- int descPad)
- {
- final String lpad = createPadding(leftPad);
- final String dpad = createPadding(descPad);
-
- // first create list containing only <lpad>-a,--aaa where
- // -a is opt and --aaa is long opt; in parallel look for
- // the longest opt string this list will be then used to
- // sort options ascending
- int max = 0;
- StringBuffer optBuf;
- List prefixList = new ArrayList();
- Option option;
- List optList = options.helpOptions();
-
- Collections.sort(optList, new OptionComparator());
-
- for (Iterator i = optList.iterator(); i.hasNext();)
- {
- option = (Option) i.next();
- optBuf = new StringBuffer(8);
-
- if (option.getOpt() == null)
- {
- optBuf.append(lpad).append(" " + defaultLongOptPrefix)
- .append(option.getLongOpt());
- }
- else
- {
- optBuf.append(lpad).append(defaultOptPrefix)
- .append(option.getOpt());
-
- if (option.hasLongOpt())
- {
- optBuf.append(',').append(defaultLongOptPrefix)
- .append(option.getLongOpt());
- }
- }
-
- if (option.hasArg())
- {
- if (option.hasArgName())
- {
- optBuf.append(" <").append(option.getArgName()).append(">");
- }
- else
- {
- optBuf.append(' ');
- }
- }
-
- prefixList.add(optBuf);
- max = (optBuf.length() > max) ? optBuf.length() : max;
- }
-
- int x = 0;
-
- for (Iterator i = optList.iterator(); i.hasNext();)
- {
- option = (Option) i.next();
- optBuf = new StringBuffer(prefixList.get(x++).toString());
-
- if (optBuf.length() < max)
- {
- optBuf.append(createPadding(max - optBuf.length()));
- }
-
- optBuf.append(dpad);
-
- int nextLineTabStop = max + descPad;
-
- if (option.getDescription() != null)
- {
- optBuf.append(option.getDescription());
- }
-
- renderWrappedText(sb, width, nextLineTabStop, optBuf.toString());
-
- if (i.hasNext())
- {
- sb.append(defaultNewLine);
- }
- }
-
- return sb;
- }
-
- /**
- * <p>Render the specified text and return the rendered Options
- * in a StringBuffer.</p>
- *
- * @param sb The StringBuffer to place the rendered text into.
- * @param width The number of characters to display per line
- * @param nextLineTabStop The position on the next line for the first tab.
- * @param text The text to be rendered.
- *
- * @return the StringBuffer with the rendered Options contents.
- */
- protected StringBuffer renderWrappedText(StringBuffer sb, int width,
- int nextLineTabStop, String text)
- {
- int pos = findWrapPos(text, width, 0);
-
- if (pos == -1)
- {
- sb.append(rtrim(text));
-
- return sb;
- }
- sb.append(rtrim(text.substring(0, pos))).append(defaultNewLine);
-
- // all following lines must be padded with nextLineTabStop space
- // characters
- final String padding = createPadding(nextLineTabStop);
-
- while (true)
- {
- text = padding + text.substring(pos).trim();
- pos = findWrapPos(text, width, nextLineTabStop);
-
- if (pos == -1)
- {
- sb.append(text);
-
- return sb;
- }
-
- sb.append(rtrim(text.substring(0, pos))).append(defaultNewLine);
- }
- }
-
- /**
- * Finds the next text wrap position after <code>startPos</code> for the
- * text in <code>text</code> with the column width <code>width</code>.
- * The wrap point is the last postion before startPos+width having a
- * whitespace character (space, \n, \r).
- *
- * @param text The text being searched for the wrap position
- * @param width width of the wrapped text
- * @param startPos position from which to start the lookup whitespace
- * character
- * @return postion on which the text must be wrapped or -1 if the wrap
- * position is at the end of the text
- */
- protected int findWrapPos(String text, int width, int startPos)
- {
- int pos = -1;
-
- // the line ends before the max wrap pos or a new line char found
- if (((pos = text.indexOf('\n', startPos)) != -1 && pos <= width)
- || ((pos = text.indexOf('\t', startPos)) != -1 && pos <= width))
- {
- return pos+1;
- }
- else if ((startPos + width) >= text.length())
- {
- return -1;
- }
-
-
- // look for the last whitespace character before startPos+width
- pos = startPos + width;
-
- char c;
-
- while ((pos >= startPos) && ((c = text.charAt(pos)) != ' ')
- && (c != '\n') && (c != '\r'))
- {
- --pos;
- }
-
- // if we found it - just return
- if (pos > startPos)
- {
- return pos;
- }
-
- // must look for the first whitespace chearacter after startPos
- // + width
- pos = startPos + width;
-
- while ((pos <= text.length()) && ((c = text.charAt(pos)) != ' ')
- && (c != '\n') && (c != '\r'))
- {
- ++pos;
- }
-
- return (pos == text.length()) ? (-1) : pos;
- }
-
- /**
- * <p>Return a String of padding of length <code>len</code>.</p>
- *
- * @param len The length of the String of padding to create.
- *
- * @return The String of padding
- */
- protected String createPadding(int len)
- {
- StringBuffer sb = new StringBuffer(len);
-
- for (int i = 0; i < len; ++i)
- {
- sb.append(' ');
- }
-
- return sb.toString();
- }
-
- /**
- * <p>Remove the trailing whitespace from the specified String.</p>
- *
- * @param s The String to remove the trailing padding from.
- *
- * @return The String of without the trailing padding
- */
- protected String rtrim(String s)
- {
- if ((s == null) || (s.length() == 0))
- {
- return s;
- }
-
- int pos = s.length();
-
- while ((pos > 0) && Character.isWhitespace(s.charAt(pos - 1)))
- {
- --pos;
- }
-
- return s.substring(0, pos);
- }
-
- // ------------------------------------------------------ Package protected
- // ---------------------------------------------------------------- Private
- // ---------------------------------------------------------- Inner classes
- /**
- * <p>This class implements the <code>Comparator</code> interface
- * for comparing Options.</p>
- */
- private static class OptionComparator
- implements Comparator {
-
- /**
- * <p>Compares its two arguments for order. Returns a negative
- * integer, zero, or a positive integer as the first argument
- * is less than, equal to, or greater than the second.</p>
- *
- * @param o1 The first Option to be compared.
- * @param o2 The second Option to be compared.
- *
- * @return a negative integer, zero, or a positive integer as
- * the first argument is less than, equal to, or greater than the
- * second.
- */
- public int compare(Object o1, Object o2)
- {
- Option opt1 = (Option)o1;
- Option opt2 = (Option)o2;
-
- return opt1.getKey().compareToIgnoreCase(opt2.getKey());
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/commons-cli/blob/9e65354f/src/java/org/apache/commons/cli/MissingArgumentException.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/commons/cli/MissingArgumentException.java b/src/java/org/apache/commons/cli/MissingArgumentException.java
deleted file mode 100644
index ccdea49..0000000
--- a/src/java/org/apache/commons/cli/MissingArgumentException.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/**
- * 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>Thrown when an option requiring an argument
- * is not provided with an argument.</p>
- *
- * @author John Keyes (john at integralsource.com)
- * @see ParseException
- */
-public class MissingArgumentException
- extends ParseException {
-
- /**
- * <p>Construct a new <code>MissingArgumentException</code>
- * with the specified detail message.</p>
- *
- * @param message the detail message
- */
- public MissingArgumentException(String message)
- {
- super(message);
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/commons-cli/blob/9e65354f/src/java/org/apache/commons/cli/MissingOptionException.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/commons/cli/MissingOptionException.java b/src/java/org/apache/commons/cli/MissingOptionException.java
deleted file mode 100644
index 5dbb0e6..0000000
--- a/src/java/org/apache/commons/cli/MissingOptionException.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/**
- * 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>Thrown when a required option has not been provided.</p>
- *
- * @author John Keyes ( john at integralsource.com )
- * @see ParseException
- */
-public class MissingOptionException
- extends ParseException {
-
- /**
- * <p>Construct a new <code>MissingSelectedException</code>
- * with the specified detail message.</p>
- *
- * @param message the detail message
- */
- public MissingOptionException(String message)
- {
- super(message);
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/commons-cli/blob/9e65354f/src/java/org/apache/commons/cli/Option.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/commons/cli/Option.java b/src/java/org/apache/commons/cli/Option.java
deleted file mode 100644
index 5512858..0000000
--- a/src/java/org/apache/commons/cli/Option.java
+++ /dev/null
@@ -1,599 +0,0 @@
-/**
- * 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;
-
-/** <p>Describes a single command-line option. It maintains
- * information regarding the short-name of the option, the long-name,
- * if any exists, a flag indicating if an argument is required for
- * this option, and a self-documenting description of the option.</p>
- *
- * <p>An Option is not created independantly, but is create through
- * an instance of {@link Options}.<p>
- *
- * @see org.apache.commons.cli.Options
- * @see org.apache.commons.cli.CommandLine
- *
- * @author bob mcwhirter (bob @ werken.com)
- * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
- * @version $Revision$
- */
-public class Option {
-
- /** constant that specifies the number of argument values has
- not been specified */
- public static final int UNINITIALIZED = -1;
-
- /** constant that specifies the number of argument values is infinite */
- public static final int UNLIMITED_VALUES = -2;
-
- /** opt the name of the option */
- private String opt;
-
- /** longOpt is the long representation of the option */
- private String longOpt;
-
- /** hasArg specifies whether this option has an associated argument */
- private boolean hasArg;
-
- /** argName specifies the name of the argument for this option */
- private String argName = "arg";
-
- /** description of the option */
- private String description;
-
- /** required specifies whether this option is required to be present */
- private boolean required;
-
- /** specifies whether the argument value of this Option is optional */
- private boolean optionalArg;
-
- /**
- * numberOfArgs specifies the number of argument values this option
- * can have
- */
- private int numberOfArgs = UNINITIALIZED;
-
- /** the type of this Option */
- private Object type;
-
- /** the list of argument values **/
- private ArrayList values = new ArrayList();
-
- /** the character that is the value separator */
- private char valuesep;
-
- /**
- * Creates an Option using the specified parameters.
- *
- * @param opt short representation of the option
- * @param description describes the function of the option
- *
- * @throws IllegalArgumentException if there are any non valid
- * Option characters in <code>opt</code>.
- */
- public Option(String opt, String description)
- throws IllegalArgumentException
- {
- this(opt, null, false, description);
- }
-
- /**
- * Creates an Option using the specified parameters.
- *
- * @param opt short representation of the option
- * @param hasArg specifies whether the Option takes an argument or not
- * @param description describes the function of the option
- *
- * @throws IllegalArgumentException if there are any non valid
- * Option characters in <code>opt</code>.
- */
- public Option(String opt, boolean hasArg, String description)
- throws IllegalArgumentException
- {
- this(opt, null, hasArg, description);
- }
-
- /**
- * Creates an Option using the specified parameters.
- *
- * @param opt short representation of the option
- * @param longOpt the long representation of the option
- * @param hasArg specifies whether the Option takes an argument or not
- * @param description describes the function of the option
- *
- * @throws IllegalArgumentException if there are any non valid
- * Option characters in <code>opt</code>.
- */
- public Option(String opt, String longOpt, boolean hasArg,
- String description)
- throws IllegalArgumentException
- {
- // ensure that the option is valid
- OptionValidator.validateOption(opt);
-
- this.opt = opt;
- this.longOpt = longOpt;
-
- // if hasArg is set then the number of arguments is 1
- if (hasArg)
- {
- this.numberOfArgs = 1;
- }
-
- this.hasArg = hasArg;
- this.description = description;
- }
-
- /**
- * Returns the id of this Option. This is only set when the
- * Option shortOpt is a single character. This is used for switch
- * statements.
- *
- * @return the id of this Option
- */
- public int getId()
- {
- return getKey().charAt(0);
- }
-
- /**
- * Returns the 'unique' Option identifier.
- *
- * @return the 'unique' Option identifier
- */
- String getKey()
- {
- // if 'opt' is null, then it is a 'long' option
- if (opt == null)
- {
- return this.longOpt;
- }
-
- return this.opt;
- }
-
- /**
- * Retrieve the name of this Option.
- *
- * It is this String which can be used with
- * {@link CommandLine#hasOption(String opt)} and
- * {@link CommandLine#getOptionValue(String opt)} to check
- * for existence and argument.
- *
- * @return The name of this option
- */
- public String getOpt()
- {
- return this.opt;
- }
-
- /**
- * Retrieve the type of this Option.
- *
- * @return The type of this option
- */
- public Object getType()
- {
- return this.type;
- }
-
- /**
- * Sets the type of this Option.
- *
- * @param type the type of this Option
- */
- public void setType(Object type)
- {
- this.type = type;
- }
-
- /**
- * Retrieve the long name of this Option.
- *
- * @return Long name of this option, or null, if there is no long name
- */
- public String getLongOpt()
- {
- return this.longOpt;
- }
-
- /**
- * Sets the long name of this Option.
- *
- * @param longOpt the long name of this Option
- */
- public void setLongOpt(String longOpt)
- {
- this.longOpt = longOpt;
- }
-
- /**
- * Sets whether this Option can have an optional argument.
- *
- * @param optionalArg specifies whether the Option can have
- * an optional argument.
- */
- public void setOptionalArg(boolean optionalArg)
- {
- this.optionalArg = optionalArg;
- }
-
- /**
- * @return whether this Option can have an optional argument
- */
- public boolean hasOptionalArg()
- {
- return this.optionalArg;
- }
-
- /**
- * Query to see if this Option has a long name
- *
- * @return boolean flag indicating existence of a long name
- */
- public boolean hasLongOpt()
- {
- return (this.longOpt != null);
- }
-
- /**
- * Query to see if this Option requires an argument
- *
- * @return boolean flag indicating if an argument is required
- */
- public boolean hasArg()
- {
- return (this.numberOfArgs > 0) || (numberOfArgs == UNLIMITED_VALUES);
- }
-
- /**
- * Retrieve the self-documenting description of this Option
- *
- * @return The string description of this option
- */
- public String getDescription()
- {
- return this.description;
- }
-
- /**
- * Sets the self-documenting description of this Option
- *
- * @param description The description of this option
- */
- public void setDescription(String description)
- {
- this.description = description;
- }
-
- /**
- * Query to see if this Option requires an argument
- *
- * @return boolean flag indicating if an argument is required
- */
- public boolean isRequired()
- {
- return this.required;
- }
-
- /**
- * Sets whether this Option is mandatory.
- *
- * @param required specifies whether this Option is mandatory
- */
- public void setRequired(boolean required)
- {
- this.required = required;
- }
-
- /**
- * Sets the display name for the argument value.
- *
- * @param argName the display name for the argument value.
- */
- public void setArgName(String argName)
- {
- this.argName = argName;
- }
-
- /**
- * Gets the display name for the argument value.
- *
- * @return the display name for the argument value.
- */
- public String getArgName()
- {
- return this.argName;
- }
-
- /**
- * Returns whether the display name for the argument value
- * has been set.
- *
- * @return if the display name for the argument value has been
- * set.
- */
- public boolean hasArgName()
- {
- return (this.argName != null && this.argName.length() > 0);
- }
-
- /**
- * Query to see if this Option can take many values.
- *
- * @return boolean flag indicating if multiple values are allowed
- */
- public boolean hasArgs()
- {
- return (this.numberOfArgs > 1)
- || (this.numberOfArgs == UNLIMITED_VALUES);
- }
-
- /**
- * Sets the number of argument values this Option can take.
- *
- * @param num the number of argument values
- */
- public void setArgs(int num)
- {
- this.numberOfArgs = num;
- }
-
- /**
- * Sets the value separator. For example if the argument value
- * was a Java property, the value separator would be '='.
- *
- * @param sep The value separator.
- */
- public void setValueSeparator(char sep)
- {
- this.valuesep = sep;
- }
-
- /**
- * Returns the value separator character.
- *
- * @return the value separator character.
- */
- public char getValueSeparator()
- {
- return this.valuesep;
- }
-
- /**
- * Return whether this Option has specified a value separator.
- *
- * @return whether this Option has specified a value separator.
- */
- public boolean hasValueSeparator()
- {
- return (this.valuesep > 0);
- }
-
- /**
- * Returns the number of argument values this Option can take.
- *
- * @return num the number of argument values
- */
- public int getArgs()
- {
- return this.numberOfArgs;
- }
-
- /**
- * Adds the specified value to this Option.
- *
- * @param value is a/the value of this Option
- */
- void addValue(String value)
- {
- switch (numberOfArgs)
- {
- case UNINITIALIZED:
- throw new RuntimeException("NO_ARGS_ALLOWED");
-
- default:
- processValue(value);
- }
- }
-
- /**
- * Processes the value. If this Option has a value separator
- * the value will have to be parsed into individual tokens. When
- * n-1 tokens have been processed and there are more value separators
- * in the value, parsing is ceased and the remaining characters are
- * added as a single token.
- *
- * @param value The String to be processed.
- *
- * @since 1.0.1
- */
- private void processValue(String value)
- {
- // this Option has a separator character
- if (hasValueSeparator())
- {
- // get the separator character
- char sep = getValueSeparator();
-
- // store the index for the value separator
- int index = value.indexOf(sep);
-
- // while there are more value separators
- while (index != -1)
- {
- // next value to be added
- if (values.size() == (numberOfArgs - 1))
- {
- break;
- }
-
-
- // store
- add(value.substring(0, index));
-
-
- // parse
- value = value.substring(index + 1);
-
-
- // get new index
- index = value.indexOf(sep);
- }
- }
-
-
- // store the actual value or the last value that has been parsed
- add(value);
- }
-
- /**
- * Add the value to this Option. If the number of arguments
- * is greater than zero and there is enough space in the list then
- * add the value. Otherwise, throw a runtime exception.
- *
- * @param value The value to be added to this Option
- *
- * @since 1.0.1
- */
- private void add(String value)
- {
- if ((numberOfArgs > 0) && (values.size() > (numberOfArgs - 1)))
- {
- throw new RuntimeException("Cannot add value, list full.");
- }
-
-
- // store value
- this.values.add(value);
- }
-
- /**
- * Returns the specified value of this Option or
- * <code>null</code> if there is no value.
- *
- * @return the value/first value of this Option or
- * <code>null</code> if there is no value.
- */
- public String getValue()
- {
- return hasNoValues() ? null : (String) this.values.get(0);
- }
-
- /**
- * Returns the specified value of this Option or
- * <code>null</code> if there is no value.
- *
- * @param index The index of the value to be returned.
- *
- * @return the specified value of this Option or
- * <code>null</code> if there is no value.
- *
- * @throws IndexOutOfBoundsException if index is less than 1
- * or greater than the number of the values for this Option.
- */
- public String getValue(int index)
- throws IndexOutOfBoundsException
- {
- return hasNoValues() ? null : (String) this.values.get(index);
- }
-
- /**
- * Returns the value/first value of this Option or the
- * <code>defaultValue</code> if there is no value.
- *
- * @param defaultValue The value to be returned if ther
- * is no value.
- *
- * @return the value/first value of this Option or the
- * <code>defaultValue</code> if there are no values.
- */
- public String getValue(String defaultValue)
- {
- String value = getValue();
-
- return (value != null) ? value : defaultValue;
- }
-
- /**
- * Return the values of this Option as a String array
- * or null if there are no values
- *
- * @return the values of this Option as a String array
- * or null if there are no values
- */
- public String[] getValues()
- {
- return hasNoValues()
- ? null : (String[]) this.values.toArray(new String[] { });
- }
-
- /**
- * @return the values of this Option as a List
- * or null if there are no values
- */
- public java.util.List getValuesList()
- {
- return this.values;
- }
-
- /**
- * Dump state, suitable for debugging.
- *
- * @return Stringified form of this object
- */
- public String toString()
- {
- StringBuffer buf = new StringBuffer().append("[ option: ");
-
- buf.append(this.opt);
-
- if (this.longOpt != null)
- {
- buf.append(" ").append(this.longOpt);
- }
-
- buf.append(" ");
-
- if (hasArg)
- {
- buf.append("+ARG");
- }
-
- buf.append(" :: ").append(this.description);
-
- if (this.type != null)
- {
- buf.append(" :: ").append(this.type);
- }
-
- buf.append(" ]");
-
- return buf.toString();
- }
-
- /**
- * Returns whether this Option has any values.
- *
- * @return whether this Option has any values.
- */
- private boolean hasNoValues()
- {
- return this.values.size() == 0;
- }
-}