From: Nathaniel Talbott Date: 2003-07-19T01:31:43+09:00 Subject: Re: Usage Message for GetoptLong Joey Gibson [mailto:joeygibson@earthlink.net] wrote: > I've been wanting an easy way to output usage info for my > programs that use GetoptLong, without having to duplicate all > the option information; once for the creation of the > GetoptLong object, and again in a help message. I've taken a > crack at altering GetoptLong to support a "usage" method that > essentially does what I want. > > Basically what it does is have you include a fourth parameter for each > option: the description. This is used internally, then > removed from each array, the collection is then passed to the > original initialize method for regular processing. Calling > the usage method of your GetoptLong object will print out a > user-defined message (or a default) and then iterates over > the options, printing both long and short versions, and the > description. I've included the code below in a test program. > I'm not finished with it, but I wanted to share it. I want to > make the output a little prettier and maybe make it more > flexible. I don't know yet. I welcome any suggestions or comments. Well, you could try using optparse... require 'optparse' ARGV.options do |options| options.on('-d', '--date=DATE', String, 'specify a date'){|v| puts "Date #{v} passed"} options.on('-q', '--quiet', 'be verry quiet'){puts "OK, I'm being very, very, very quiet... can't you tell?"} options.on_tail('-h', '--help', 'Print this help information'){puts options; exit} options.parse! end I believe that's approximately equal to what you posted. I've only just begun using optparse, but it seems quite powerful and easy to use. HTH, Nathaniel <:((><