01: /*
02: Copyright 2004-2007 Paul R. Holser, Jr. All rights reserved.
03: Licensed under the Academic Free License version 3.0
04: */
05:
06: package joptsimple;
07:
08: /**
09: * How a parser reacts to an argument when it thinks more options are present.
10: *
11: * @since 1.0
12: * @author <a href="mailto:pholser@alumni.rice.edu">Paul Holser</a>
13: * @version $Id: MoreOptionsParserState.java,v 1.10 2007/04/10 20:06:25 pholser Exp $
14: */
15: class MoreOptionsParserState implements OptionParserState {
16: private final boolean posixlyCorrect;
17:
18: MoreOptionsParserState(boolean posixlyCorrect) {
19: this .posixlyCorrect = posixlyCorrect;
20: }
21:
22: public void handleArgument(OptionParser parser,
23: ArgumentList arguments, OptionSet detectedOptions) {
24:
25: String candidate = arguments.next();
26:
27: if (ParserRules.isOptionTerminator(candidate))
28: parser.noMoreOptions();
29: else if (ParserRules.isLongOptionToken(candidate))
30: parser.handleLongOptionToken(candidate, arguments,
31: detectedOptions);
32: else if (ParserRules.isShortOptionToken(candidate))
33: parser.handleShortOptionToken(candidate, arguments,
34: detectedOptions);
35: else {
36: if (posixlyCorrect)
37: parser.noMoreOptions();
38:
39: detectedOptions.addNonOptionArgument(candidate);
40: }
41: }
42: }
|