@@ -147,32 +147,23 @@ public CommandLine parse(final Options options, final String[] arguments, final
147147 for (final Option opt : options .helpOptions ()) {
148148 opt .clearValues ();
149149 }
150-
151150 // clear the data from the groups
152151 for (final OptionGroup group : options .getOptionGroups ()) {
153152 group .setSelected (null );
154153 }
155-
156154 // initialize members
157155 setOptions (options );
158-
159156 cmd = CommandLine .builder ().build ();
160-
161157 boolean eatTheRest = false ;
162-
163158 final List <String > tokenList = Arrays .asList (flatten (getOptions (), arguments == null ? new String [0 ] : arguments , stopAtNonOption ));
164-
165159 final ListIterator <String > iterator = tokenList .listIterator ();
166-
167160 // process each flattened token
168161 while (iterator .hasNext ()) {
169162 final String token = iterator .next ();
170-
171163 // the value is the double-dash
172164 if ("--" .equals (token )) {
173165 eatTheRest = true ;
174166 }
175-
176167 // the value is a single dash
177168 else if ("-" .equals (token )) {
178169 if (stopAtNonOption ) {
@@ -181,7 +172,6 @@ else if ("-".equals(token)) {
181172 cmd .addArg (token );
182173 }
183174 }
184-
185175 // the value is an option
186176 else if (token .startsWith ("-" )) {
187177 if (stopAtNonOption && !getOptions ().hasOption (token )) {
@@ -191,32 +181,26 @@ else if (token.startsWith("-")) {
191181 processOption (token , iterator );
192182 }
193183 }
194-
195184 // the value is an argument
196185 else {
197186 cmd .addArg (token );
198-
199187 if (stopAtNonOption ) {
200188 eatTheRest = true ;
201189 }
202190 }
203-
204191 // eat the remaining tokens
205192 if (eatTheRest ) {
206193 while (iterator .hasNext ()) {
207194 final String str = iterator .next ();
208-
209195 // ensure only one double-dash is added
210196 if (!"--" .equals (str )) {
211197 cmd .addArg (str );
212198 }
213199 }
214200 }
215201 }
216-
217202 processProperties (properties );
218203 checkRequiredOptions ();
219-
220204 return cmd ;
221205 }
222206
@@ -233,13 +217,11 @@ public void processArgs(final Option opt, final ListIterator<String> iter) throw
233217 // loop until an option is found
234218 while (iter .hasNext ()) {
235219 final String str = iter .next ();
236-
237220 // found an Option, not an argument
238221 if (getOptions ().hasOption (str ) && str .startsWith ("-" )) {
239222 iter .previous ();
240223 break ;
241224 }
242-
243225 // found a value
244226 try {
245227 opt .addValueForProcessing (Util .stripLeadingAndTrailingQuotes (str ));
@@ -248,7 +230,6 @@ public void processArgs(final Option opt, final ListIterator<String> iter) throw
248230 break ;
249231 }
250232 }
251-
252233 if (opt .getValues () == null && !opt .hasOptionalArg ()) {
253234 throw new MissingArgumentException (opt );
254235 }
@@ -265,23 +246,18 @@ public void processArgs(final Option opt, final ListIterator<String> iter) throw
265246 */
266247 protected void processOption (final String arg , final ListIterator <String > iter ) throws ParseException {
267248 final boolean hasOption = getOptions ().hasOption (arg );
268-
269249 // if there is no option throw an UnrecognizedOptionException
270250 if (!hasOption ) {
271251 throw new UnrecognizedOptionException ("Unrecognized option: " + arg , arg );
272252 }
273-
274253 // get the option represented by arg
275254 final Option opt = (Option ) getOptions ().getOption (arg ).clone ();
276-
277255 // update the required options and groups
278256 updateRequiredOptions (opt );
279-
280257 // if the option takes an argument value
281258 if (opt .hasArg ()) {
282259 processArgs (opt , iter );
283260 }
284-
285261 // set the option on the command line
286262 cmd .addOption (opt );
287263 }
@@ -296,23 +272,18 @@ protected void processProperties(final Properties properties) throws ParseExcept
296272 if (properties == null ) {
297273 return ;
298274 }
299-
300275 for (final Enumeration <?> e = properties .propertyNames (); e .hasMoreElements ();) {
301276 final String option = e .nextElement ().toString ();
302-
303277 final Option opt = options .getOption (option );
304278 if (opt == null ) {
305279 throw new UnrecognizedOptionException ("Default option wasn't defined" , option );
306280 }
307-
308281 // if the option is part of a group, check if another option of the group has been selected
309282 final OptionGroup group = options .getOptionGroup (opt );
310283 final boolean selected = group != null && group .getSelected () != null ;
311-
312284 if (!cmd .hasOption (option ) && !selected ) {
313285 // get the value from the properties instance
314286 final String value = properties .getProperty (option );
315-
316287 if (opt .hasArg ()) {
317288 if (opt .getValues () == null || opt .getValues ().length == 0 ) {
318289 try {
@@ -326,7 +297,6 @@ protected void processProperties(final Properties properties) throws ParseExcept
326297 // option to the CommandLine
327298 continue ;
328299 }
329-
330300 cmd .addOption (opt );
331301 updateRequiredOptions (opt );
332302 }
@@ -354,17 +324,15 @@ private void updateRequiredOptions(final Option opt) throws ParseException {
354324 if (opt .isRequired ()) {
355325 getRequiredOptions ().remove (opt .getKey ());
356326 }
357-
358327 // if the option is in an OptionGroup make that option the selected
359328 // option of the group
360329 if (getOptions ().getOptionGroup (opt ) != null ) {
361330 final OptionGroup group = getOptions ().getOptionGroup (opt );
362-
363331 if (group .isRequired ()) {
364332 getRequiredOptions ().remove (group );
365333 }
366-
367334 group .setSelected (opt );
368335 }
369336 }
337+
370338}
0 commit comments