1 package org.eclipse.jgit.pgm.opt;
2
3 import java.util.ArrayList;
4 import java.util.List;
5
6 import org.eclipse.jgit.pgm.internal.CLIText;
7 import org.kohsuke.args4j.CmdLineException;
8 import org.kohsuke.args4j.CmdLineParser;
9 import org.kohsuke.args4j.OptionDef;
10 import org.kohsuke.args4j.spi.OptionHandler;
11 import org.kohsuke.args4j.spi.Parameters;
12 import org.kohsuke.args4j.spi.Setter;
13
14
15
16
17
18
19 public class OptionWithValuesListHandler extends OptionHandler<List<?>> {
20
21
22
23
24
25
26
27
28
29
30
31 public OptionWithValuesListHandler(CmdLineParser parser,
32 OptionDef option, Setter<List<?>> setter) {
33 super(parser, option, setter);
34 }
35
36
37 @Override
38 public int parseArguments(Parameters params) throws CmdLineException {
39 final List<String> list = new ArrayList<>();
40 for (int idx = 0; idx < params.size(); idx++) {
41 final String p;
42 try {
43 p = params.getParameter(idx);
44 } catch (CmdLineException cle) {
45 break;
46 }
47 list.add(p);
48 }
49 setter.addValue(list);
50 return list.size();
51 }
52
53
54 @Override
55 public String getDefaultMetaVariable() {
56 return CLIText.get().metaVar_values;
57 }
58
59 }