Class: Deployme::OptionParser

Inherits:
OptionParser
  • Object
show all
Defined in:
lib/deployme/option_parser.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ OptionParser

Returns a new instance of OptionParser.



10
11
12
13
# File 'lib/deployme/option_parser.rb', line 10

def initialize(&block)
  @options = OpenStruct.new
  super
end

Class Method Details

.run(args, &block) ⇒ Object



6
7
8
# File 'lib/deployme/option_parser.rb', line 6

def self.run(args, &block)
  new(&block).run(args)
end

Instance Method Details

#on(*args) ⇒ Object



15
16
17
18
19
# File 'lib/deployme/option_parser.rb', line 15

def on(*args)
  super(*args) do |value|
    yield(@options, value)
  end
end

#on_tail(*args) ⇒ Object



21
22
23
24
25
# File 'lib/deployme/option_parser.rb', line 21

def on_tail(*args)
  super(*args) do
    yield(@options)
  end
end

#run(args) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/deployme/option_parser.rb', line 27

def run(args)
  begin
    parse!(args)
  rescue OptionParser::InvalidOption, OptionParser::MissingArgument
    puts $ERROR_INFO.to_s
    puts
    puts self
    exit 1
  end

  @options
end