Path: blob/master/src/jdk.internal.opt/share/classes/jdk/internal/joptsimple/OptionDeclarer.java
40948 views
/*1* Copyright (c) 2009, 2015, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package jdk.internal.joptsimple;2627import java.util.List;2829/**30* Trains the option parser. This interface aids integration that disposes declaration of options but not actual31* command-line parsing.32*33* Typical use is for another class to implement {@code OptionDeclarer} as a facade, forwarding calls to an34* {@code OptionParser} instance.35*36* Note that although this is an interface, the returned values of calls are concrete jopt-simple classes.37*38* @author <a href="mailto:[email protected]">Paul Holser</a>39* @see OptionParser40* @since 4.641*/42public interface OptionDeclarer {43/**44* Tells the parser to recognize the given option.45*46* <p>This method returns an instance of {@link OptionSpecBuilder} to allow the formation of parser directives47* as sentences in a fluent interface language. For example:</p>48*49* <pre><code>50* OptionDeclarer parser = new OptionParser();51* parser.<strong>accepts( "c" )</strong>.withRequiredArg().ofType( Integer.class );52* </code></pre>53*54* <p>If no methods are invoked on the returned {@link OptionSpecBuilder}, then the parser treats the option as55* accepting no argument.</p>56*57* @param option the option to recognize58* @return an object that can be used to flesh out more detail about the option59* @throws OptionException if the option contains illegal characters60* @throws NullPointerException if the option is {@code null}61*/62OptionSpecBuilder accepts( String option );6364/**65* Tells the parser to recognize the given option.66*67* @see #accepts(String)68* @param option the option to recognize69* @param description a string that describes the purpose of the option. This is used when generating help70* information about the parser.71* @return an object that can be used to flesh out more detail about the option72* @throws OptionException if the option contains illegal characters73* @throws NullPointerException if the option is {@code null}74*/75OptionSpecBuilder accepts( String option, String description );7677/**78* Tells the parser to recognize the given options, and treat them as synonymous.79*80* @see #accepts(String)81* @param options the options to recognize and treat as synonymous82* @return an object that can be used to flesh out more detail about the options83* @throws OptionException if any of the options contain illegal characters84* @throws NullPointerException if the option list or any of its elements are {@code null}85*/86OptionSpecBuilder acceptsAll( List<String> options );8788/**89* Tells the parser to recognize the given options, and treat them as synonymous.90*91* @see #acceptsAll(List)92* @param options the options to recognize and treat as synonymous93* @param description a string that describes the purpose of the option. This is used when generating help94* information about the parser.95* @return an object that can be used to flesh out more detail about the options96* @throws OptionException if any of the options contain illegal characters97* @throws NullPointerException if the option list or any of its elements are {@code null}98* @throws IllegalArgumentException if the option list is empty99*/100OptionSpecBuilder acceptsAll( List<String> options, String description );101102/**103* Gives an object that represents an access point for non-option arguments on a command line.104*105* @return an object that can be used to flesh out more detail about the non-option arguments106*/107NonOptionArgumentSpec<String> nonOptions();108109/**110* Gives an object that represents an access point for non-option arguments on a command line.111*112* @see #nonOptions()113* @param description a string that describes the purpose of the non-option arguments. This is used when generating114* help information about the parser.115* @return an object that can be used to flesh out more detail about the non-option arguments116*/117NonOptionArgumentSpec<String> nonOptions( String description );118119/**120* Tells the parser whether or not to behave "POSIX-ly correct"-ly.121*122* @param setting {@code true} if the parser should behave "POSIX-ly correct"-ly123*/124void posixlyCorrect( boolean setting );125126/**127* <p>Tells the parser to treat unrecognized options as non-option arguments.</p>128*129* <p>If not called, then the parser raises an {@link OptionException} when it encounters an unrecognized130* option.</p>131*/132void allowsUnrecognizedOptions();133134/**135* Tells the parser either to recognize or ignore {@code -W}-style long options.136*137* @param recognize {@code true} if the parser is to recognize the special style of long options138*/139void recognizeAlternativeLongOptions( boolean recognize );140}141142143