/* The MIT License Copyright (c) 2009 Paul R. Holser, Jr. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ package joptsimple; import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.StringTokenizer; import static java.util.Collections.*; import joptsimple.internal.ReflectionException; import static joptsimple.internal.Objects.*; import static joptsimple.internal.Reflection.*; import static joptsimple.internal.Strings.*; /** *
Specification of an option that accepts an argument.
* *Instances are returned from {@link OptionSpecBuilder} methods to allow the formation * of parser directives as sentences in a "fluent interface" language. For example:
* *
*
* OptionParser parser = new OptionParser();
* parser.accepts( "c" ).withRequiredArg().ofType( Integer.class );
*
*
*
* If no methods are invoked on an instance of this class, then that instance's option * will treat its argument as a {@link String}.
* * @paramSpecifies a type to which arguments of this spec's option are to be * converted.
* *JOpt Simple accepts types that have either:
* *This class converts arguments using those methods in that order; that is, * {@code valueOf} would be invoked before a one-{@link String}-arg constructor * would.
* *Invoking this method will trump any previous calls to this method or to
* {@link #withValuesConvertedBy(ValueConverter)}.
*
* @param Specifies a converter to use to translate arguments of this spec's option into
* Java objects. This is useful when converting to types that do not have the
* requisite factory method or constructor for {@link #ofType(Class)}. Invoking this method will trump any previous calls to this method or to
* {@link #ofType(Class)}.
*
* @param Specifies a description for the argument of the option that this spec
* represents. This description is used when generating help information about
* the parser. Specifies a value separator for the argument of the option that this spec
* represents. This allows a single option argument to represent multiple values
* for the option. For example: Then {@code options.valuesOf( "z" )} would yield the list {@code [foo, bar,
* baz, fizz, buzz]}. You cannot use Unicode U+0000 as the separator. Specifies a set of default values for the argument of the option that this spec
* represents.
*
*
*
* parser.accepts( "z" ).withRequiredArg()
* .withValuesSeparatedBy( ',' );
* OptionSet options = parser.parse( new String[] { "-z", "foo,bar,baz", "-z",
* "fizz", "-z", "buzz" } );
*
*