@@ -70,6 +70,11 @@ public static void main(String[] args) {
7070 try {
7171 CommandLine cmd = parser .parse (options , args );
7272
73+ if (cmd .hasOption ('?' )) {
74+ usage (options );
75+ System .exit (0 );
76+ }
77+
7378 String hostName = strArg (cmd , 'h' , "localhost" );
7479 int portNumber = intArg (cmd , 'p' , AMQP .PROTOCOL .PORT );
7580 String exchangeType = strArg (cmd , 't' , "direct" );
@@ -152,17 +157,22 @@ public static void main(String[] args) {
152157 }
153158 catch ( ParseException exp ) {
154159 System .err .println ("Parsing failed. Reason: " + exp .getMessage ());
155- HelpFormatter formatter = new HelpFormatter ();
156- formatter .printHelp ("<program>" , options );
160+ usage (options );
157161 } catch (Exception e ) {
158162 System .err .println ("Main thread caught exception: " + e );
159163 e .printStackTrace ();
160164 System .exit (1 );
161165 }
162166 }
163167
168+ private static void usage (Options options ) {
169+ HelpFormatter formatter = new HelpFormatter ();
170+ formatter .printHelp ("<program>" , options );
171+ }
172+
164173 private static Options getOptions () {
165174 Options options = new Options ();
175+ options .addOption (new Option ("?" , "help" , false ,"show usage" ));
166176 options .addOption (new Option ("h" , "host" , true , "broker host" ));
167177 options .addOption (new Option ("p" , "port" , true , "broker port" ));
168178 options .addOption (new Option ("t" , "type" , true , "exchange type" ));
0 commit comments