GetoptLongWithHelp: Programm options with documentation de


[API-Dokumentation (englisch)]
You are here: Home GetoptLongWithHelp

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
                  }
          
          
        

Availability

The script is available at rubyforum