Class: Hivent::CLI::StartOptionParser

Inherits:
Object
  • Object
show all
Defined in:
lib/hivent/cli/start_option_parser.rb

Instance Method Summary collapse

Constructor Details

#initialize(command, argv) ⇒ StartOptionParser

Returns a new instance of StartOptionParser.



8
9
10
11
# File 'lib/hivent/cli/start_option_parser.rb', line 8

def initialize(command, argv)
  @command = command
  @argv = argv
end

Instance Method Details

#parseObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/hivent/cli/start_option_parser.rb', line 13

def parse
  return @options if @options
  @options = {}

  parser = OptionParser.new do |o|
    o.banner = "Usage: hivent #{@command} [options]"

    o.on('-r', '--require PATH', 'File to require to bootstrap consumers') do |arg|
      @options[:require] = arg
    end
  end

  parser.parse(@argv)

  validate_options

  @options
end

#validate_optionsObject



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/hivent/cli/start_option_parser.rb', line 32

def validate_options
  if @options[:require].nil? || !File.exist?(@options[:require])
    puts <<-EOS.strip_heredoc
      =========================================================
        Please point hivent to a Ruby file
        to load your consumers with -r FILE.
      =========================================================
    EOS

    exit(1)
  end
end