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