http://git-wip-us.apache.org/repos/asf/commons-cli/blob/9e65354f/src/java/org/apache/commons/cli/OptionBuilder.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/commons/cli/OptionBuilder.java b/src/java/org/apache/commons/cli/OptionBuilder.java deleted file mode 100644 index e1ac1af..0000000 --- a/src/java/org/apache/commons/cli/OptionBuilder.java +++ /dev/null @@ -1,372 +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>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> - * - * @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 to prevent instances being created - */ - private OptionBuilder() - { - // hide the constructor - } - - /** - * Resets the member variables to their default values. - */ - private static void reset() - { - description = null; - argName = "arg"; - longopt = null; - type = null; - required = false; - numberOfArgs = Option.UNINITIALIZED; - - - // PMM 9/6/02 - these were missing - optionalArg = false; - valuesep = (char) 0; - } - - /** - * The next Option created will have the following long option value. - * - * @param newLongopt the long option value - * @return the OptionBuilder instance - */ - public static OptionBuilder withLongOpt(String newLongopt) - { - OptionBuilder.longopt = newLongopt; - - return instance; - } - - /** - * The next Option created will require an argument value. - * - * @return the OptionBuilder instance - */ - public static OptionBuilder hasArg() - { - OptionBuilder.numberOfArgs = 1; - - return instance; - } - - /** - * The next Option created will require an argument value if - * <code>hasArg</code> is true. - * - * @param hasArg if true then the Option has an argument value - * @return the OptionBuilder instance - */ - public static OptionBuilder hasArg(boolean hasArg) - { - OptionBuilder.numberOfArgs = (hasArg == true) ? 1 : Option.UNINITIALIZED; - - return instance; - } - - /** - * The next Option created will have the specified argument value - * name. - * - * @param name the name for the argument value - * @return the OptionBuilder instance - */ - public static OptionBuilder withArgName(String name) - { - OptionBuilder.argName = name; - - return instance; - } - - /** - * The next Option created will be required. - * - * @return the OptionBuilder instance - */ - public static OptionBuilder isRequired() - { - OptionBuilder.required = true; - - return instance; - } - - /** - * The next Option created uses <code>sep</code> as a means to - * separate argument values. - * - * <b>Example:</b> - * <pre> - * Option opt = OptionBuilder.withValueSeparator(':') - * .create('D'); - * - * 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) - { - OptionBuilder.valuesep = sep; - - return instance; - } - - /** - * The next Option created uses '<code>=</code>' as a means to - * separate argument values. - * - * <b>Example:</b> - * <pre> - * Option opt = OptionBuilder.withValueSeparator() - * .create('D'); - * - * CommandLine line = parser.parse(args); - * String propertyName = opt.getValue(0); - * String propertyValue = opt.getValue(1); - * </pre> - * - * @return the OptionBuilder instance - */ - public static OptionBuilder withValueSeparator() - { - OptionBuilder.valuesep = '='; - - return instance; - } - - /** - * The next Option created will be required if <code>required</code> - * is true. - * - * @param newRequired if true then the Option is required - * @return the OptionBuilder instance - */ - public static OptionBuilder isRequired(boolean newRequired) - { - OptionBuilder.required = newRequired; - - return instance; - } - - /** - * The next Option created can have unlimited argument values. - * - * @return the OptionBuilder instance - */ - public static OptionBuilder hasArgs() - { - OptionBuilder.numberOfArgs = Option.UNLIMITED_VALUES; - - return instance; - } - - /** - * The next Option created can have <code>num</code> - * argument values. - * - * @param num the number of args that the option can have - * @return the OptionBuilder instance - */ - public static OptionBuilder hasArgs(int num) - { - OptionBuilder.numberOfArgs = num; - - return instance; - } - - /** - * The next Option can have an optional argument. - * - * @return the OptionBuilder instance - */ - public static OptionBuilder hasOptionalArg() - { - OptionBuilder.numberOfArgs = 1; - OptionBuilder.optionalArg = true; - - return instance; - } - - /** - * The next Option can have an unlimited number of - * optional arguments. - * - * @return the OptionBuilder instance - */ - public static OptionBuilder hasOptionalArgs() - { - OptionBuilder.numberOfArgs = Option.UNLIMITED_VALUES; - OptionBuilder.optionalArg = true; - - return instance; - } - - /** - * The next Option can have the specified number of - * optional arguments. - * - * @param numArgs - the maximum number of optional arguments - * the next Option created can have. - * @return the OptionBuilder instance - */ - public static OptionBuilder hasOptionalArgs(int numArgs) - { - OptionBuilder.numberOfArgs = numArgs; - OptionBuilder.optionalArg = true; - - return instance; - } - - /** - * The next Option created will have a value that will be an instance - * of <code>type</code>. - * - * @param newType the type of the Options argument value - * @return the OptionBuilder instance - */ - public static OptionBuilder withType(Object newType) - { - OptionBuilder.type = newType; - - return instance; - } - - /** - * The next Option created will have the specified description - * - * @param newDescription a description of the Option's purpose - * @return the OptionBuilder instance - */ - public static OptionBuilder withDescription(String newDescription) - { - OptionBuilder.description = newDescription; - - return instance; - } - - /** - * Create an Option using the current settings and with - * the specified Option <code>char</code>. - * - * @param opt the character representation of the Option - * @return the Option instance - * @throws IllegalArgumentException if <code>opt</code> is not - * a valid character. See Option. - */ - public static Option create(char opt) - throws IllegalArgumentException - { - return create(String.valueOf(opt)); - } - - /** - * Create an Option using the current settings - * - * @return the Option instance - * @throws IllegalArgumentException if <code>longOpt</code> has - * not been set. - */ - public static Option create() - throws IllegalArgumentException - { - if (longopt == null) - { - throw new IllegalArgumentException("must specify longopt"); - } - - return create(null); - } - - /** - * Create an Option using the current settings and with - * the specified Option <code>char</code>. - * - * @param opt the <code>java.lang.String</code> representation - * of the Option - * @return the Option instance - * @throws IllegalArgumentException if <code>opt</code> is not - * a valid character. See Option. - */ - public static Option create(String opt) - throws IllegalArgumentException - { - // create the option - 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); - - - // reset the OptionBuilder properties - OptionBuilder.reset(); - - // return the Option instance - return option; - } -} \ No newline at end of file
http://git-wip-us.apache.org/repos/asf/commons-cli/blob/9e65354f/src/java/org/apache/commons/cli/OptionGroup.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/commons/cli/OptionGroup.java b/src/java/org/apache/commons/cli/OptionGroup.java deleted file mode 100644 index 905a10f..0000000 --- a/src/java/org/apache/commons/cli/OptionGroup.java +++ /dev/null @@ -1,162 +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; - -/** - * A group of mutually exclusive options. - * @author John Keyes ( john at integralsource.com ) - * @version $Revision$ - */ -public class OptionGroup { - - /** hold the options */ - private HashMap optionMap = new HashMap(); - - /** the name of the selected option */ - private String selected; - - /** specified whether this group is required */ - private boolean required; - - /** - * add <code>opt</code> to this group - * - * @param opt the option to add to this group - * @return this option group with opt added - */ - public OptionGroup addOption(Option opt) - { - // key - option name - // value - the option - optionMap.put(opt.getKey(), opt); - - return this; - } - - /** - * @return the names of the options in this group as a - * <code>Collection</code> - */ - public Collection getNames() - { - // the key set is the collection of names - return optionMap.keySet(); - } - - /** - * @return the options in this group as a <code>Collection</code> - */ - public Collection getOptions() - { - // the values are the collection of options - return optionMap.values(); - } - - /** - * set the selected option of this group to <code>name</code>. - * @param opt the option that is selected - * @throws AlreadySelectedException if an option from this group has - * already been selected. - */ - 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())) - { - this.selected = opt.getOpt(); - } - else - { - throw new AlreadySelectedException("an option from this group has " - + "already been selected: '" - + selected + "'"); - } - } - - /** - * @return the selected option name - */ - public String getSelected() - { - return selected; - } - - /** - * @param required specifies if this group is required - */ - public void setRequired(boolean required) - { - this.required = required; - } - - /** - * Returns whether this option group is required. - * - * @return whether this option group is required - */ - public boolean isRequired() - { - return this.required; - } - - /** - * <p>Returns the stringified version of this OptionGroup.</p> - * @return the stringified representation of this group - */ - 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()); - } - else - { - buff.append("--"); - buff.append(option.getLongOpt()); - } - - buff.append(" "); - buff.append(option.getDescription()); - - if (iter.hasNext()) - { - buff.append(", "); - } - } - - buff.append("]"); - - return buff.toString(); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/commons-cli/blob/9e65354f/src/java/org/apache/commons/cli/OptionValidator.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/commons/cli/OptionValidator.java b/src/java/org/apache/commons/cli/OptionValidator.java deleted file mode 100644 index 5096182..0000000 --- a/src/java/org/apache/commons/cli/OptionValidator.java +++ /dev/null @@ -1,100 +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; - -/** - * Validates an Option string. - * - * @author John Keyes ( john at integralsource.com ) - */ -public class OptionValidator { - - /** - * <p>Validates whether <code>opt</code> is a permissable Option - * shortOpt. The rules that specify if the <code>opt</code> - * is valid are:</p> - * <ul> - * <li><code>opt</code> is not NULL</li> - * <li>a single character <code>opt</code> that is either - * ' '(special case), '?', '@' or a letter</li> - * <li>a multi character <code>opt</code> that only contains - * letters.</li> - * </ul> - * - * @param opt The option string to validate - * @throws IllegalArgumentException if the Option is not valid. - */ - static void validateOption(String opt) - throws IllegalArgumentException - { - // check that opt is not 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 - + "'"); - } - } - - // handle the multi character opt - 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] - + "'"); - } - } - } - } - - /** - * <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. - */ - private static boolean isValidOpt(char c) - { - return (isValidChar(c) || (c == ' ') || (c == '?') || c == '@'); - } - - /** - * <p>Returns whether the specified character is a valid character.</p> - * - * @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); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/commons-cli/blob/9e65354f/src/java/org/apache/commons/cli/Options.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/commons/cli/Options.java b/src/java/org/apache/commons/cli/Options.java deleted file mode 100644 index 815c6a3..0000000 --- a/src/java/org/apache/commons/cli/Options.java +++ /dev/null @@ -1,277 +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; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -/** <p>Main entry-point into the library.</p> - * - * <p>Options represents a collection of {@link Option} objects, which - * describe the possible options for a command-line.<p> - * - * <p>It may flexibly parse long and short options, with or without - * values. Additionally, it may parse only a portion of a commandline, - * allowing for flexible multi-stage parsing.<p> - * - * @see org.apache.commons.cli.CommandLine - * - * @author bob mcwhirter (bob @ werken.com) - * @author <a href="mailto:[email protected]">James Strachan</a> - * @version $Revision$ - */ -public class Options { - - /** a map of the options with the character key */ - private Map shortOpts = new HashMap(); - - /** a map of the options with the long key */ - 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(); - - /** Construct a new Options descriptor - */ - public Options() - { - // nothing to do - } - - /** - * Add the specified option group. - * - * @param group the OptionGroup that is to be added - * @return the resulting Options instance - */ - public Options addOptionGroup(OptionGroup group) - { - Iterator options = group.getOptions().iterator(); - - if (group.isRequired()) - { - requiredOpts.add(group); - } - - 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); - - optionGroups.put(option.getKey(), group); - } - - return this; - } - - /** - * Lists the OptionGroups that are members of this Options instance. - * @return a Collection of OptionGroup instances. - */ - Collection getOptionGroups(){ - return new HashSet(optionGroups.values()); - } - - /** - * Add an option that only contains a short-name. - * It may be specified as requiring an argument. - * - * @param opt Short single-character name of the option. - * @param hasArg flag signally if an argument is required after this option - * @param description Self-documenting description - * @return the resulting Options instance - */ - public Options addOption(String opt, boolean hasArg, String description) - { - addOption(opt, null, hasArg, description); - - return this; - } - - /** - * Add an option that contains a short-name and a long-name. - * It may be specified as requiring an argument. - * - * @param opt Short single-character name of the option. - * @param longOpt Long multi-character name of the option. - * @param hasArg flag signally if an argument is required after this option - * @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)); - - return this; - } - - /** - * Adds an option instance - * - * @param opt the option that is to be added - * @return the resulting Options instance - */ - 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 the option is required add it to the required list - if (opt.isRequired() ) - { - if( requiredOpts.contains(key) ) { - requiredOpts.remove( requiredOpts.indexOf(key) ); - } - requiredOpts.add(key); - } - - shortOpts.put(key, opt); - - return this; - } - - /** - * Retrieve a read-only list of options in this set - * - * @return read-only Collection of {@link Option} objects in this descriptor - */ - public Collection getOptions() - { - return Collections.unmodifiableCollection(helpOptions()); - } - - /** - * Returns the Options for use by the HelpFormatter. - * - * @return the List of Options - */ - 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); - } - - /** - * Returns the required options as a - * <code>java.util.Collection</code>. - * - * @return Collection of required options - */ - public List getRequiredOptions() - { - return requiredOpts; - } - - /** - * Retrieve the named {@link Option} - * - * @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); - - if (shortOpts.containsKey(opt)) - { - return (Option) shortOpts.get(opt); - } - - return (Option) longOpts.get(opt); - } - - /** - * Returns whether the named {@link Option} is a member - * of this {@link Options}. - * - * @param opt short or long name of the {@link Option} - * @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); - } - - /** - * Returns the OptionGroup the <code>opt</code> - * belongs to. - * @param opt the option whose OptionGroup is being queried. - * - * @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()); - } - - /** - * Dump state, suitable for debugging. - * - * @return Stringified form of this object - */ - public String toString() - { - StringBuffer buf = new StringBuffer(); - - buf.append("[ Options: [ short "); - buf.append(shortOpts.toString()); - buf.append(" ] [ long "); - buf.append(longOpts); - buf.append(" ]"); - - return buf.toString(); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/commons-cli/blob/9e65354f/src/java/org/apache/commons/cli/ParseException.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/commons/cli/ParseException.java b/src/java/org/apache/commons/cli/ParseException.java deleted file mode 100644 index 9b06536..0000000 --- a/src/java/org/apache/commons/cli/ParseException.java +++ /dev/null @@ -1,36 +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>Base for Exceptions thrown during parsing of a command-line.</p> - * - * @author bob mcwhirter (bob @ werken.com) - * @version $Revision$ - */ -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); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/commons-cli/blob/9e65354f/src/java/org/apache/commons/cli/Parser.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/commons/cli/Parser.java b/src/java/org/apache/commons/cli/Parser.java deleted file mode 100644 index 8eb336c..0000000 --- a/src/java/org/apache/commons/cli/Parser.java +++ /dev/null @@ -1,406 +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.Arrays; -import java.util.Enumeration; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; -import java.util.Properties; - -/** - * <p><code>Parser</code> creates {@link CommandLine}s.</p> - * - * @author John Keyes (john at integralsource.com) - * @see Parser - * @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; - - /** - * <p>Subclasses must implement this method to reduce - * the <code>arguments</code> that have been passed to the parse - * method.</p> - * - * @param opts 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 abstract String[] flatten(Options opts, String[] arguments, - boolean stopAtNonOption); - - /** - * <p>Parses the specified <code>arguments</code> - * based on the specifed {@link Options}.</p> - * - * @param options the <code>Options</code> - * @param arguments the <code>arguments</code> - * @return the <code>CommandLine</code> - * @throws ParseException if an error occurs when parsing the - * arguments. - */ - public CommandLine parse(Options options, String[] arguments) - throws ParseException - { - return parse(options, arguments, null, false); - } - - /** - * 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. - */ - public CommandLine parse(Options options, String[] arguments, - Properties properties) - throws ParseException - { - return parse(options, arguments, properties, false); - } - - /** - * <p>Parses the specified <code>arguments</code> - * based on the specifed {@link Options}.</p> - * - * @param options the <code>Options</code> - * @param arguments the <code>arguments</code> - * @param stopAtNonOption specifies whether to stop - * interpreting the arguments when a non option has - * been encountered and to add them to the CommandLines - * args list. - * - * @return the <code>CommandLine</code> - * @throws ParseException if an error occurs when parsing the - * arguments. - */ - public CommandLine parse(Options options, String[] arguments, - boolean stopAtNonOption) - throws ParseException - { - return parse(options, arguments, null, stopAtNonOption); - } - - /** - * 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 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 options, String[] arguments, - Properties properties, boolean stopAtNonOption) - throws ParseException - { - // initialise members - this.options = options; - requiredOptions = options.getRequiredOptions(); - cmd = new CommandLine(); - - boolean eatTheRest = false; - - if (arguments == null) - { - arguments = new String[0]; - } - - 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(); - - // the value is the double-dash - if ("--".equals(t)) - { - eatTheRest = true; - } - - // the value is a single dash - else if ("-".equals(t)) - { - if (stopAtNonOption) - { - eatTheRest = true; - } - else - { - cmd.addArg(t); - } - } - - // the value is an option - else if (t.startsWith("-")) - { - if (stopAtNonOption && !options.hasOption(t)) - { - eatTheRest = true; - cmd.addArg(t); - } - else - { - processOption(t, iterator); - } - } - - // the value is an argument - else - { - cmd.addArg(t); - - if (stopAtNonOption) - { - eatTheRest = true; - } - } - - // eat the remaining tokens - if (eatTheRest) - { - while (iterator.hasNext()) - { - String str = (String) iterator.next(); - - // ensure only one double-dash is added - if (!"--".equals(str)) - { - cmd.addArg(str); - } - } - } - } - - processProperties(properties); - checkRequiredOptions(); - - return cmd; - } - - /** - * <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) - { - return; - } - - for (Enumeration e = properties.propertyNames(); e.hasMoreElements();) - { - String option = e.nextElement().toString(); - - 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 - } - } - } - 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); - } - } - } - - /** - * <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 - { - // if there are required options that have not been - // processsed - if (requiredOptions.size() > 0) - { - Iterator iter = requiredOptions.iterator(); - StringBuffer buff = new StringBuffer(); - - // loop through the required options - while (iter.hasNext()) - { - buff.append(iter.next()); - } - - throw new MissingOptionException(buff.toString()); - } - } - - /** - * <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, not an argument - if (options.hasOption(str) && str.startsWith("-")) - { - iter.previous(); - break; - } - - // found a value - try - { - opt.addValue( Util.stripLeadingAndTrailingQuotes(str) ); - } - catch (RuntimeException exp) - { - iter.previous(); - break; - } - } - - if ((opt.getValues() == null) && !opt.hasOptionalArg()) - { - throw new MissingArgumentException("Missing argument for option:" - + opt.getKey()); - } - } - - /** - * <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 - { - boolean hasOption = options.hasOption(arg); - - // if there is no option throw an UnrecognisedOptionException - 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 the option is in an OptionGroup make that option the selected - // option of the group - if (options.getOptionGroup(opt) != null) - { - OptionGroup group = options.getOptionGroup(opt); - - if (group.isRequired()) - { - requiredOptions.remove(group); - } - - group.setSelected(opt); - } - - // if the option takes an argument value - if (opt.hasArg()) - { - processArgs(opt, iter); - } - - - // set the option on the command line - cmd.addOption(opt); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/commons-cli/blob/9e65354f/src/java/org/apache/commons/cli/PatternOptionBuilder.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/commons/cli/PatternOptionBuilder.java b/src/java/org/apache/commons/cli/PatternOptionBuilder.java deleted file mode 100644 index a359d60..0000000 --- a/src/java/org/apache/commons/cli/PatternOptionBuilder.java +++ /dev/null @@ -1,211 +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> - * 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$ - */ -public class PatternOptionBuilder { - - /** String class */ - public static final Class STRING_VALUE = java.lang.String.class; - - /** Object class */ - public static final Class OBJECT_VALUE = java.lang.Object.class; - - /** Number class */ - public static final Class NUMBER_VALUE = java.lang.Number.class; - - /** Date class */ - public static final Class DATE_VALUE = java.util.Date.class; - - /** 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. - - /** 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; - - /** File array class */ - public static final Class FILES_VALUE = java.io.File[].class; - - /** URL class */ - public static final Class URL_VALUE = java.net.URL.class; - - /** - * <p>Retrieve the class that <code>ch</code> represents.</p> - * - * @param ch the specified character - * @return The class that <code>ch</code> represents - */ - public static Object getValueClass(char ch) - { - if (ch == '@') - { - return PatternOptionBuilder.OBJECT_VALUE; - } - else if (ch == ':') - { - return PatternOptionBuilder.STRING_VALUE; - } - else if (ch == '%') - { - return PatternOptionBuilder.NUMBER_VALUE; - } - else if (ch == '+') - { - return PatternOptionBuilder.CLASS_VALUE; - } - else if (ch == '#') - { - return PatternOptionBuilder.DATE_VALUE; - } - else if (ch == '<') - { - return PatternOptionBuilder.EXISTING_FILE_VALUE; - } - else if (ch == '>') - { - return PatternOptionBuilder.FILE_VALUE; - } - else if (ch == '*') - { - return PatternOptionBuilder.FILES_VALUE; - } - 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> - * - * @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 != '/') && (ch != '!')) - { - return false; - } - - return true; - } - - /** - * <p>Returns the {@link Options} instance represented by - * <code>pattern</code>.</p> - * - * @param pattern the pattern string - * @return The {@link Options} instance - */ - public static Options parsePattern(String pattern) - { - int sz = pattern.length(); - - char opt = ' '; - char ch = ' '; - boolean required = false; - Object type = null; - - Options options = new Options(); - - 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 != ' ') - { - OptionBuilder.hasArg(type != null); - OptionBuilder.isRequired(required); - OptionBuilder.withType(type); - - // we have a previous one to deal with - options.addOption(OptionBuilder.create(opt)); - required = false; - type = null; - opt = ' '; - } - - opt = ch; - } - else if (ch == '!') - { - required = true; - } - else - { - type = getValueClass(ch); - } - } - - if (opt != ' ') - { - OptionBuilder.hasArg(type != null); - OptionBuilder.isRequired(required); - OptionBuilder.withType(type); - - // we have a final one to deal with - options.addOption(OptionBuilder.create(opt)); - } - - return options; - } -} http://git-wip-us.apache.org/repos/asf/commons-cli/blob/9e65354f/src/java/org/apache/commons/cli/PosixParser.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/commons/cli/PosixParser.java b/src/java/org/apache/commons/cli/PosixParser.java deleted file mode 100644 index f3c9d0d..0000000 --- a/src/java/org/apache/commons/cli/PosixParser.java +++ /dev/null @@ -1,309 +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; -import java.util.Arrays; -import java.util.Iterator; - -/** - * The class PosixParser 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 PosixParser extends Parser { - - /** holder for flattened tokens */ - private ArrayList tokens = new ArrayList(); - - /** specifies if bursting should continue */ - private boolean eatTheRest; - - /** holder for the current option */ - private Option currentOption; - - /** the command line Options */ - private Options options; - - /** - * <p>Resets the members to their original state i.e. remove - * all of <code>tokens</code> entries, set <code>eatTheRest</code> - * to false and set <code>currentOption</code> to null.</p> - */ - private void init() - { - eatTheRest = false; - tokens.clear(); - currentOption = null; - } - - /** - * <p>An implementation of {@link Parser}'s abstract - * {@link Parser#flatten(Options,String[],boolean) flatten} method.</p> - * - * <p>The following are the rules used by this flatten method. - * <ol> - * <li>if <code>stopAtNonOption</code> is <b>true</b> then do not - * burst anymore of <code>arguments</code> entries, just add each - * successive entry without further processing. Otherwise, ignore - * <code>stopAtNonOption</code>.</li> - * <li>if the current <code>arguments</code> entry is "<b>--</b>" - * just add the entry to the list of processed tokens</li> - * <li>if the current <code>arguments</code> entry is "<b>-</b>" - * just add the entry to the list of processed tokens</li> - * <li>if the current <code>arguments</code> entry is two characters - * in length and the first character is "<b>-</b>" then check if this - * is a valid {@link Option} id. If it is a valid id, then add the - * entry to the list of processed tokens and set the current {@link Option} - * member. If it is not a valid id and <code>stopAtNonOption</code> - * is true, then the remaining entries are copied to the list of - * processed tokens. Otherwise, the current entry is ignored.</li> - * <li>if the current <code>arguments</code> entry is more than two - * characters in length and the first character is "<b>-</b>" then - * we need to burst the entry to determine its constituents. For more - * information on the bursting algorithm see - * {@link PosixParser#burstToken(String, boolean) burstToken}.</li> - * <li>if the current <code>arguments</code> entry is not handled - * by any of the previous rules, then the entry is added to the list - * of processed tokens.</li> - * </ol> - * </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 flattened <code>arguments</code> String array. - */ - protected String[] flatten(Options options, String[] arguments, - boolean stopAtNonOption) - { - init(); - this.options = options; - - // an iterator for the command line tokens - Iterator iter = Arrays.asList(arguments).iterator(); - String token = null; - - // process each command line token - while (iter.hasNext()) - { - // get the next command line token - token = (String) iter.next(); - - // handle SPECIAL TOKEN - if (token.startsWith("--")) - { - if (token.indexOf('=') != -1) - { - tokens.add(token.substring(0, token.indexOf('='))); - tokens.add(token.substring(token.indexOf('=') + 1, - token.length())); - } - else - { - tokens.add(token); - } - } - - // single hyphen - else if ("-".equals(token)) - { - processSingleHyphen(token); - } - else if (token.startsWith("-")) - { - int tokenLength = token.length(); - - if (tokenLength == 2) - { - processOptionToken(token, stopAtNonOption); - } - else if (options.hasOption(token)) { - tokens.add(token); - } - // requires bursting - else - { - burstToken(token, stopAtNonOption); - } - } - else - { - if (stopAtNonOption) - { - process(token); - } - else - { - tokens.add(token); - } - } - - gobble(iter); - } - - return (String[]) tokens.toArray(new String[] { }); - } - - /** - * <p>Adds the remaining tokens to the processed tokens list.</p> - * - * @param iter An iterator over the remaining tokens - */ - private void gobble(Iterator iter) - { - if (eatTheRest) - { - while (iter.hasNext()) - { - tokens.add(iter.next()); - } - } - } - - /** - * <p>If there is a current option and it can have an argument - * value then add the token to the processed tokens list and - * set the current option to null.</p> - * <p>If there is a current option and it can have argument - * values then add the token to the processed tokens list.</p> - * <p>If there is not a current option add the special token - * "<b>--</b>" and the current <code>value</code> to the processed - * tokens list. The add all the remaining <code>argument</code> - * values to the processed tokens list.</p> - * - * @param value The current token - */ - private void process(String value) - { - if ((currentOption != null) && currentOption.hasArg()) - { - if (currentOption.hasArg()) - { - tokens.add(value); - currentOption = null; - } - else if (currentOption.hasArgs()) - { - tokens.add(value); - } - } - else - { - eatTheRest = true; - tokens.add("--"); - tokens.add(value); - } - } - - /** - * <p>If it is a hyphen then add the hyphen directly to - * the processed tokens list.</p> - * - * @param hyphen The hyphen token - */ - private void processSingleHyphen(String hyphen) - { - tokens.add(hyphen); - } - - /** - * <p>If an {@link Option} exists for <code>token</code> then - * set the current option and add the token to the processed - * list.</p> - * <p>If an {@link Option} does not exist and <code>stopAtNonOption</code> - * is set then ignore the current token and add the remaining tokens - * to the processed tokens list directly.</p> - * - * @param token The current option token - * @param stopAtNonOption Specifies whether flattening should halt - * at the first non option. - */ - private void processOptionToken(String token, boolean stopAtNonOption) - { - if (this.options.hasOption(token)) - { - currentOption = this.options.getOption(token); - tokens.add(token); - } - else if (stopAtNonOption) - { - eatTheRest = true; - } - } - - /** - * <p>Breaks <code>token</code> into its constituent parts - * using the following algorithm. - * <ul> - * <li>ignore the first character ("<b>-</b>")</li> - * <li>foreach remaining character check if an {@link Option} - * exists with that id.</li> - * <li>if an {@link Option} does exist then add that character - * prepended with "<b>-</b>" to the list of processed tokens.</li> - * <li>if the {@link Option} can have an argument value and there - * are remaining characters in the token then add the remaining - * characters as a token to the list of processed tokens.</li> - * <li>if an {@link Option} does <b>NOT</b> exist <b>AND</b> - * <code>stopAtNonOption</code> <b>IS</b> set then add the special token - * "<b>--</b>" followed by the remaining characters and also - * the remaining tokens directly to the processed tokens list.</li> - * <li>if an {@link Option} does <b>NOT</b> exist <b>AND</b> - * <code>stopAtNonOption</code> <b>IS NOT</b> set then add that - * character prepended with "<b>-</b>".</li> - * </ul> - * </p> - * - * @param token The current token to be <b>burst</b> - * @param stopAtNonOption Specifies whether to stop processing - * at the first non-Option encountered. - */ - protected void burstToken(String token, boolean stopAtNonOption) - { - int tokenLength = token.length(); - - for (int i = 1; i < tokenLength; i++) - { - String ch = String.valueOf(token.charAt(i)); - boolean hasOption = options.hasOption(ch); - - if (hasOption) - { - tokens.add("-" + ch); - currentOption = options.getOption(ch); - - if (currentOption.hasArg() && (token.length() != (i + 1))) - { - tokens.add(token.substring(i + 1)); - - break; - } - } - else if (stopAtNonOption) - { - process(token.substring(i)); - } - else - { - tokens.add("-" + ch); - } - } - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/commons-cli/blob/9e65354f/src/java/org/apache/commons/cli/TypeHandler.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/commons/cli/TypeHandler.java b/src/java/org/apache/commons/cli/TypeHandler.java deleted file mode 100644 index 84e48bb..0000000 --- a/src/java/org/apache/commons/cli/TypeHandler.java +++ /dev/null @@ -1,257 +0,0 @@ -/* - * Copyright 1999-2005 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.File; - -import java.net.MalformedURLException; -import java.net.URL; - -import java.util.Date; - -import org.apache.commons.lang.math.NumberUtils; - -/** - * This is a temporary implementation. TypeHandler will handle the - * pluggableness of OptionTypes and it will direct all of these types - * of conversion functionalities to ConvertUtils component in Commons - * alreayd. BeanUtils I think. - * - * @author Henri Yandell (bayard @ generationjava.com) - * @version $Revision$ - */ -public class TypeHandler { - - /** - * <p>Returns the <code>Object</code> of type <code>obj</code> - * with the value of <code>str</code>.</p> - * - * @param str the command line value - * @param obj the type of argument - * @return The instance of <code>obj</code> initialised with - * the value of <code>str</code>. - */ - public static Object createValue(String str, Object obj) - { - return createValue(str, (Class) obj); - } - - /** - * <p>Returns the <code>Object</code> of type <code>clazz</code> - * with the value of <code>str</code>.</p> - * - * @param str the command line value - * @param clazz the type of argument - * @return The instance of <code>clazz</code> initialised with - * the value of <code>str</code>. - */ - public static Object createValue(String str, Class clazz) - { - if (PatternOptionBuilder.STRING_VALUE == clazz) - { - return str; - } - else if (PatternOptionBuilder.OBJECT_VALUE == clazz) - { - return createObject(str); - } - else if (PatternOptionBuilder.NUMBER_VALUE == clazz) - { - return createNumber(str); - } - else if (PatternOptionBuilder.DATE_VALUE == clazz) - { - return createDate(str); - } - else if (PatternOptionBuilder.CLASS_VALUE == clazz) - { - return createClass(str); - } - else if (PatternOptionBuilder.FILE_VALUE == clazz) - { - return createFile(str); - } - else if (PatternOptionBuilder.EXISTING_FILE_VALUE == clazz) - { - return createFile(str); - } - else if (PatternOptionBuilder.FILES_VALUE == clazz) - { - return createFiles(str); - } - else if (PatternOptionBuilder.URL_VALUE == clazz) - { - return createURL(str); - } - else - { - return null; - } - } - - /** - * <p>Create an Object from the classname and empty constructor.</p> - * - * @param str the argument value - * @return the initialised object, or null if it couldn't create - * the Object. - */ - public static Object createObject(String str) - { - Class cl = null; - - try - { - cl = Class.forName(str); - } - catch (ClassNotFoundException cnfe) - { - System.err.println("Unable to find: " + str); - - return null; - } - - Object instance = null; - - try - { - instance = cl.newInstance(); - } - catch (InstantiationException cnfe) - { - System.err.println("InstantiationException; Unable to create: " - + str); - - return null; - } - catch (IllegalAccessException cnfe) - { - System.err.println("IllegalAccessException; Unable to create: " - + str); - - return null; - } - - return instance; - } - - /** - * <p>Create a number from a String.</p> - * - * @param str the value - * @return the number represented by <code>str</code>, if <code>str</code> - * is not a number, null is returned. - */ - public static Number createNumber(String str) - { - // Needs to be able to create - try - { - // do searching for decimal point etc, but atm just make an Integer - return NumberUtils.createNumber(str); - } - catch (NumberFormatException nfe) - { - System.err.println(nfe.getMessage()); - - return null; - } - } - - /** - * <p>Returns the class whose name is <code>str</code>.</p> - * - * @param str the class name - * @return The class if it is found, otherwise return null - */ - public static Class createClass(String str) - { - try - { - return Class.forName(str); - } - catch (ClassNotFoundException cnfe) - { - System.err.println("Unable to find: " + str); - - return null; - } - } - - /** - * <p>Returns the date represented by <code>str</code>.</p> - * - * @param str the date string - * @return The date if <code>str</code> is a valid date string, - * otherwise return null. - */ - public static Date createDate(String str) - { - Date date = null; - - if (date == null) - { - System.err.println("Unable to parse: " + str); - } - - return date; - } - - /** - * <p>Returns the URL represented by <code>str</code>.</p> - * - * @param str the URL string - * @return The URL is <code>str</code> is well-formed, otherwise - * return null. - */ - public static URL createURL(String str) - { - try - { - return new URL(str); - } - catch (MalformedURLException mue) - { - System.err.println("Unable to parse: " + str); - - return null; - } - } - - /** - * <p>Returns the File represented by <code>str</code>.</p> - * - * @param str the File location - * @return The file represented by <code>str</code>. - */ - public static File createFile(String str) - { - return new File(str); - } - - /** - * <p>Returns the File[] represented by <code>str</code>.</p> - * - * @param str the paths to the files - * @return The File[] represented by <code>str</code>. - */ - public static File[] createFiles(String str) - { - // to implement/port: - // return FileW.findFiles(str); - return null; - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/commons-cli/blob/9e65354f/src/java/org/apache/commons/cli/UnrecognizedOptionException.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/commons/cli/UnrecognizedOptionException.java b/src/java/org/apache/commons/cli/UnrecognizedOptionException.java deleted file mode 100644 index b417c19..0000000 --- a/src/java/org/apache/commons/cli/UnrecognizedOptionException.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>Exception thrown during parsing signalling an unrecognized - * option was seen.<p> - * - * @author bob mcwhiter (bob @ werken.com) - * @version $Revision$ - */ -public class UnrecognizedOptionException - extends ParseException { - - /** - * <p>Construct a new <code>UnrecognizedArgumentException</code> - * with the specified detail message.</p> - * - * @param message the detail message - */ - public UnrecognizedOptionException(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/Util.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/commons/cli/Util.java b/src/java/org/apache/commons/cli/Util.java deleted file mode 100644 index 86a231b..0000000 --- a/src/java/org/apache/commons/cli/Util.java +++ /dev/null @@ -1,66 +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; - -/** - * Contains useful helper methods for classes within this package. - * - * @author John Keyes (john at integralsource.com) - */ -class Util { - - /** - * <p>Remove the hyphens from the begining of <code>str</code> and - * return the new String.</p> - * - * @param str The string from which the hyphens should be removed. - * - * @return the new String. - */ - static String stripLeadingHyphens(String str) - { - if (str.startsWith("--")) - { - return str.substring(2, str.length()); - } - else if (str.startsWith("-")) - { - return str.substring(1, str.length()); - } - - return str; - } - - /** - * Remove the leading and trailing quotes from <code>str</code>. - * E.g. if str is '"one two"', then 'one two' is returned. - * - * @param str The string from which the leading and trailing quotes - * should be removed. - * - * @return The string without the leading and trailing quotes. - */ - static String stripLeadingAndTrailingQuotes(String str) - { - if (str.startsWith("\"")) { - str = str.substring(1, str.length()); - } - if (str.endsWith("\"")) { - str = str.substring(0, str.length()-1); - } - return str; - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/commons-cli/blob/9e65354f/src/java/org/apache/commons/cli/overview.html ---------------------------------------------------------------------- diff --git a/src/java/org/apache/commons/cli/overview.html b/src/java/org/apache/commons/cli/overview.html deleted file mode 100644 index eadba1e..0000000 --- a/src/java/org/apache/commons/cli/overview.html +++ /dev/null @@ -1,28 +0,0 @@ - -<body> - - <p>Commons CLI -- version ##VERSION## (##QUALITY##)</p> - - <p>The commons-cli package aides in parsing command-line arguments.</p> - - <p>Allow command-line arguments to be parsed against a descriptor of - valid options (long and short), potentially with arguments.</p> - - <p>command-line arguments may be of the typical <code>String[]</code> - form, but also may be a <code>java.util.List</code>. Indexes allow - for parsing only a portion of the command-line. Also, functionality - for parsing the command-line in phases is built in, allowing for - 'cvs-style' command-lines, where some global options are specified - before a 'command' argument, and command-specific options are - specified after the command argument: - - <code> - <pre> - myApp -p <port> command -p <printer> - </pre> - </code> - - - <p>The homepage for the project is - <a href="http://jakarta.apache.org/commons/">jakarta commons/</a> -</body> http://git-wip-us.apache.org/repos/asf/commons-cli/blob/9e65354f/src/java/org/apache/commons/cli/package.html ---------------------------------------------------------------------- diff --git a/src/java/org/apache/commons/cli/package.html b/src/java/org/apache/commons/cli/package.html deleted file mode 100644 index 5bf2066..0000000 --- a/src/java/org/apache/commons/cli/package.html +++ /dev/null @@ -1,6 +0,0 @@ - -<body> - - Commons CLI 1.0 - -</body> http://git-wip-us.apache.org/repos/asf/commons-cli/blob/9e65354f/src/java/org/apache/commons/cli2/Argument.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/commons/cli2/Argument.java b/src/java/org/apache/commons/cli2/Argument.java deleted file mode 100644 index b5fb466..0000000 --- a/src/java/org/apache/commons/cli2/Argument.java +++ /dev/null @@ -1,106 +0,0 @@ -/** - * Copyright 2003-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.cli2; - -import java.util.ListIterator; - -/** - * An Option that can process values passed on the command line in the form - * "--file README". - */ -public interface Argument extends Option { - - /** - * Returns the initial separator character or - * '\0' if no character has been set. - * - * @return char the initial separator character - */ - char getInitialSeparator(); - - /** - * Processes the "README" style element of the argument. - * - * Values identified should be added to the CommandLine object in - * association with this Argument. - * - * @see WriteableCommandLine#addValue(Option,Object) - * - * @param commandLine The CommandLine object to store results in. - * @param args The arguments to process. - * @param option The option to register value against. - * @throws OptionException if any problems occur. - */ - void processValues( - final WriteableCommandLine commandLine, - final ListIterator args, - final Option option) - throws OptionException; - - /** - * Adds defaults to a CommandLine. - * - * @param commandLine - * The CommandLine object to store defaults in. - * @param option - * The Option to store the defaults against. - */ - void defaultValues(final WriteableCommandLine commandLine, final Option option); - - /** - * Performs any necessary validation on the values added to the - * CommandLine. - * - * Validation will typically involve using the - * CommandLine.getValues(option) method to retrieve the values - * and then either checking each value. Optionally the String - * value can be replaced by another Object such as a Number - * instance or a File instance. - * - * @see CommandLine#getValues(Option) - * - * @param commandLine The CommandLine object to query. - * @param option The option to lookup values with. - * @throws OptionException if any problems occur. - */ - void validate(final WriteableCommandLine commandLine, final Option option) - throws OptionException; - - /** - * Indicates whether argument values must be present for the CommandLine to - * be valid. - * - * @see #getMinimum() - * @see #getMaximum() - * @return true iff the CommandLine will be invalid without at least one - * value - */ - boolean isRequired(); - - /** - * Retrieves the minimum number of values required for a valid Argument - * - * @return the minimum number of values - */ - int getMinimum(); - - /** - * Retrieves the maximum number of values acceptable for a valid Argument - * - * @return the maximum number of values - */ - int getMaximum(); -} http://git-wip-us.apache.org/repos/asf/commons-cli/blob/9e65354f/src/java/org/apache/commons/cli2/CommandLine.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/commons/cli2/CommandLine.java b/src/java/org/apache/commons/cli2/CommandLine.java deleted file mode 100644 index cad65ca..0000000 --- a/src/java/org/apache/commons/cli2/CommandLine.java +++ /dev/null @@ -1,214 +0,0 @@ -/** - * Copyright 2003-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.cli2; - -import java.util.List; -import java.util.Set; - -/** - * Instances of CommandLine represent a command line that has been processed - * according to the definition supplied to the parser. - */ -public interface CommandLine { - - /** - * Detects the presence of an option with the specified trigger in this - * CommandLine. - * - * @param trigger the trigger to search for - * @return true iff an option with this trigger is present - */ - boolean hasOption(final String trigger); - - /** - * Detects the presence of an option in this CommandLine. - * - * @param option the Option to search for - * @return true iff the option is present - */ - boolean hasOption(final Option option); - - /** - * Finds the Option with the specified trigger - * - * @param trigger the name of the option to retrieve - * @return the Option matching the trigger or null if none exists - */ - Option getOption(final String trigger); - - /** - * Retrieves the Argument values associated with the specified Option - * - * @param trigger a trigger used to lookup the Option - * @return a list of values or an empty List if none are found - */ - List getValues(final String trigger); - - /** - * Retrieves the Argument values associated with the specified Option - * - * @param trigger a trigger used to lookup the Option - * @param defaultValues the result to return if no values are found - * @return a list of values or defaultValues if none are found - */ - List getValues(final String trigger, final List defaultValues); - - /** - * Retrieves the Argument values associated with the specified Option - * - * @param option the Option associated with the values - * @return a list of values or an empty List if none are found - */ - List getValues(final Option option); - - /** - * Retrieves the Argument values associated with the specified Option - * - * @param option the Option associated with the values - * @param defaultValues the result to return if no values are found - * @return a list of values or defaultValues if none are found - */ - List getValues(final Option option, final List defaultValues); - - /** - * Retrieves the single Argument value associated with the specified Option - * - * @param trigger a trigger used to lookup the Option - * @return the matching value or null if none exists - * @throws IllegalStateException if more than one values are found - */ - Object getValue(final String trigger) throws IllegalStateException; - - /** - * Retrieves the single Argument value associated with the specified Option - * - * @param trigger a trigger used to lookup the Option - * @param defaultValue the result to use if no values are found - * @return the matching value or defaultValue if none exists - * @throws IllegalStateException if more than one values are found - */ - Object getValue(final String trigger, final Object defaultValue) throws IllegalStateException; - - /** - * Retrieves the single Argument value associated with the specified Option - * - * @param option the Option associated with the value - * @return the matching value or null if none exists - * @throws IllegalStateException if more than one values are found - */ - Object getValue(final Option option) throws IllegalStateException; - - /** - * Retrieves the single Argument value associated with the specified Option - * - * @param option the Option associated with the value - * @param defaultValue the result to use if no values are found - * @return the matching value or defaultValue if none exists - * @throws IllegalStateException if more than one values are found - */ - Object getValue(final Option option, final Object defaultValue) throws IllegalStateException; - - /** - * Retrieves the Boolean value associated with the specified Switch - * - * @param trigger a trigger used to lookup the Option - * @return the Boolean associated with trigger or null if none exists - */ - Boolean getSwitch(final String trigger); - - /** - * Retrieves the Boolean value associated with the specified Switch - * - * @param trigger a trigger used to lookup the Option - * @param defaultValue the Boolean to use if none match - * @return the Boolean associated with trigger or defaultValue if none exists - */ - Boolean getSwitch(final String trigger, final Boolean defaultValue); - - /** - * Retrieves the Boolean value associated with the specified Switch - * - * @param option the Option associated with the value - * @return the Boolean associated with option or null if none exists - */ - Boolean getSwitch(final Option option); - - /** - * Retrieves the Boolean value associated with the specified Switch - * - * @param option the Option associated with the value - * @param defaultValue the Boolean to use if none match - * @return the Boolean associated with option or defaultValue if none exists - */ - Boolean getSwitch(final Option option, final Boolean defaultValue); - - - /** - * Retrieves the value associated with the specified property - * - * @param property the property name to lookup - * @return the value of the property or null - */ - String getProperty(final String property); - - /** - * Retrieves the value associated with the specified property - * - * @param property the property name to lookup - * @param defaultValue the value to use if no other is found - * @return the value of the property or defaultValue - */ - String getProperty(final String property, final String defaultValue); - - /** - * Retrieves the set of all property names associated with this CommandLine - * - * @return a none null set of property names - */ - Set getProperties(); - - /** - * Retrieves the number of times the specified Option appeared in this - * CommandLine - * - * @param trigger a trigger used to lookup the Option - * @return the number of occurrences of the option - */ - int getOptionCount(final String trigger); - - /** - * Retrieves the number of times the specified Option appeared in this - * CommandLine - * - * @param option the Option associated to check - * @return the number of occurrences of the option - */ - int getOptionCount(final Option option); - - /** - * Retrieves a list of all Options found in this CommandLine - * - * @return a none null list of Options - */ - List getOptions(); - - /** - * Retrieves a list of all Option triggers found in this CommandLine - * - * @return a none null list of Option triggers - */ - Set getOptionTriggers(); -}
