src/jdk.internal.opt/share/classes/jdk/internal/joptsimple/OptionDeclarer.java
author jlahoda
Wed, 06 Jun 2018 15:36:29 +0200
changeset 50428 8c88df2e8a78
parent 47216 71c04702a3d5
permissions -rw-r--r--
8203891: Upgrade JOpt Simple to 5.0.4 Reviewed-by: alanb, chegar, mchung
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
35377
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
     1
/*
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
     2
 * Copyright (c) 2009, 2015, Oracle and/or its affiliates. All rights reserved.
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
     4
 *
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    10
 *
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    15
 * accompanied this code).
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    16
 *
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    20
 *
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    23
 * questions.
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    24
 */
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    25
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    26
package jdk.internal.joptsimple;
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    27
50428
8c88df2e8a78 8203891: Upgrade JOpt Simple to 5.0.4
jlahoda
parents: 47216
diff changeset
    28
import java.util.List;
35377
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    29
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    30
/**
50428
8c88df2e8a78 8203891: Upgrade JOpt Simple to 5.0.4
jlahoda
parents: 47216
diff changeset
    31
 * Trains the option parser. This interface aids integration that disposes declaration of options but not actual
8c88df2e8a78 8203891: Upgrade JOpt Simple to 5.0.4
jlahoda
parents: 47216
diff changeset
    32
 * command-line parsing.
8c88df2e8a78 8203891: Upgrade JOpt Simple to 5.0.4
jlahoda
parents: 47216
diff changeset
    33
 *
8c88df2e8a78 8203891: Upgrade JOpt Simple to 5.0.4
jlahoda
parents: 47216
diff changeset
    34
 * Typical use is for another class to implement {@code OptionDeclarer} as a facade, forwarding calls to an
8c88df2e8a78 8203891: Upgrade JOpt Simple to 5.0.4
jlahoda
parents: 47216
diff changeset
    35
 * {@code OptionParser} instance.
8c88df2e8a78 8203891: Upgrade JOpt Simple to 5.0.4
jlahoda
parents: 47216
diff changeset
    36
 *
8c88df2e8a78 8203891: Upgrade JOpt Simple to 5.0.4
jlahoda
parents: 47216
diff changeset
    37
 * Note that although this is an interface, the returned values of calls are concrete jopt-simple classes.
35377
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    38
 *
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    39
 * @author <a href="mailto:pholser@alumni.rice.edu">Paul Holser</a>
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    40
 * @see OptionParser
50428
8c88df2e8a78 8203891: Upgrade JOpt Simple to 5.0.4
jlahoda
parents: 47216
diff changeset
    41
 * @since 4.6
35377
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    42
 */
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    43
public interface OptionDeclarer {
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    44
    /**
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    45
     * Tells the parser to recognize the given option.
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    46
     *
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    47
     * <p>This method returns an instance of {@link OptionSpecBuilder} to allow the formation of parser directives
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    48
     * as sentences in a fluent interface language. For example:</p>
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    49
     *
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    50
     * <pre><code>
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    51
     *   OptionDeclarer parser = new OptionParser();
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    52
     *   parser.<strong>accepts( "c" )</strong>.withRequiredArg().ofType( Integer.class );
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    53
     * </code></pre>
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    54
     *
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    55
     * <p>If no methods are invoked on the returned {@link OptionSpecBuilder}, then the parser treats the option as
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    56
     * accepting no argument.</p>
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    57
     *
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    58
     * @param option the option to recognize
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    59
     * @return an object that can be used to flesh out more detail about the option
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    60
     * @throws OptionException if the option contains illegal characters
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    61
     * @throws NullPointerException if the option is {@code null}
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    62
     */
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    63
    OptionSpecBuilder accepts( String option );
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    64
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    65
    /**
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    66
     * Tells the parser to recognize the given option.
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    67
     *
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    68
     * @see #accepts(String)
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    69
     * @param option the option to recognize
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    70
     * @param description a string that describes the purpose of the option. This is used when generating help
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    71
     * information about the parser.
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    72
     * @return an object that can be used to flesh out more detail about the option
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    73
     * @throws OptionException if the option contains illegal characters
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    74
     * @throws NullPointerException if the option is {@code null}
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    75
     */
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    76
    OptionSpecBuilder accepts( String option, String description );
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    77
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    78
    /**
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    79
     * Tells the parser to recognize the given options, and treat them as synonymous.
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    80
     *
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    81
     * @see #accepts(String)
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    82
     * @param options the options to recognize and treat as synonymous
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    83
     * @return an object that can be used to flesh out more detail about the options
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    84
     * @throws OptionException if any of the options contain illegal characters
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    85
     * @throws NullPointerException if the option list or any of its elements are {@code null}
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    86
     */
50428
8c88df2e8a78 8203891: Upgrade JOpt Simple to 5.0.4
jlahoda
parents: 47216
diff changeset
    87
    OptionSpecBuilder acceptsAll( List<String> options );
35377
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    88
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    89
    /**
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    90
     * Tells the parser to recognize the given options, and treat them as synonymous.
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    91
     *
50428
8c88df2e8a78 8203891: Upgrade JOpt Simple to 5.0.4
jlahoda
parents: 47216
diff changeset
    92
     * @see #acceptsAll(List)
35377
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    93
     * @param options the options to recognize and treat as synonymous
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    94
     * @param description a string that describes the purpose of the option.  This is used when generating help
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    95
     * information about the parser.
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    96
     * @return an object that can be used to flesh out more detail about the options
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    97
     * @throws OptionException if any of the options contain illegal characters
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    98
     * @throws NullPointerException if the option list or any of its elements are {@code null}
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    99
     * @throws IllegalArgumentException if the option list is empty
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   100
     */
50428
8c88df2e8a78 8203891: Upgrade JOpt Simple to 5.0.4
jlahoda
parents: 47216
diff changeset
   101
    OptionSpecBuilder acceptsAll( List<String> options, String description );
35377
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   102
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   103
    /**
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   104
     * Gives an object that represents an access point for non-option arguments on a command line.
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   105
     *
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   106
     * @return an object that can be used to flesh out more detail about the non-option arguments
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   107
     */
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   108
    NonOptionArgumentSpec<String> nonOptions();
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   109
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   110
    /**
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   111
     * Gives an object that represents an access point for non-option arguments on a command line.
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   112
     *
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   113
     * @see #nonOptions()
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   114
     * @param description a string that describes the purpose of the non-option arguments. This is used when generating
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   115
     * help information about the parser.
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   116
     * @return an object that can be used to flesh out more detail about the non-option arguments
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   117
     */
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   118
    NonOptionArgumentSpec<String> nonOptions( String description );
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   119
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   120
    /**
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   121
     * Tells the parser whether or not to behave "POSIX-ly correct"-ly.
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   122
     *
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   123
     * @param setting {@code true} if the parser should behave "POSIX-ly correct"-ly
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   124
     */
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   125
    void posixlyCorrect( boolean setting );
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   126
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   127
    /**
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   128
     * <p>Tells the parser to treat unrecognized options as non-option arguments.</p>
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   129
     *
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   130
     * <p>If not called, then the parser raises an {@link OptionException} when it encounters an unrecognized
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   131
     * option.</p>
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   132
     */
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   133
    void allowsUnrecognizedOptions();
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   134
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   135
    /**
50428
8c88df2e8a78 8203891: Upgrade JOpt Simple to 5.0.4
jlahoda
parents: 47216
diff changeset
   136
     * Tells the parser either to recognize or ignore {@code -W}-style long options.
35377
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   137
     *
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   138
     * @param recognize {@code true} if the parser is to recognize the special style of long options
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   139
     */
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   140
    void recognizeAlternativeLongOptions( boolean recognize );
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   141
}