Class: Bini::OptionParser

Inherits:
OptionParser
  • Object
show all
Defined in:
lib/bini/optparser.rb

Instance Method Summary collapse

Constructor Details

#initializeOptionParser

Returns a new instance of OptionParser.



5
6
7
8
9
10
# File 'lib/bini/optparser.rb', line 5

def initialize
  super
  @options = {}

  on("-V", "--version", "Print version") { |version| @options[:version] = true}
end

Instance Method Details

#[](k = nil) ⇒ Object



33
34
35
36
37
# File 'lib/bini/optparser.rb', line 33

def [](k = nil)
  return @options[k] if k
  return @options if @options.any?
  {}
end

#[]=(k, v) ⇒ Object



39
40
41
# File 'lib/bini/optparser.rb', line 39

def []=(k,v)
  @options[k] = v
end

#clearObject

These are the hash like bits.



29
30
31
# File 'lib/bini/optparser.rb', line 29

def clear
  @options.clear
end

#mash(h) ⇒ Object

merge takes in a set of values and overwrites the previous values. mash does this in reverse.



45
46
47
48
49
# File 'lib/bini/optparser.rb', line 45

def mash(h)
  h.merge! @options
  @options.clear
  h.each {|k,v| self[k] = v}
end

#parse!Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/bini/optparser.rb', line 12

def parse!
  super

  if @options[:version]
    if Bini.version
      puts Bini.version
    else
      puts "No version supplied."
    end
    exit 0
  end

  mash Bini.config if Bini.config
end