@@ -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