| 1 |
package joptsimple; |
| 2 |
|
| 3 |
import joptsimple.util.KeyValuePair; |
| 4 |
|
| 5 |
/** |
| 6 |
* Custom subclass of the jopt parser for Barclay. Overrides short argument handling |
| 7 |
* so that short arg clustering is disabled. |
| 8 |
*/ |
| 9 |
public class BarclayOptionParser extends OptionParser { |
| 10 |
public BarclayOptionParser(final boolean allowAbbreviations) { |
| 11 |
super(allowAbbreviations); |
| 12 |
} |
| 13 |
|
| 14 |
/** |
| 15 |
* Only delegate short arg handling to the base class if we're guaranteed that the option will be |
| 16 |
* recognized using the full argument string. Otherwise the base class implementation will fall back |
| 17 |
* to clustered short name recognition, which we want to disable to avoid the confusing error message |
| 18 |
* generated. |
| 19 |
*/ |
| 20 |
@Override |
| 21 |
void handleShortOptionToken( String candidate, ArgumentList arguments, OptionSet detected ) { |
| 22 |
KeyValuePair optionAndArgument = KeyValuePair.valueOf( candidate.substring( 1 ) ); |
| 23 |
|
| 24 |
if ( isRecognized( optionAndArgument.key ) ) { |
| 25 |
super.handleShortOptionToken(candidate, arguments, detected ); |
| 26 |
} |
| 27 |
else { |
| 28 |
throw new UnrecognizedOptionException(candidate); |
| 29 |
} |
| 30 |
} |
| 31 |
|
| 32 |
} |