Usage of GetoptLongWithHelp
The class GetoptLong allows the usage of ARGV-parameters in programms (check if the option is valid, if a parameter is required...).A documentation must be created on your own. With GetoptLongWithHelp you can simplify this work.
Example
The script test.rb get the following code:require 'GetoptLongWithHelp' opt = GetoptLongWithHelp.new( [ "--filename", '-f', GetoptLong::REQUIRED_ARGUMENT ], [ "--overwrite", '-o', GetoptLong::NO_ARGUMENT ] ) opt.addHelp('-f',"Style-file (Source)") opt.addHelp2( "-o","Overwrite existing file") opt.mkHelp( %Q|This program reads a file, convert it and create another File. Usage: test.rb [-h] [-f filename] [-o]|) opt.each{ |option, selection| case option when '--help' puts opt.help( selection ) exit when "--filename" # ..... end }
- new is taken form the original super class GetoptLong.
- mkHelp defines a general help text.
By default, a list of all options is used. - addHelp defines a help text for an option.
- addHelp2 defines also a help text, but in addition names are listed.
- With test.rb -h you get the text from
mkHelp
. In the example you get:This program reads a file, convert it and create another File. Usage: test.rb [-h] [-f filename] [-o] --filename, -f (arg) --overwrite, -o --help, -h [arg] --HELP, -H -h <switch> for detailed information on switch <switch>
- With test.rb -h <Option> you get the
specific help text.
test.rb -h f:Style-file (Source)
test.rb -h o:--overwrite, -o Overwrite existing file
- The help text for <o> is
created with
mkHelp2
, so you get all option names