01: package org.kohsuke.args4j.spi;
02:
03: import org.kohsuke.args4j.OptionDef;
04: import org.kohsuke.args4j.CmdLineException;
05: import org.kohsuke.args4j.CmdLineParser;
06:
07: /**
08: * {@link Integer} {@link OptionHandler}.
09: *
10: * @author Kohsuke Kawaguchi
11: */
12: public class IntOptionHandler extends OptionHandler<Integer> {
13: public IntOptionHandler(CmdLineParser parser, OptionDef option,
14: Setter<? super Integer> setter) {
15: super (parser, option, setter);
16: }
17:
18: @Override
19: public int parseArguments(Parameters params)
20: throws CmdLineException {
21: String token = params.getParameter(0);
22: try {
23: int value = Integer.parseInt(token);
24: setter.addValue(value);
25: } catch (NumberFormatException e) {
26: throw new CmdLineException(Messages.ILLEGAL_OPERAND.format(
27: option.toString(), token));
28: }
29: return 1;
30: }
31:
32: @Override
33: public String getDefaultMetaVariable() {
34: return "N";
35: }
36: }
|