Class: EventHub::ArgumentParser

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

Class Method Summary collapse

Class Method Details

.parse(args) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/eventhub/argument_parser.rb', line 5

def self.parse(args)
  # The options specified on the command line will be collected in *options*.
  # We set default values here.
  options = OpenStruct.new
  options.environment = 'development'
  options.detached = false

  opt_parser = OptionParser.new do |opts|
    opts.banner = "Usage: #{args[0]}.rb [options]"
    yield(opts, options) if block_given? # allow to add more options

    opts.on("-e", "--environment ENVIRONMENT","Environment the processor is running") do |environment|
      options.environment = environment
    end

    opts.on("-d", "--detached", "Run processor detached as a daemon") do |v|
      options.detached = v
    end

    opts.on_tail("-h", "--help", "Show this message") do
      puts opts
      exit
    end
  end

  opt_parser.parse!(args)
  options
end