Class: StaticCmdParser

Inherits:
Object
  • Object
show all
Defined in:
lib/opts.rb

Instance Method Summary collapse

Instance Method Details

#addOpts(aParser, opts) ⇒ Object

for adding options in subclass



26
27
28
29
30
# File 'lib/opts.rb', line 26

def addOpts aParser, opts
    #p.on("-c", "--config YMLFILE", "Configuration file, can be overriden by cmdline opts") { |file| opts[:config] = file }
    #p.on( "--forcepid", "XXX") { |v| opts[:pid]= v }
    opts
end

#parse!(aDefaults = {}, allowedCommands = ["run"]) ⇒ Object

destructively parses the ARGV for statically declared config options by addOpts method and valided by validateOpts method return opts symbol=>string, the ARGV contains the remaining content



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/opts.rb', line 7

def parse! aDefaults ={}, allowedCommands = ["run"]
    cmds = allowedCommands.join('|')
    cmds = "<#{cmds}>" if allowedCommands.length>1
    opts = aDefaults
    parser = OptionParser.new do |p|
        p.banner = "Usage: #{$0} [options] #{cmds}"
        p.separator ""
        p.separator "Options:"        
        addOpts p, opts                
    end
##        opts = parser.parse!
    parser.parse!
    #opts[:cmd] = *ARGV[-1]
    #raise OptionParser::MissingArgument, "lang" if opts[:lang].nil? and opts[:config_file].nil?
    validateOpts opts, ARGV
    opts
end

#validateOpts(opts, argv) ⇒ Object

for validating parsed options



32
33
34
# File 'lib/opts.rb', line 32

def validateOpts opts, argv
    #raise OptionParser::MissingArgument, "lang" if opts[:lang].nil?
end