Skip to content

Commit 205e3f8

Browse files
author
Alexandru Scvortov
committed
added a --help flag to MulticastMain
-? used to work for the same reason -h worked: it would cause a parse failure
1 parent 9e0a552 commit 205e3f8

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

test/src/com/rabbitmq/examples/MulticastMain.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ public static void main(String[] args) {
7171
try {
7272
CommandLine cmd = parser.parse(options, args);
7373

74+
if (cmd.hasOption('?')) {
75+
usage(options);
76+
System.exit(0);
77+
}
78+
7479
String hostName = strArg(cmd, 'h', "localhost");
7580
int portNumber = intArg(cmd, 'p', AMQP.PROTOCOL.PORT);
7681
String exchangeType = strArg(cmd, 't', "direct");
@@ -163,17 +168,22 @@ public static void main(String[] args) {
163168
}
164169
catch( ParseException exp ) {
165170
System.err.println("Parsing failed. Reason: " + exp.getMessage());
166-
HelpFormatter formatter = new HelpFormatter();
167-
formatter.printHelp("<program>", options);
171+
usage(options);
168172
} catch (Exception e) {
169173
System.err.println("Main thread caught exception: " + e);
170174
e.printStackTrace();
171175
System.exit(1);
172176
}
173177
}
174178

179+
private static void usage(Options options) {
180+
HelpFormatter formatter = new HelpFormatter();
181+
formatter.printHelp("<program>", options);
182+
}
183+
175184
private static Options getOptions() {
176185
Options options = new Options();
186+
options.addOption(new Option("?", "help", false,"show usage"));
177187
options.addOption(new Option("h", "host", true, "broker host"));
178188
options.addOption(new Option("p", "port", true, "broker port"));
179189
options.addOption(new Option("t", "type", true, "exchange type"));

0 commit comments

Comments
 (0)