-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path168.java
More file actions
86 lines (73 loc) · 2.59 KB
/
Copy path168.java
File metadata and controls
86 lines (73 loc) · 2.59 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package com.github.dreamhead.moco.bootstrap.parser;
import com.github.dreamhead.moco.bootstrap.ParseArgException;
import com.github.dreamhead.moco.bootstrap.arg.StartArgs;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.DefaultParser;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
public abstract class StartArgsParser {
protected abstract Options options();
protected abstract StartArgs parseArgs(CommandLine cmd);
public final StartArgs parse(final String[] args) {
try {
return doParse(args);
} catch (ParseException e) {
throw new ParseArgException("fail to parse arguments", e);
}
}
private StartArgs doParse(final String[] args) throws ParseException {
CommandLineParser parser = new DefaultParser();
CommandLine cmd = parser.parse(options(), args);
return parseArgs(cmd);
}
protected final Option portOption() {
Option opt = new Option("p", true, "port");
opt.setType(Number.class);
opt.setRequired(false);
return opt;
}
protected final Option configOption() {
Option opt = new Option("c", true, "config");
opt.setType(String.class);
opt.setRequired(false);
return opt;
}
protected final Option settingsOption() {
Option opt = new Option("g", true, "global settings");
opt.setType(String.class);
opt.setRequired(false);
return opt;
}
protected final Option envOption() {
Option opt = new Option("e", true, "environment");
opt.setType(String.class);
opt.setRequired(false);
return opt;
}
protected final Option httpsCertificate() {
Option option = new Option(null, "https", true, "Https certificate filename");
option.setType(String.class);
option.setRequired(false);
return option;
}
protected final Option keyStore() {
Option option = new Option(null, "keystore", true, "Key store password");
option.setType(String.class);
option.setRequired(false);
return option;
}
protected final Option cert() {
Option option = new Option(null, "cert", true, "Cert password");
option.setType(String.class);
option.setRequired(false);
return option;
}
public static Integer getPort(final String port) {
if (port == null) {
return null;
}
return Integer.valueOf(port);
}
}