Skip to content

Commit 25324c8

Browse files
committed
help オプションだけを指定した場合にエラーとなる不具合を修正。
1 parent e951877 commit 25324c8

3 files changed

Lines changed: 21 additions & 6 deletions

File tree

modules/deviceconnect-codegen/src/main/java/org/deviceconnect/codegen/Const.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ public final class Const {
2323
static final ResourceBundle MESSAGES = ResourceBundle.getBundle("Messages", Locale.getDefault(),
2424
ResourceBundleWithUtf8.UTF8_ENCODING_CONTROL);
2525

26-
public static final Options OPTIONS;
26+
public static final Options MAIN_OPTIONS;
27+
public static final Options HELP_OPTION;
2728

2829
static Map<String, DConnectCodegenConfig> configs = new HashMap<String, DConnectCodegenConfig>();
2930

@@ -57,7 +58,8 @@ static DConnectCodegenConfig getConfig(String name) {
5758
configs.put(config.getName(), config);
5859
}
5960
configString = sb.toString();
60-
OPTIONS = createOptions();
61+
MAIN_OPTIONS = createOptions();
62+
HELP_OPTION = createHelpOption();
6163
}
6264

6365
static List<DConnectCodegenConfig> getExtensions() {
@@ -69,6 +71,12 @@ static List<DConnectCodegenConfig> getExtensions() {
6971
return output;
7072
}
7173

74+
private static Options createHelpOption() {
75+
Options options = new Options();
76+
options.addOption("h", "help", false, "shows this message");
77+
return options;
78+
}
79+
7280
private static Options createOptions() {
7381
Options options = new Options();
7482

@@ -90,7 +98,7 @@ private static Options createOptions() {
9098
options.addOption("p", "package-name", true, "package name (for Android only)");
9199
options.addOption("n", "display-name", true, "display name of the generated project.");
92100
options.addOption("x", "class-prefix", true, "prefix of each generated class that implements a device connect profile. (for Android and iOS only)");
93-
options.addOption("b", "connection-type", true, "specifies the connection type with device connect manager by \"binder\" or \"broadcast\"; The default value is \"broadcast\". (for Android only)");
101+
options.addOption("b", "connection-type", true, "specifies the connection type with device connect manager by \"binder\" or \"broadcast\"; The default value is \"binder\". (for Android only)");
94102
options.addOption("r", "gradle-plugin-version", true, "version of Android Plugin for Gradle. The default value is \"3.0.0\". (for Android only)");
95103
options.addOption("k", "sdk", true, "location of Device Connect SDKs.");
96104
options.addOption("g", "signing-configs", true, "location of singing configs.");

modules/deviceconnect-codegen/src/main/java/org/deviceconnect/codegen/DConnectCodegen.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,6 @@ public class DConnectCodegen {
6868
public static void main(String[] args) {
6969
System.setProperty("org.slf4j.simpleLogger.defaultLogLevel", "warn");
7070

71-
Options options = Const.OPTIONS;
72-
7371
ClientOptInput clientOptInput = new ClientOptInput();
7472
ClientOpts clientOpts = new ClientOpts();
7573

@@ -78,6 +76,15 @@ public static void main(String[] args) {
7876
CommandLineParser parser = new BasicParser();
7977
DConnectCodegenConfig config;
8078

79+
Options options = Const.MAIN_OPTIONS;
80+
try {
81+
cmd = parser.parse(Const.HELP_OPTION, args);
82+
if (cmd.hasOption("h")) {
83+
usage(options);
84+
return;
85+
}
86+
} catch (ParseException ignored) {}
87+
8188
cmd = parser.parse(options, args);
8289
if (cmd.hasOption("d")) {
8390
usage(options);

modules/deviceconnect-codegen/src/main/java/org/deviceconnect/codegen/error/Errors.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ private static String concatOptions(List<Object> list) {
4141
}
4242
result += groupStr + "\n";
4343
} else {
44-
Option found = Const.OPTIONS.getOption(opt.toString());
44+
Option found = Const.MAIN_OPTIONS.getOption(opt.toString());
4545
if (found != null) {
4646
result += found.getLongOpt() + "\n";
4747
}

0 commit comments

Comments
 (0)