commons-cli-1.2-src/src/ 40755 0 0 0 11157377776 12227 5 ustar 0 0 commons-cli-1.2-src/src/assembly/ 40755 0 0 0 11157377772 14042 5 ustar 0 0 commons-cli-1.2-src/src/conf/ 40755 0 0 0 11157377776 13154 5 ustar 0 0 commons-cli-1.2-src/src/java/ 40755 0 0 0 11157377775 13147 5 ustar 0 0 commons-cli-1.2-src/src/java/org/ 40755 0 0 0 11157377775 13736 5 ustar 0 0 commons-cli-1.2-src/src/java/org/apache/ 40755 0 0 0 11157377775 15157 5 ustar 0 0 commons-cli-1.2-src/src/java/org/apache/commons/ 40755 0 0 0 11157377775 16632 5 ustar 0 0 commons-cli-1.2-src/src/java/org/apache/commons/cli/ 40755 0 0 0 11157377776 17402 5 ustar 0 0 commons-cli-1.2-src/src/media/ 40755 0 0 0 11157377773 13303 5 ustar 0 0 commons-cli-1.2-src/src/test/ 40755 0 0 0 11157377773 13203 5 ustar 0 0 commons-cli-1.2-src/src/test/org/ 40755 0 0 0 11157377773 13772 5 ustar 0 0 commons-cli-1.2-src/src/test/org/apache/ 40755 0 0 0 11157377773 15213 5 ustar 0 0 commons-cli-1.2-src/src/test/org/apache/commons/ 40755 0 0 0 11157377773 16666 5 ustar 0 0 commons-cli-1.2-src/src/test/org/apache/commons/cli/ 40755 0 0 0 11157377775 17437 5 ustar 0 0 commons-cli-1.2-src/src/test/org/apache/commons/cli/bug/ 40755 0 0 0 11157377775 20214 5 ustar 0 0 commons-cli-1.2-src/LICENSE.txt 100644 0 0 26136 11157377776 13410 0 ustar 0 0 Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
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.
commons-cli-1.2-src/NOTICE.txt 100644 0 0 254 11157377776 13240 0 ustar 0 0 Apache Commons CLI
Copyright 2001-2009 The Apache Software Foundation
This product includes software developed by
The Apache Software Foundation (http://www.apache.org/).
commons-cli-1.2-src/pom.xml 100644 0 0 17454 11157377776 13105 0 ustar 0 0
AlreadySelectedException
* with the specified detail message.
*
* @param message the detail message
*/
public AlreadySelectedException(String message)
{
super(message);
}
/**
* Construct a new AlreadySelectedException
* for the specified option group.
*
* @param group the option group already selected
* @param option the option that triggered the exception
* @since 1.2
*/
public AlreadySelectedException(OptionGroup group, Option option)
{
this("The option '" + option.getKey() + "' was specified but an option from this group "
+ "has already been selected: '" + group.getSelected() + "'");
this.group = group;
this.option = option;
}
/**
* Returns the option group where another option has been selected.
*
* @return the related option group
* @since 1.2
*/
public OptionGroup getOptionGroup()
{
return group;
}
/**
* Returns the option that was added to the group and triggered the exception.
*
* @return the related option
* @since 1.2
*/
public Option getOption()
{
return option;
}
}
commons-cli-1.2-src/src/java/org/apache/commons/cli/BasicParser.java 100644 0 0 3601 11157377776 22540 0 ustar 0 0 /**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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)
* @version $Revision: 680644 $, $Date: 2008-07-29 01:13:48 -0700 (Tue, 29 Jul 2008) $
*/
public class BasicParser extends Parser
{
/**
*
A simple implementation of {@link Parser}'s abstract * {@link Parser#flatten(Options, String[], boolean) flatten} method.
* *Note: options
and stopAtNonOption
* are not used in this flatten
method.
arguments
String array.
*/
protected String[] flatten(Options options, String[] arguments, boolean stopAtNonOption)
{
// just echo the arguments
return arguments;
}
}
commons-cli-1.2-src/src/java/org/apache/commons/cli/CommandLine.java 100644 0 0 25661 11157377776 22562 0 ustar 0 0 /**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Properties;
/**
* Represents list of arguments parsed against a {@link Options} descriptor.
*
* It allows querying of a boolean {@link #hasOption(String opt)}, * in addition to retrieving the {@link #getOptionValue(String opt)} * for options requiring arguments.
* *Additionally, any left-over or unrecognized arguments, * are available for further processing.
* * @author bob mcwhirter (bob @ werken.com) * @author James Strachan * @author John Keyes (john at integralsource.com) * @version $Revision: 735247 $, $Date: 2009-01-17 00:23:35 -0800 (Sat, 17 Jan 2009) $ */ public class CommandLine implements Serializable { private static final long serialVersionUID = 1L; /** the unrecognised options/arguments */ private List args = new LinkedList(); /** the processed options */ private List options = new ArrayList(); /** * 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.contains(resolveOption(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 theObject
type of this Option
.
*
* @param opt the name of the option
* @return the type of this Option
* @deprecated due to System.err message. Instead use getParsedOptionValue(String)
*/
public Object getOptionObject(String opt)
{
try {
return getParsedOptionValue(opt);
} catch(ParseException pe) {
System.err.println("Exception found converting " + opt + " to desired type: " +
pe.getMessage() );
return null;
}
}
/**
* Return a version of this Option
converted to a particular type.
*
* @param opt the name of the option
* @return the value parsed into a particluar object
* @throws ParseException if there are problems turning the option value into the desired type
* @see PatternOptionBuilder
*/
public Object getParsedOptionValue(String opt)
throws ParseException
{
String res = getOptionValue(opt);
Option option = resolveOption(opt);
if (option == null)
{
return null;
}
Object type = option.getType();
return (res == null) ? null : TypeHandler.createValue(res, type);
}
/**
* Return the Object
type of this Option
.
*
* @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)
{
List values = new ArrayList();
for (Iterator it = options.iterator(); it.hasNext();)
{
Option option = (Option) it.next();
if (opt.equals(option.getOpt()) || opt.equals(option.getLongOpt()))
{
values.addAll(option.getValuesList());
}
}
return values.isEmpty() ? null : (String[]) values.toArray(new String[values.size()]);
}
/**
* Retrieves the option object given the long or short option as a String
*
* @param opt short or long name of the option
* @return Canonicalized option
*/
private Option resolveOption(String opt)
{
opt = Util.stripLeadingHyphens(opt);
for (Iterator it = options.iterator(); it.hasNext();)
{
Option option = (Option) it.next();
if (opt.equals(option.getOpt()))
{
return option;
}
if (opt.equals(option.getLongOpt()))
{
return option;
}
}
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 defaultValue
.
*/
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 defaultValue
.
*/
public String getOptionValue(char opt, String defaultValue)
{
return getOptionValue(String.valueOf(opt), defaultValue);
}
/**
* Retrieve the map of values associated to the option. This is convenient
* for options specifying Java properties like -Dparam1=value1
* -Dparam2=value2. The first argument of the option is the key, and
* the 2nd argument is the value. If the option has only one argument
* (-Dfoo) it is considered as a boolean flag and the value is
* "true".
*
* @param opt name of the option
* @return The Properties mapped by the option, never null
* even if the option doesn't exists
* @since 1.2
*/
public Properties getOptionProperties(String opt)
{
Properties props = new Properties();
for (Iterator it = options.iterator(); it.hasNext();)
{
Option option = (Option) it.next();
if (opt.equals(option.getOpt()) || opt.equals(option.getLongOpt()))
{
List values = option.getValuesList();
if (values.size() >= 2)
{
// use the first 2 arguments as the key/value pair
props.put(values.get(0), values.get(1));
}
else if (values.size() == 1)
{
// no explicit value, handle it as a boolean
props.put(values.get(0), "true");
}
}
}
return props;
}
/**
* 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 List
.
*/
public List getArgList()
{
return args;
}
/**
* jkeyes
* - commented out until it is implemented properly
* Dump state, suitable for debugging.
* * @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) { options.add(opt); } /** * Returns an iterator over the Option members of CommandLine. * * @return anIterator
over the processed {@link Option}
* members of this {@link CommandLine}
*/
public Iterator iterator()
{
return options.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;
// reinitialise array
Option[] optionsArray = new Option[processed.size()];
// return the array
return (Option[]) processed.toArray(optionsArray);
}
}
commons-cli-1.2-src/src/java/org/apache/commons/cli/CommandLineParser.java 100644 0 0 7332 11157377776 23712 0 ustar 0 0 /**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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;
/**
* A class that implements the CommandLineParser
interface
* can parse a String array according to the {@link Options} specified
* and return a {@link CommandLine}.
*
* @author John Keyes (john at integralsource.com)
* @version $Revision: 680644 $, $Date: 2008-07-29 01:13:48 -0700 (Tue, 29 Jul 2008) $
*/
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.
*/
/* To maintain binary compatibility, this is commented out.
It is still in the abstract Parser class, so most users will
still reap the benefit.
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.
*/
/* To maintain binary compatibility, this is commented out.
It is still in the abstract Parser class, so most users will
still reap the benefit.
CommandLine parse(Options options, String[] arguments, Properties properties, boolean stopAtNonOption)
throws ParseException;
*/
}
commons-cli-1.2-src/src/java/org/apache/commons/cli/GnuParser.java 100644 0 0 10030 11157377776 22262 0 ustar 0 0 /**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.List;
/**
* The class GnuParser provides an implementation of the
* {@link Parser#flatten(Options, String[], boolean) flatten} method.
*
* @author John Keyes (john at integralsource.com)
* @version $Revision: 680644 $, $Date: 2008-07-29 01:13:48 -0700 (Tue, 29 Jul 2008) $
*/
public class GnuParser extends Parser
{
/**
* This flatten method does so using the following rules:
* arguments
entry AND an {@link Option}
* does not exist for the whole argument
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.options
with the specified
* command line syntax. This method prints help information to
* System.out.
*
* @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);
}
/**
* Print the help for options
with the specified
* command line syntax. This method prints help information to
* System.out.
*
* @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);
}
/**
* Print the help for options
with the specified
* command line syntax. This method prints help information to
* System.out.
*
* @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);
}
/**
* Print the help for options
with the specified
* command line syntax. This method prints help information to
* System.out.
*
* @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);
}
/**
* Print the help for options
with the specified
* command line syntax. This method prints help information to
* System.out.
*
* @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 beginning 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);
}
/**
* Print the help for options
with the specified
* command line syntax. This method prints help information to
* System.out.
*
* @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();
}
/**
* Print the help for options
with the specified
* command line syntax.
*
* @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
*
* @throws IllegalStateException if there is no room to print a line
*/
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);
}
/**
* Print the help for options
with the specified
* command line syntax.
*
* @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
*
* @throws IllegalStateException if there is no room to print a line
*/
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);
}
}
/**
* Prints the usage statement for the specified application.
* * @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; List optList = new ArrayList(options.getOptions()); Collections.sort(optList, getOptionComparator()); // iterate over the options for (Iterator i = optList.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 void appendOptionGroup(final StringBuffer buff, final OptionGroup group) { if (!group.isRequired()) { buff.append("["); } List optList = new ArrayList(group.getOptions()); Collections.sort(optList, getOptionComparator()); // for each option in the OptionGroup for (Iterator i = optList.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.hasArgName()) { buff.append(" <").append(option.getArgName()).append(">"); } // if the Option is not a required option if (!required) { buff.append("]"); } } /** * Print the cmdLineSyntax to the specified writer, using the * specified width. * * @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); } /** *Print the help for the specified Options to the specified writer, * using the specified width, left padding and description padding.
* * @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()); } /** * Print the specified text to the specified PrintWriter. * * @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); } /** * Print the specified text to the specified PrintWriter. * * @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 /** * Render the specified Options and return the rendered Options * in a StringBuffer. * * @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 onlystartPos
for the
* text in text
with the column width width
.
* 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;
}
/**
* Return a String of padding of length len
.
*
* @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();
}
/**
* Remove the trailing whitespace from the specified String.
*
* @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
/**
* This class implements the Comparator
interface
* for comparing Options.
*/
private static class OptionComparator implements Comparator
{
/**
* 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.
*
* @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());
}
}
}
commons-cli-1.2-src/src/java/org/apache/commons/cli/MissingArgumentException.java 100644 0 0 4021 11157377776 25332 0 ustar 0 0 /**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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;
/**
* Thrown when an option requiring an argument
* is not provided with an argument.
*
* @author John Keyes (john at integralsource.com)
* @version $Revision: 680644 $, $Date: 2008-07-29 01:13:48 -0700 (Tue, 29 Jul 2008) $
*/
public class MissingArgumentException extends ParseException
{
/** The option requiring additional arguments */
private Option option;
/**
* Construct a new MissingArgumentException
* with the specified detail message.
*
* @param message the detail message
*/
public MissingArgumentException(String message)
{
super(message);
}
/**
* Construct a new MissingArgumentException
* with the specified detail message.
*
* @param option the option requiring an argument
* @since 1.2
*/
public MissingArgumentException(Option option)
{
this("Missing argument for option: " + option.getKey());
this.option = option;
}
/**
* Return the option requiring an argument that wasn't provided
* on the command line.
*
* @return the related option
* @since 1.2
*/
public Option getOption()
{
return option;
}
}
commons-cli-1.2-src/src/java/org/apache/commons/cli/MissingOptionException.java 100644 0 0 5251 11157377776 25026 0 ustar 0 0 /**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.List;
import java.util.Iterator;
/**
* Thrown when a required option has not been provided.
*
* @author John Keyes ( john at integralsource.com )
* @version $Revision: 680644 $, $Date: 2008-07-29 01:13:48 -0700 (Tue, 29 Jul 2008) $
*/
public class MissingOptionException extends ParseException
{
/** The list of missing options */
private List missingOptions;
/**
* Construct a new MissingSelectedException
* with the specified detail message.
*
* @param message the detail message
*/
public MissingOptionException(String message)
{
super(message);
}
/**
* Constructs a new MissingSelectedException
with the
* specified list of missing options.
*
* @param missingOptions the list of missing options
* @since 1.2
*/
public MissingOptionException(List missingOptions)
{
this(createMessage(missingOptions));
this.missingOptions = missingOptions;
}
/**
* Return the list of options (as strings) missing in the command line parsed.
*
* @return the missing options
* @since 1.2
*/
public List getMissingOptions()
{
return missingOptions;
}
/**
* Build the exception message from the specified list of options.
*
* @param missingOptions
* @since 1.2
*/
private static String createMessage(List missingOptions)
{
StringBuffer buff = new StringBuffer("Missing required option");
buff.append(missingOptions.size() == 1 ? "" : "s");
buff.append(": ");
Iterator it = missingOptions.iterator();
while (it.hasNext())
{
buff.append(it.next());
if (it.hasNext())
{
buff.append(", ");
}
}
return buff.toString();
}
}
commons-cli-1.2-src/src/java/org/apache/commons/cli/Option.java 100644 0 0 42742 11157377776 21643 0 ustar 0 0 /**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.Serializable;
import java.util.ArrayList;
import java.util.List;
/** 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.
* *An Option is not created independantly, but is create through * an instance of {@link Options}.
*
* @see org.apache.commons.cli.Options
* @see org.apache.commons.cli.CommandLine
*
* @author bob mcwhirter (bob @ werken.com)
* @author James Strachan
* @version $Revision: 680644 $, $Date: 2008-07-29 01:13:48 -0700 (Tue, 29 Jul 2008) $
*/
public class Option implements Cloneable, Serializable
{
private static final long serialVersionUID = 1L;
/** 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;
/** the name of the option */
private String opt;
/** the long representation of the option */
private String longOpt;
/** the name of the argument for this option */
private String argName = "arg";
/** description of the option */
private String description;
/** 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;
/** 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 List 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 opt
.
*/
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 opt
.
*/
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 opt
.
*/
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.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 longOpt;
}
return 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 opt;
}
/**
* Retrieve the type of this Option.
*
* @return The type of this option
*/
public Object getType()
{
return 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 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 optionalArg;
}
/**
* Query to see if this Option has a long name
*
* @return boolean flag indicating existence of a long name
*/
public boolean hasLongOpt()
{
return longOpt != null;
}
/**
* Query to see if this Option requires an argument
*
* @return boolean flag indicating if an argument is required
*/
public boolean hasArg()
{
return numberOfArgs > 0 || numberOfArgs == UNLIMITED_VALUES;
}
/**
* Retrieve the self-documenting description of this Option
*
* @return The string description of this option
*/
public String getDescription()
{
return description;
}
/**
* Sets the self-documenting description of this Option
*
* @param description The description of this option
* @since 1.1
*/
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 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 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 argName != null && 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 numberOfArgs > 1 || 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 valuesep;
}
/**
* Return whether this Option has specified a value separator.
*
* @return whether this Option has specified a value separator.
* @since 1.1
*/
public boolean hasValueSeparator()
{
return valuesep > 0;
}
/**
* Returns the number of argument values this Option can take.
*
* @return num the number of argument values
*/
public int getArgs()
{
return numberOfArgs;
}
/**
* Adds the specified value to this Option.
*
* @param value is a/the value of this Option
*/
void addValueForProcessing(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
values.add(value);
}
/**
* Returns the specified value of this Option or
* null
if there is no value.
*
* @return the value/first value of this Option or
* null
if there is no value.
*/
public String getValue()
{
return hasNoValues() ? null : (String) values.get(0);
}
/**
* Returns the specified value of this Option or
* null
if there is no value.
*
* @param index The index of the value to be returned.
*
* @return the specified value of this Option or
* null
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) values.get(index);
}
/**
* Returns the value/first value of this Option or the
* defaultValue
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
* defaultValue
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[]) values.toArray(new String[values.size()]);
}
/**
* @return the values of this Option as a List
* or null if there are no values
*/
public List getValuesList()
{
return values;
}
/**
* Dump state, suitable for debugging.
*
* @return Stringified form of this object
*/
public String toString()
{
StringBuffer buf = new StringBuffer().append("[ option: ");
buf.append(opt);
if (longOpt != null)
{
buf.append(" ").append(longOpt);
}
buf.append(" ");
if (hasArgs())
{
buf.append("[ARG...]");
}
else if (hasArg())
{
buf.append(" [ARG]");
}
buf.append(" :: ").append(description);
if (type != null)
{
buf.append(" :: ").append(type);
}
buf.append(" ]");
return buf.toString();
}
/**
* Returns whether this Option has any values.
*
* @return whether this Option has any values.
*/
private boolean hasNoValues()
{
return values.isEmpty();
}
public boolean equals(Object o)
{
if (this == o)
{
return true;
}
if (o == null || getClass() != o.getClass())
{
return false;
}
Option option = (Option) o;
if (opt != null ? !opt.equals(option.opt) : option.opt != null)
{
return false;
}
if (longOpt != null ? !longOpt.equals(option.longOpt) : option.longOpt != null)
{
return false;
}
return true;
}
public int hashCode()
{
int result;
result = (opt != null ? opt.hashCode() : 0);
result = 31 * result + (longOpt != null ? longOpt.hashCode() : 0);
return result;
}
/**
* A rather odd clone method - due to incorrect code in 1.0 it is public
* and in 1.1 rather than throwing a CloneNotSupportedException it throws
* a RuntimeException so as to maintain backwards compat at the API level.
*
* After calling this method, it is very likely you will want to call
* clearValues().
*
* @throws RuntimeException
*/
public Object clone()
{
try
{
Option option = (Option) super.clone();
option.values = new ArrayList(values);
return option;
}
catch (CloneNotSupportedException cnse)
{
throw new RuntimeException("A CloneNotSupportedException was thrown: " + cnse.getMessage());
}
}
/**
* Clear the Option values. After a parse is complete, these are left with
* data in them and they need clearing if another parse is done.
*
* See: CLI-71
*/
void clearValues()
{
values.clear();
}
/**
* This method is not intended to be used. It was a piece of internal
* API that was made public in 1.0. It currently throws an UnsupportedOperationException.
* @deprecated
* @throws UnsupportedOperationException
*/
public boolean addValue(String value)
{
throw new UnsupportedOperationException("The addValue method is not intended for client use. "
+ "Subclasses should use the addValueForProcessing method instead. ");
}
}
commons-cli-1.2-src/src/java/org/apache/commons/cli/OptionBuilder.java 100644 0 0 23563 11157377776 23152 0 ustar 0 0 /**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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;
/**
* OptionBuilder allows the user to create Options using descriptive methods.
*
*
Details on the Builder pattern can be found at * * http://c2.com/cgi-bin/wiki?BuilderPattern.
* * @author John Keyes (john at integralsource.com) * @version $Revision: 754830 $, $Date: 2009-03-16 00:26:44 -0700 (Mon, 16 Mar 2009) $ * @since 1.0 */ public final 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 *hasArg
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 ? 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 sep
as a means to
* separate argument values.
*
* Example:
* * Option opt = OptionBuilder.withValueSeparator(':') * .create('D'); * * CommandLine line = parser.parse(args); * String propertyName = opt.getValue(0); * String propertyValue = opt.getValue(1); ** * @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 '
=
' as a means to
* separate argument values.
*
* Example:
* * Option opt = OptionBuilder.withValueSeparator() * .create('D'); * * CommandLine line = parser.parse(args); * String propertyName = opt.getValue(0); * String propertyValue = opt.getValue(1); ** * @return the OptionBuilder instance */ public static OptionBuilder withValueSeparator() { OptionBuilder.valuesep = '='; return instance; } /** * The next Option created will be required if
required
* 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 num
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 type
.
*
* @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 char
.
*
* @param opt the character representation of the Option
* @return the Option instance
* @throws IllegalArgumentException if opt
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 longOpt
has not been set.
*/
public static Option create() throws IllegalArgumentException
{
if (longopt == null)
{
OptionBuilder.reset();
throw new IllegalArgumentException("must specify longopt");
}
return create(null);
}
/**
* Create an Option using the current settings and with
* the specified Option char
.
*
* @param opt the java.lang.String
representation
* of the Option
* @return the Option instance
* @throws IllegalArgumentException if opt
is not
* a valid character. See Option.
*/
public static Option create(String opt) throws IllegalArgumentException
{
Option option = null;
try {
// create the 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);
} finally {
// reset the OptionBuilder properties
OptionBuilder.reset();
}
// return the Option instance
return option;
}
}
commons-cli-1.2-src/src/java/org/apache/commons/cli/OptionGroup.java 100644 0 0 10566 11157377776 22657 0 ustar 0 0 /**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.Serializable;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
/**
* A group of mutually exclusive options.
*
* @author John Keyes ( john at integralsource.com )
* @version $Revision: 680644 $, $Date: 2008-07-29 01:13:48 -0700 (Tue, 29 Jul 2008) $
*/
public class OptionGroup implements Serializable
{
private static final long serialVersionUID = 1L;
/** hold the options */
private Map optionMap = new HashMap();
/** the name of the selected option */
private String selected;
/** specified whether this group is required */
private boolean required;
/**
* Add the specified Option
to this group.
*
* @param option the option to add to this group
* @return this option group with the option added
*/
public OptionGroup addOption(Option option)
{
// key - option name
// value - the option
optionMap.put(option.getKey(), option);
return this;
}
/**
* @return the names of the options in this group as a
* Collection
*/
public Collection getNames()
{
// the key set is the collection of names
return optionMap.keySet();
}
/**
* @return the options in this group as a Collection
*/
public Collection getOptions()
{
// the values are the collection of options
return optionMap.values();
}
/**
* Set the selected option of this group to name
.
*
* @param option the option that is selected
* @throws AlreadySelectedException if an option from this group has
* already been selected.
*/
public void setSelected(Option option) throws AlreadySelectedException
{
// if no option has already been selected or the
// same option is being reselected then set the
// selected member variable
if (selected == null || selected.equals(option.getOpt()))
{
selected = option.getOpt();
}
else
{
throw new AlreadySelectedException(this, option);
}
}
/**
* @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 required;
}
/**
* Returns the stringified version of this OptionGroup.
*
* @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();
}
}
commons-cli-1.2-src/src/java/org/apache/commons/cli/Options.java 100644 0 0 16513 11157377776 22023 0 ustar 0 0 /**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.Serializable;
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;
/**
* Main entry-point into the library.
* *Options represents a collection of {@link Option} objects, which * describe the possible options for a command-line.
* *
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.
*
* @see org.apache.commons.cli.CommandLine
*
* @author bob mcwhirter (bob @ werken.com)
* @author James Strachan
* @version $Revision: 680644 $, $Date: 2008-07-29 01:13:48 -0700 (Tue, 29 Jul 2008) $
*/
public class Options implements Serializable
{
private static final long serialVersionUID = 1L;
/** 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();
/**
* 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()
{
return new ArrayList(shortOpts.values());
}
/**
* Returns the required options.
*
* @return List of required options
*/
public List getRequiredOptions()
{
return requiredOpts;
}
/**
* Retrieve the {@link Option} matching the long or short name specified.
* The leading hyphens in the name are ignored (up to 2).
*
* @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 opt
belongs to.
* @param opt the option whose OptionGroup is being queried.
*
* @return the OptionGroup if opt
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();
}
}
commons-cli-1.2-src/src/java/org/apache/commons/cli/OptionValidator.java 100644 0 0 6124 11157377776 23463 0 ustar 0 0 /**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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 )
* @version $Revision: 680644 $, $Date: 2008-07-29 01:13:48 -0700 (Tue, 29 Jul 2008) $
* @since 1.1
*/
class OptionValidator
{
/**
* Validates whether opt
is a permissable Option
* shortOpt. The rules that specify if the opt
* is valid are:
*
*
opt
is not NULLopt
that is either
* ' '(special case), '?', '@' or a letteropt
that only contains
* letters.c
is a letter, ' ', '?' or '@',
* otherwise false.
*/
private static boolean isValidOpt(char c)
{
return isValidChar(c) || c == ' ' || c == '?' || c == '@';
}
/**
* Returns whether the specified character is a valid character.
*
* @param c the character to validate
* @return true if c
is a letter.
*/
private static boolean isValidChar(char c)
{
return Character.isJavaIdentifierPart(c);
}
}
commons-cli-1.2-src/src/java/org/apache/commons/cli/overview.html 100644 0 0 3255 11157377776 22240 0 ustar 0 0
Commons CLI -- version 1.2
The commons-cli package aides in parsing command-line arguments.
Allow command-line arguments to be parsed against a descriptor of valid options (long and short), potentially with arguments.
command-line arguments may be of the typical String[]
form, but also may be a java.util.List
. 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:
myApp -p <port> command -p <printer>
The homepage for the project is Apache Commons/ commons-cli-1.2-src/src/java/org/apache/commons/cli/package.html 100644 0 0 1442 11157377776 21761 0 ustar 0 0
Commons CLI 1.2 commons-cli-1.2-src/src/java/org/apache/commons/cli/ParseException.java 100644 0 0 2460 11157377776 23275 0 ustar 0 0 /** * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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; /** * Base for Exceptions thrown during parsing of a command-line. * * @author bob mcwhirter (bob @ werken.com) * @version $Revision: 680644 $, $Date: 2008-07-29 01:13:48 -0700 (Tue, 29 Jul 2008) $ */ public class ParseException extends Exception { /** * Construct a newParseException
* with the specified detail message.
*
* @param message the detail message
*/
public ParseException(String message)
{
super(message);
}
}
commons-cli-1.2-src/src/java/org/apache/commons/cli/Parser.java 100644 0 0 30325 11157377776 21621 0 ustar 0 0 /**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.Enumeration;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import java.util.Properties;
/**
* Parser
creates {@link CommandLine}s.
*
* @author John Keyes (john at integralsource.com)
* @version $Revision: 680644 $, $Date: 2008-07-29 01:13:48 -0700 (Tue, 29 Jul 2008) $
*/
public abstract class Parser implements CommandLineParser
{
/** commandline instance */
protected CommandLine cmd;
/** current Options */
private Options options;
/** list of required options strings */
private List requiredOptions;
protected void setOptions(final Options options)
{
this.options = options;
this.requiredOptions = new ArrayList(options.getRequiredOptions());
}
protected Options getOptions()
{
return options;
}
protected List getRequiredOptions()
{
return requiredOptions;
}
/**
* Subclasses must implement this method to reduce
* the arguments
that have been passed to the parse method.
*
* @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);
/**
* Parses the specified arguments
based
* on the specifed {@link Options}.
*
* @param options the Options
* @param arguments the arguments
* @return the CommandLine
* @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.
*
* @since 1.1
*/
public CommandLine parse(Options options, String[] arguments, Properties properties) throws ParseException
{
return parse(options, arguments, properties, false);
}
/**
* Parses the specified arguments
* based on the specifed {@link Options}.
*
* @param options the Options
* @param arguments the arguments
* @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 CommandLine
* @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.
*
* @since 1.1
*/
public CommandLine parse(Options options, String[] arguments, Properties properties, boolean stopAtNonOption)
throws ParseException
{
// clear out the data in options in case it's been used before (CLI-71)
for (Iterator it = options.helpOptions().iterator(); it.hasNext();)
{
Option opt = (Option) it.next();
opt.clearValues();
}
// initialise members
setOptions(options);
cmd = new CommandLine();
boolean eatTheRest = false;
if (arguments == null)
{
arguments = new String[0];
}
List tokenList = Arrays.asList(flatten(getOptions(), 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 && !getOptions().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;
}
/**
* Sets the values of Options using the values in properties
.
*
* @param properties The value properties to be processed.
*/
protected 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 = getOptions().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.addValueForProcessing(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);
}
}
}
/**
* Throws a {@link MissingOptionException} if all of the required options
* are not present.
*
* @throws MissingOptionException if any of the required Options
* are not present.
*/
protected void checkRequiredOptions() throws MissingOptionException
{
// if there are required options that have not been processsed
if (!getRequiredOptions().isEmpty())
{
throw new MissingOptionException(getRequiredOptions());
}
}
/**
* Process the argument values for the specified Option
* opt
using the values retrieved from the
* specified iterator iter
.
*
* @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 (getOptions().hasOption(str) && str.startsWith("-"))
{
iter.previous();
break;
}
// found a value
try
{
opt.addValueForProcessing(Util.stripLeadingAndTrailingQuotes(str));
}
catch (RuntimeException exp)
{
iter.previous();
break;
}
}
if (opt.getValues() == null && !opt.hasOptionalArg())
{
throw new MissingArgumentException(opt);
}
}
/**
* Process the Option specified by arg
using the values
* retrieved from the specfied iterator iter
.
*
* @param arg The String value representing an Option
* @param iter The iterator over the flattened command line arguments.
*
* @throws ParseException if arg
does not represent an Option
*/
protected void processOption(String arg, ListIterator iter) throws ParseException
{
boolean hasOption = getOptions().hasOption(arg);
// if there is no option throw an UnrecognisedOptionException
if (!hasOption)
{
throw new UnrecognizedOptionException("Unrecognized option: " + arg, arg);
}
// get the option represented by arg
Option opt = (Option) getOptions().getOption(arg).clone();
// if the option is a required option remove the option from
// the requiredOptions list
if (opt.isRequired())
{
getRequiredOptions().remove(opt.getKey());
}
// if the option is in an OptionGroup make that option the selected
// option of the group
if (getOptions().getOptionGroup(opt) != null)
{
OptionGroup group = getOptions().getOptionGroup(opt);
if (group.isRequired())
{
getRequiredOptions().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);
}
}
commons-cli-1.2-src/src/java/org/apache/commons/cli/PatternOptionBuilder.java 100644 0 0 14060 11157377776 24500 0 ustar 0 0 /**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.io.FileInputStream;
import java.net.URL;
import java.util.Date;
/**
*
* 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. *
* *a | -a flag |
b@ | -b [classname] |
c> | -c [filename] |
d+ | -d [classname] (creates object via empty contructor) |
e% | -e [number] (creates Double/Long instance depeding on existing of a '.') |
f/ | -f [url] |
g: | -g [string] |
* For example, the following allows command line flags of '-v -p string-value -f /dir/file'. * The exclamation mark precede a mandatory option. *
*Options options = PatternOptionBuilder.parsePattern("vp:!f/");
*
* * TODO These need to break out to OptionType and also * to be pluggable. *
* * @version $Revision: 734339 $, $Date: 2009-01-13 21:56:47 -0800 (Tue, 13 Jan 2009) $ */ public class PatternOptionBuilder { /** String class */ public static final Class STRING_VALUE = String.class; /** Object class */ public static final Class OBJECT_VALUE = Object.class; /** Number class */ public static final Class NUMBER_VALUE = Number.class; /** Date class */ public static final Class DATE_VALUE = Date.class; /** Class class */ public static final Class CLASS_VALUE = 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 = FileInputStream.class; /** File class */ public static final Class FILE_VALUE = File.class; /** File array class */ public static final Class FILES_VALUE = File[].class; /** URL class */ public static final Class URL_VALUE = URL.class; /** * Retrieve the class thatch
represents.
*
* @param ch the specified character
* @return The class that ch
represents
*/
public static Object getValueClass(char ch)
{
switch (ch)
{
case '@':
return PatternOptionBuilder.OBJECT_VALUE;
case ':':
return PatternOptionBuilder.STRING_VALUE;
case '%':
return PatternOptionBuilder.NUMBER_VALUE;
case '+':
return PatternOptionBuilder.CLASS_VALUE;
case '#':
return PatternOptionBuilder.DATE_VALUE;
case '<':
return PatternOptionBuilder.EXISTING_FILE_VALUE;
case '>':
return PatternOptionBuilder.FILE_VALUE;
case '*':
return PatternOptionBuilder.FILES_VALUE;
case '/':
return PatternOptionBuilder.URL_VALUE;
}
return null;
}
/**
* Returns whether ch
is a value code, i.e.
* whether it represents a class in a pattern.
*
* @param ch the specified character
* @return true if ch
is a value code, otherwise false.
*/
public static boolean isValueCode(char ch)
{
return ch == '@'
|| ch == ':'
|| ch == '%'
|| ch == '+'
|| ch == '#'
|| ch == '<'
|| ch == '>'
|| ch == '*'
|| ch == '/'
|| ch == '!';
}
/**
* Returns the {@link Options} instance represented by pattern
.
*
* @param pattern the pattern string
* @return The {@link Options} instance
*/
public static Options parsePattern(String pattern)
{
char opt = ' ';
boolean required = false;
Object type = null;
Options options = new Options();
for (int i = 0; i < pattern.length(); i++)
{
char 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;
}
}
commons-cli-1.2-src/src/java/org/apache/commons/cli/PosixParser.java 100644 0 0 22701 11157377776 22643 0 ustar 0 0 /**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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;
import java.util.List;
/**
* The class PosixParser provides an implementation of the
* {@link Parser#flatten(Options,String[],boolean) flatten} method.
*
* @author John Keyes (john at integralsource.com)
* @version $Revision: 695760 $, $Date: 2008-09-16 01:05:03 -0700 (Tue, 16 Sep 2008) $
*/
public class PosixParser extends Parser
{
/** holder for flattened tokens */
private List 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;
/**
* Resets the members to their original state i.e. remove
* all of tokens
entries and set eatTheRest
* to false.
*/
private void init()
{
eatTheRest = false;
tokens.clear();
}
/**
* An implementation of {@link Parser}'s abstract * {@link Parser#flatten(Options,String[],boolean) flatten} method.
* *The following are the rules used by this flatten method. *
stopAtNonOption
is true then do not
* burst anymore of arguments
entries, just add each
* successive entry without further processing. Otherwise, ignore
* stopAtNonOption
.arguments
entry is "--"
* just add the entry to the list of processed tokensarguments
entry is "-"
* just add the entry to the list of processed tokensarguments
entry is two characters
* in length and the first character is "-" 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 stopAtNonOption
* is true, then the remaining entries are copied to the list of
* processed tokens. Otherwise, the current entry is ignored.arguments
entry is more than two
* characters in length and the first character is "-" 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}.arguments
entry is not handled
* by any of the previous rules, then the entry is added to the list
* of processed tokens.arguments
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();
// process each command line token
while (iter.hasNext())
{
// get the next command line token
String token = (String) iter.next();
// handle long option --foo or --foo=bar
if (token.startsWith("--"))
{
int pos = token.indexOf('=');
String opt = pos == -1 ? token : token.substring(0, pos); // --foo
if (!options.hasOption(opt))
{
processNonOptionToken(token, stopAtNonOption);
}
else
{
currentOption = options.getOption(opt);
tokens.add(opt);
if (pos != -1)
{
tokens.add(token.substring(pos + 1));
}
}
}
// single hyphen
else if ("-".equals(token))
{
tokens.add(token);
}
else if (token.startsWith("-"))
{
if (token.length() == 2 || options.hasOption(token))
{
processOptionToken(token, stopAtNonOption);
}
// requires bursting
else
{
burstToken(token, stopAtNonOption);
}
}
else
{
processNonOptionToken(token, stopAtNonOption);
}
gobble(iter);
}
return (String[]) tokens.toArray(new String[tokens.size()]);
}
/**
* Adds the remaining tokens to the processed tokens list.
*
* @param iter An iterator over the remaining tokens
*/
private void gobble(Iterator iter)
{
if (eatTheRest)
{
while (iter.hasNext())
{
tokens.add(iter.next());
}
}
}
/**
* Add the special token "--" and the current value
* to the processed tokens list. Then add all the remaining
* argument
values to the processed tokens list.
*
* @param value The current token
*/
private void processNonOptionToken(String value, boolean stopAtNonOption)
{
if (stopAtNonOption && (currentOption == null || !currentOption.hasArg()))
{
eatTheRest = true;
tokens.add("--");
}
tokens.add(value);
}
/**
* If an {@link Option} exists for token
then
* add the token to the processed list.
If an {@link Option} does not exist and stopAtNonOption
* is set then add the remaining tokens to the processed tokens list
* directly.
token
into its constituent parts
* using the following algorithm.
*
* stopAtNonOption
IS set then add the special token
* "--" followed by the remaining characters and also
* the remaining tokens directly to the processed tokens list.stopAtNonOption
IS NOT set then add that
* character prepended with "-".Object
of type obj
* with the value of str
.
*
* @param str the command line value
* @param obj the type of argument
* @return The instance of obj
initialised with
* the value of str
.
*/
public static Object createValue(String str, Object obj)
throws ParseException
{
return createValue(str, (Class) obj);
}
/**
* Returns the Object
of type clazz
* with the value of str
.
*
* @param str the command line value
* @param clazz the type of argument
* @return The instance of clazz
initialised with
* the value of str
.
*/
public static Object createValue(String str, Class clazz)
throws ParseException
{
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;
}
}
/**
* Create an Object from the classname and empty constructor.
*
* @param classname the argument value
* @return the initialised object, or null if it couldn't create
* the Object.
*/
public static Object createObject(String classname)
throws ParseException
{
Class cl = null;
try
{
cl = Class.forName(classname);
}
catch (ClassNotFoundException cnfe)
{
throw new ParseException("Unable to find the class: " + classname);
}
Object instance = null;
try
{
instance = cl.newInstance();
}
catch (Exception e)
{
throw new ParseException(e.getClass().getName() + "; Unable to create an instance of: " + classname);
}
return instance;
}
/**
* Create a number from a String. If a . is present, it creates a
* Double, otherwise a Long.
*
* @param str the value
* @return the number represented by str
, if str
* is not a number, null is returned.
*/
public static Number createNumber(String str)
throws ParseException
{
try
{
if (str.indexOf('.') != -1)
{
return Double.valueOf(str);
}
else
{
return Long.valueOf(str);
}
}
catch (NumberFormatException e)
{
throw new ParseException(e.getMessage());
}
}
/**
* Returns the class whose name is classname
.
*
* @param classname the class name
* @return The class if it is found, otherwise return null
*/
public static Class createClass(String classname)
throws ParseException
{
try
{
return Class.forName(classname);
}
catch (ClassNotFoundException e)
{
throw new ParseException("Unable to find the class: " + classname);
}
}
/**
* Returns the date represented by str
.
*
* @param str the date string
* @return The date if str
is a valid date string,
* otherwise return null.
*/
public static Date createDate(String str)
throws ParseException
{
throw new UnsupportedOperationException("Not yet implemented");
}
/**
* Returns the URL represented by str
.
*
* @param str the URL string
* @return The URL is str
is well-formed, otherwise
* return null.
*/
public static URL createURL(String str)
throws ParseException
{
try
{
return new URL(str);
}
catch (MalformedURLException e)
{
throw new ParseException("Unable to parse the URL: " + str);
}
}
/**
* Returns the File represented by str
.
*
* @param str the File location
* @return The file represented by str
.
*/
public static File createFile(String str)
throws ParseException
{
return new File(str);
}
/**
* Returns the File[] represented by str
.
*
* @param str the paths to the files
* @return The File[] represented by str
.
*/
public static File[] createFiles(String str)
throws ParseException
{
// to implement/port:
// return FileW.findFiles(str);
throw new UnsupportedOperationException("Not yet implemented");
}
}
commons-cli-1.2-src/src/java/org/apache/commons/cli/UnrecognizedOptionException.java 100644 0 0 3743 11157377776 26055 0 ustar 0 0 /**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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;
/**
* Exception thrown during parsing signalling an unrecognized
* option was seen.
*
* @author bob mcwhiter (bob @ werken.com)
* @version $Revision: 680644 $, $Date: 2008-07-29 01:13:48 -0700 (Tue, 29 Jul 2008) $
*/
public class UnrecognizedOptionException extends ParseException
{
/** The unrecognized option */
private String option;
/**
* Construct a new UnrecognizedArgumentException
* with the specified detail message.
*
* @param message the detail message
*/
public UnrecognizedOptionException(String message)
{
super(message);
}
/**
* Construct a new UnrecognizedArgumentException
* with the specified option and detail message.
*
* @param message the detail message
* @param option the unrecognized option
* @since 1.2
*/
public UnrecognizedOptionException(String message, String option)
{
this(message);
this.option = option;
}
/**
* Returns the unrecognized option.
*
* @return the related option
* @since 1.2
*/
public String getOption()
{
return option;
}
}
commons-cli-1.2-src/src/java/org/apache/commons/cli/Util.java 100644 0 0 4367 11157377776 21271 0 ustar 0 0 /**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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)
* @version $Revision: 680644 $, $Date: 2008-07-29 01:13:48 -0700 (Tue, 29 Jul 2008) $
*/
class Util
{
/**
* Remove the hyphens from the begining of str
and
* return the new String.
*
* @param str The string from which the hyphens should be removed.
*
* @return the new String.
*/
static String stripLeadingHyphens(String str)
{
if (str == null)
{
return null;
}
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 str
.
* 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;
}
}
commons-cli-1.2-src/src/media/logo.xcf 100644 0 0 47455 11157377773 15101 0 ustar 0 0 gimp xcf file , d B B /
gimp-comment Created with The GIMP ª N Ò -ý Kð M X &