Class SrvLstOptions
In: srv/serverlist.rb
Parent: Object

Wrapper for command line parser

Methods
env    new    parse    show_banner    show_help   
Attributes
:args  [R] 
:vals  [R] 
Public Class methods
new(usage, banner)

Initialize with help, version text.

usage
top part of message shown for help option
banner
message shown for version and copyright info
# File srv/serverlist.rb, line 103
  def initialize(usage, banner)
    @vals = Hash.new
    @args = nil
    @banner = banner
    @parser = OptionParser.new(usage, Width)

    # set default values
    @vals["v"] = false
    @vals["myname"] = APPNAME

    # define program options
    @parser.def_option("-h", "--help", 
		     "Show this help.") {
      show_help
    }
    @parser.def_option("-V", "--version", 
		     "Show version and copyright.") {
      show_banner
    }
    @parser.def_option("-v", "--verbose", 
		     "Turn on verbose messages.") {
      |v| @vals["v"] = true
    }
  end
Public Instance methods
env(s)
s
name of env var to parse for command line options
# File srv/serverlist.rb, line 131
  def env(s)
    envopts = ENV[s] || ENV[s.upcase]
    @parser.order(*Shellwords::shellwords(envopts)) if envopts
  end
parse(av)
av
array of command line options, usually ARGV passed in,
        in one form or another
# File srv/serverlist.rb, line 138
  def parse(av)
    @args = @parser.order(*av)
    # other processing here
    @args
  end
show_help(rc = 0)

Show help and exit.

# File srv/serverlist.rb, line 145
  def show_help(rc = 0)
    print @parser; exit(rc)
  end
show_banner(rc = 0)

Show help and exit.

# File srv/serverlist.rb, line 150
  def show_banner(rc = 0)
    print @banner; exit(rc)
  end