1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
package org.kohsuke.args4j.spi;
import org.kohsuke.args4j.CmdLineException;
import org.kohsuke.args4j.CmdLineParser;
import org.kohsuke.args4j.OptionDef;
/**
* {@link OptionHandler} for the option terminator <tt>--</tt>.
*
* <p>
* This {@link OptionHandler} can be used to implement the special token
* <tt>--</tt> that indicates that the rest of tokens are not options, but arguments.
*
* <p>
* For example, if you have the following class:
*
* <pre>
* <code>
* class Foo {
* {@literal @}Argument
* {@literal @}Option(name="--",handler={@link StopOptionHandler}.class)
* List<String> args;
*
* {@literal @}Option(name="-n")
* int n;
* }
* </code></pre>
*
* <p>
* The command line <code>-n 5 abc def</code> would parse into {@code n=5, args={"abc",def"}},
* but <code> -- -n 5 abc def</code> would parse into {@code n=0, args={"-n","5","abc","def"}}.
*
* @author Kohsuke Kawaguchi
*/
public class StopOptionHandler extends OptionHandler<String> {
public StopOptionHandler(CmdLineParser parser, OptionDef option, Setter<? super String> setter) {
super(parser, option, setter);
}
@Override
public int parseArguments(Parameters params) throws CmdLineException {
owner.stopOptionParsing();
return 0;
}
@Override
public String getDefaultMetaVariable() {
return Messages.DEFAULT_META_REST_OF_ARGUMENTS_HANDLER.format();
}
}
|