1
2
3
4
5
6
7
8
9
10 package org.eclipse.jgit.pgm.opt;
11
12 import org.kohsuke.args4j.CmdLineException;
13 import org.kohsuke.args4j.CmdLineParser;
14 import org.kohsuke.args4j.OptionDef;
15 import org.kohsuke.args4j.spi.Parameters;
16 import org.kohsuke.args4j.spi.Setter;
17 import org.kohsuke.args4j.spi.StringOptionHandler;
18
19
20
21
22
23
24
25
26
27
28
29
30
31 public class GpgSignHandler extends StringOptionHandler {
32
33
34
35
36
37 public static final String DEFAULT = "default";
38
39
40
41
42
43
44
45
46
47
48
49
50
51 public GpgSignHandler(CmdLineParser parser, OptionDef option,
52 Setter<? super String> setter) {
53 super(parser, option, setter);
54 }
55
56
57 @Override
58 public int parseArguments(Parameters params) throws CmdLineException {
59 String alias = params.getParameter(-1);
60 if ("--gpg-sign".equals(alias) || "-S".equals(alias)) {
61 try {
62 String key = params.getParameter(0);
63 if (key == null || key.startsWith("-")) {
64
65 setter.addValue(DEFAULT);
66 return 0;
67 }
68
69
70 setter.addValue(key);
71 return 1;
72 } catch (CmdLineException e) {
73
74 setter.addValue(DEFAULT);
75 return 0;
76 }
77 }
78 return 0;
79 }
80
81 }