1
2
3
4
5
6
7
8
9
10
11 package org.eclipse.jgit.pgm.opt;
12
13 import org.eclipse.jgit.pgm.CommandCatalog;
14 import org.eclipse.jgit.pgm.CommandRef;
15 import org.eclipse.jgit.pgm.TextBuiltin;
16 import org.eclipse.jgit.pgm.internal.CLIText;
17 import org.kohsuke.args4j.CmdLineException;
18 import org.kohsuke.args4j.CmdLineParser;
19 import org.kohsuke.args4j.OptionDef;
20 import org.kohsuke.args4j.spi.OptionHandler;
21 import org.kohsuke.args4j.spi.Parameters;
22 import org.kohsuke.args4j.spi.Setter;
23
24
25
26
27
28
29
30
31 public class SubcommandHandler extends OptionHandler<TextBuiltin> {
32 private final org.eclipse.jgit.pgm.opt.CmdLineParser clp;
33
34
35
36
37
38
39
40
41
42
43
44
45
46 public SubcommandHandler(final CmdLineParser parser,
47 final OptionDef option, final Setter<? super TextBuiltin> setter) {
48 super(parser, option, setter);
49 clp = (org.eclipse.jgit.pgm.opt.CmdLineParser) parser;
50 }
51
52
53 @Override
54 public int parseArguments(Parameters params) throws CmdLineException {
55 final String name = params.getParameter(0);
56 final CommandRef cr = CommandCatalog.get(name);
57 if (cr == null)
58 throw new CmdLineException(clp,
59 CLIText.format(CLIText.get().notAJgitCommand), name);
60
61
62
63
64
65 owner.stopOptionParsing();
66 setter.addValue(cr.create());
67 return 1;
68 }
69
70
71 @Override
72 public String getDefaultMetaVariable() {
73 return CLIText.get().metaVar_command;
74 }
75 }