Class BServerOpts
In: srv/backendserver.rb
Parent: Object

Wrapper for command line parser

Methods
env    new    parse   
Attributes
:args  [R] 
:banner  [R] 
:vals  [R] 
Public Class methods
new(usage, banner)
usage
top part of message shown for help option
banner
message shown for version and copyright info
# File srv/backendserver.rb, line 145
  def initialize(usage, banner)
    @banner = banner
    @args = nil
    @parser = OptionParser.new(usage, Width)
    @vals = Hash.new

    @vals["myname"] = APPNAME

    Config.instance.backend[APPNAME].each_pair {
      |k,v| @vals[k] = v
    }

    @parser.def_option("-h", "--help", 
		       "Show this help.") {
      print @parser; exit(0)
    }
    @parser.def_option("-V", "--version", 
		       "Show version and copyright.") {
      puts @banner; exit(0)
    }
    @parser.def_option("-v", "--verbose", 
		       "Turn on verbose messages.") {
      |v|
      @vals["verbose"] = true
    }
    @parser.def_option("-f", "--foreground",
		       "Run in foreground, not as daemon.") {
      |f|
      @vals["daemon"] = "no"
    }
    @parser.def_option("-a", "--alias=NAME",
		       "Use NAME as name for this process.") {
      |name|
      @vals["myname"] = name
    }

  end
Public Instance methods
env(s)

Set options from environment variable.

s
name of env var to parse for command line options
# File srv/backendserver.rb, line 187
  def env(s)
    envopts = ENV[s] || ENV[s.upcase]
    @parser.order(*Shellwords::shellwords(envopts)) if envopts
  end
parse(av)

Parse array including options.

av
array of command line options, usually ARGV
# File srv/backendserver.rb, line 194
  def parse(av)
    @args = @parser.order(*av)
  end