aspose file tools*
The moose likes Other Open Source Projects and the fly likes apache commons-cli how to have help coexist with a required parameter? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "apache commons-cli how to have help coexist with a required parameter?" Watch "apache commons-cli how to have help coexist with a required parameter?" New topic
Author

apache commons-cli how to have help coexist with a required parameter?

Jordan Thompson
Greenhorn

Joined: Nov 09, 2009
Posts: 20
I am using apache commons-cli (their command line interface.)

From what I can see, if you have a required parameter and only provide the help option, the parser throws an exception looking for the required parameter and there is no way to determine if help was passed in as an option. I have tried different attempts with OptionGroup, to no avail.
Here is my code:



Here is what I get with only the -h:
test -h
usage: Note that you can append d,h,m,s to the times to specify durations
of days, hours, minutes, or seconds (default is in seconds).
For example: check_down -H192.168.1.122 -w5h -c10m
The parameters are as follows: -c <crit> -H <host> [-h] [-v] [-w
<warn>]
Missing required options: c, H
-c,--critical <crit> Time to begin alarming critical the host has been
up too long
-H,--hostname <host> Name or IP address of host to check
-h,--help this help info
-v,--version Version of this app
-w,--warning <warn> Time to begin alarming warn a host has been up too
long

If I pass in the required parameter and -h, the code works as expected:

test -h -Htest
usage: Note that you can append d,h,m,s to the times to specify durations
of days, hours, minutes, or seconds (default is in seconds).
For example: check_down -H192.168.1.122 -w5h -c10m
The parameters are as follows: [-c <crit>] -H <host> [-h] [-v] [-w
<warn>]
-c,--critical <crit> Time to begin alarming critical the host has been
up too long
-H,--hostname <host> Name or IP address of host to check
-h,--help this help info
-v,--version Version of this app
-w,--warning <warn> Time to begin alarming warn a host has been up too
long


I am looking for a way to be able to pass in only a -h and be able to nicely print out only the help.
Thanks for your help,
Jordan


No matter where you go - there you are
-- Buckaroo Banzai
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19723
    
  20

Moving to Other Open Source Products.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: apache commons-cli how to have help coexist with a required parameter?