View Javadoc

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