@@ -70,6 +70,11 @@ public static void main(String[] args) {
70
70
try {
71
71
CommandLine cmd = parser .parse (options , args );
72
72
73
+ if (cmd .hasOption ('?' )) {
74
+ usage (options );
75
+ System .exit (0 );
76
+ }
77
+
73
78
String hostName = strArg (cmd , 'h' , "localhost" );
74
79
int portNumber = intArg (cmd , 'p' , AMQP .PROTOCOL .PORT );
75
80
String exchangeType = strArg (cmd , 't' , "direct" );
@@ -152,17 +157,22 @@ public static void main(String[] args) {
152
157
}
153
158
catch ( ParseException exp ) {
154
159
System .err .println ("Parsing failed. Reason: " + exp .getMessage ());
155
- HelpFormatter formatter = new HelpFormatter ();
156
- formatter .printHelp ("<program>" , options );
160
+ usage (options );
157
161
} catch (Exception e ) {
158
162
System .err .println ("Main thread caught exception: " + e );
159
163
e .printStackTrace ();
160
164
System .exit (1 );
161
165
}
162
166
}
163
167
168
+ private static void usage (Options options ) {
169
+ HelpFormatter formatter = new HelpFormatter ();
170
+ formatter .printHelp ("<program>" , options );
171
+ }
172
+
164
173
private static Options getOptions () {
165
174
Options options = new Options ();
175
+ options .addOption (new Option ("?" , "help" , false ,"show usage" ));
166
176
options .addOption (new Option ("h" , "host" , true , "broker host" ));
167
177
options .addOption (new Option ("p" , "port" , true , "broker port" ));
168
178
options .addOption (new Option ("t" , "type" , true , "exchange type" ));
0 commit comments