author | chegar |
Tue, 26 Jan 2016 09:18:51 +0000 | |
changeset 35377 | 462f93ab37f2 |
permissions | -rw-r--r-- |
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 |
/* |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
27 |
* This file is available under and governed by the GNU General Public |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
28 |
* License version 2 only, as published by the Free Software Foundation. |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
29 |
* However, the following notice accompanied the original version of this |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
30 |
* file: |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
31 |
* |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
32 |
* The MIT License |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
33 |
* |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
34 |
* Copyright (c) 2004-2014 Paul R. Holser, Jr. |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
35 |
* |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
36 |
* Permission is hereby granted, free of charge, to any person obtaining |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
37 |
* a copy of this software and associated documentation files (the |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
38 |
* "Software"), to deal in the Software without restriction, including |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
39 |
* without limitation the rights to use, copy, modify, merge, publish, |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
40 |
* distribute, sublicense, and/or sell copies of the Software, and to |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
41 |
* permit persons to whom the Software is furnished to do so, subject to |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
42 |
* the following conditions: |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
43 |
* |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
44 |
* The above copyright notice and this permission notice shall be |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
45 |
* included in all copies or substantial portions of the Software. |
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 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
48 |
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
49 |
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
50 |
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
51 |
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
52 |
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
53 |
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
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 |
|
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
56 |
package jdk.internal.joptsimple; |
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 |
import java.util.ArrayList; |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
59 |
import java.util.Collection; |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
60 |
import java.util.Collections; |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
61 |
import java.util.List; |
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 |
/** |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
64 |
* Allows callers to specify whether a given option accepts arguments (required or optional). |
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 |
* <p>Instances are returned from {@link OptionParser#accepts(String)} to allow the formation of parser directives as |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
67 |
* sentences in a "fluent interface" language. For example:</p> |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
68 |
* |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
69 |
* <pre><code> |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
70 |
* OptionParser parser = new OptionParser(); |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
71 |
* parser.accepts( "c" ).<strong>withRequiredArg()</strong>.ofType( Integer.class ); |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
72 |
* </code></pre> |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
73 |
* |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
74 |
* <p>If no methods are invoked on an instance of this class, then that instance's option will accept no argument.</p> |
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 |
* <p>Note that you should not use the fluent interface clauses in a way that would defeat the typing of option |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
77 |
* arguments:</p> |
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 |
* <pre><code> |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
80 |
* OptionParser parser = new OptionParser(); |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
81 |
* ArgumentAcceptingOptionSpec<String> optionC = |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
82 |
* parser.accepts( "c" ).withRequiredArg(); |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
83 |
* <strong>optionC.ofType( Integer.class ); // DON'T THROW AWAY THE TYPE!</strong> |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
84 |
* |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
85 |
* String value = parser.parse( "-c", "2" ).valueOf( optionC ); // ClassCastException |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
86 |
* </code></pre> |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
87 |
* |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
88 |
* @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
|
89 |
*/ |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
90 |
public class OptionSpecBuilder extends NoArgumentOptionSpec { |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
91 |
private final OptionParser parser; |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
92 |
|
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
93 |
OptionSpecBuilder( OptionParser parser, Collection<String> options, String description ) { |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
94 |
super( options, description ); |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
95 |
|
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
96 |
this.parser = parser; |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
97 |
attachToParser(); |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
98 |
} |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
99 |
|
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
100 |
private void attachToParser() { |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
101 |
parser.recognize( this ); |
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 |
/** |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
105 |
* Informs an option parser that this builder's option requires an argument. |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
106 |
* |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
107 |
* @return a specification for the option |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
108 |
*/ |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
109 |
public ArgumentAcceptingOptionSpec<String> withRequiredArg() { |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
110 |
ArgumentAcceptingOptionSpec<String> newSpec = |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
111 |
new RequiredArgumentOptionSpec<String>( options(), description() ); |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
112 |
parser.recognize( newSpec ); |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
113 |
|
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
114 |
return newSpec; |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
115 |
} |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
116 |
|
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 |
* Informs an option parser that this builder's option accepts an optional argument. |
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 |
* @return a specification for the option |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
121 |
*/ |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
122 |
public ArgumentAcceptingOptionSpec<String> withOptionalArg() { |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
123 |
ArgumentAcceptingOptionSpec<String> newSpec = |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
124 |
new OptionalArgumentOptionSpec<String>( options(), description() ); |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
125 |
parser.recognize( newSpec ); |
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 |
return newSpec; |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
128 |
} |
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 |
/** |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
131 |
* <p>Informs an option parser that this builder's option is required if the given option is present on the command |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
132 |
* line.</p> |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
133 |
* |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
134 |
* <p>For a given option, you <em>should not</em> mix this with {@link #requiredUnless(String, String...) |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
135 |
* requiredUnless} to avoid conflicts.</p> |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
136 |
* |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
137 |
* @param dependent an option whose presence on a command line makes this builder's option required |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
138 |
* @param otherDependents other options whose presence on a command line makes this builder's option required |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
139 |
* @return self, so that the caller can add clauses to the fluent interface sentence |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
140 |
* @throws OptionException if any of the dependent options haven't been configured in the parser yet |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
141 |
*/ |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
142 |
public OptionSpecBuilder requiredIf( String dependent, String... otherDependents ) { |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
143 |
List<String> dependents = validatedDependents( dependent, otherDependents ); |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
144 |
for ( String each : dependents ) { |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
145 |
parser.requiredIf( options(), each ); |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
146 |
} |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
147 |
|
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
148 |
return this; |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
149 |
} |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
150 |
|
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
151 |
/** |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
152 |
* <p>Informs an option parser that this builder's option is required if the given option is present on the command |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
153 |
* line.</p> |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
154 |
* |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
155 |
* <p>For a given option, you <em>should not</em> mix this with {@link #requiredUnless(OptionSpec, OptionSpec[]) |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
156 |
* requiredUnless} to avoid conflicts.</p> |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
157 |
* |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
158 |
* <p>This method recognizes only instances of options returned from the fluent interface methods.</p> |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
159 |
* |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
160 |
* @param dependent the option whose presence on a command line makes this builder's option required |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
161 |
* @param otherDependents other options whose presence on a command line makes this builder's option required |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
162 |
* @return self, so that the caller can add clauses to the fluent interface sentence |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
163 |
*/ |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
164 |
public OptionSpecBuilder requiredIf( OptionSpec<?> dependent, OptionSpec<?>... otherDependents ) { |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
165 |
parser.requiredIf( options(), dependent ); |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
166 |
for ( OptionSpec<?> each : otherDependents ) |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
167 |
parser.requiredIf( options(), each ); |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
168 |
|
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
169 |
return this; |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
170 |
} |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
171 |
|
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
172 |
/** |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
173 |
* <p>Informs an option parser that this builder's option is required if the given option is absent on the command |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
174 |
* line.</p> |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
175 |
* |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
176 |
* <p>For a given option, you <em>should not</em> mix this with {@link #requiredIf(OptionSpec, OptionSpec[]) |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
177 |
* requiredIf} to avoid conflicts.</p> |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
178 |
* |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
179 |
* @param dependent an option whose absence on a command line makes this builder's option required |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
180 |
* @param otherDependents other options whose absence on a command line makes this builder's option required |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
181 |
* @return self, so that the caller can add clauses to the fluent interface sentence |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
182 |
* @throws OptionException if any of the dependent options haven't been configured in the parser yet |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
183 |
*/ |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
184 |
public OptionSpecBuilder requiredUnless( String dependent, String... otherDependents ) { |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
185 |
List<String> dependents = validatedDependents( dependent, otherDependents ); |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
186 |
for ( String each : dependents ) { |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
187 |
parser.requiredUnless( options(), each ); |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
188 |
} |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
189 |
return this; |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
190 |
} |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
191 |
|
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
192 |
/** |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
193 |
* <p>Informs an option parser that this builder's option is required if the given option is absent on the command |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
194 |
* line.</p> |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
195 |
* |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
196 |
* <p>For a given option, you <em>should not</em> mix this with {@link #requiredIf(OptionSpec, OptionSpec[]) |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
197 |
* requiredIf} to avoid conflicts.</p> |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
198 |
* |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
199 |
* <p>This method recognizes only instances of options returned from the fluent interface methods.</p> |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
200 |
* |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
201 |
* @param dependent the option whose absence on a command line makes this builder's option required |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
202 |
* @param otherDependents other options whose absence on a command line makes this builder's option required |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
203 |
* @return self, so that the caller can add clauses to the fluent interface sentence |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
204 |
*/ |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
205 |
public OptionSpecBuilder requiredUnless( OptionSpec<?> dependent, OptionSpec<?>... otherDependents ) { |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
206 |
parser.requiredUnless( options(), dependent ); |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
207 |
for ( OptionSpec<?> each : otherDependents ) |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
208 |
parser.requiredUnless( options(), each ); |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
209 |
|
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
210 |
return this; |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
211 |
} |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
212 |
|
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
213 |
private List<String> validatedDependents( String dependent, String... otherDependents ) { |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
214 |
List<String> dependents = new ArrayList<String>(); |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
215 |
dependents.add( dependent ); |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
216 |
Collections.addAll( dependents, otherDependents ); |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
217 |
|
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
218 |
for ( String each : dependents ) { |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
219 |
if ( !parser.isRecognized( each ) ) |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
220 |
throw new UnconfiguredOptionException( each ); |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
221 |
} |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
222 |
|
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
223 |
return dependents; |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
224 |
} |
462f93ab37f2
8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff
changeset
|
225 |
} |