Class: Harmoniser::Parser

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

Instance Method Summary collapse

Constructor Details

#initialize(logger:) ⇒ Parser

Returns a new instance of Parser.



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/harmoniser/parser.rb', line 6

def initialize(logger:)
  @logger = logger
  @options = {}
  @option_parser = OptionParser.new do |opts|
    opts.banner = "harmoniser [options]"
    opts.on "-c", "--concurrency INT", "Set the number of threads to use" do |arg|
      @options[:concurrency] = Integer(arg)
    end
    opts.on "-e", "--environment ENV", "Set the application environment (defaults to inferred environment or 'production')" do |arg|
      @options[:environment] = arg
    end
    opts.on "-r", "--require [PATH|DIR]", "Specify a file to require or the location of the Rails application" do |arg|
      @options[:require] = arg
    end
    opts.on("-v", "--[no-]verbose", "Run verbosely (set log severity to 'debug' for detailed RabbitMQ interactions)") do |arg|
      @options[:verbose] = arg
    end
    opts.on "-V", "--version", "Print version and exit" do
      puts "Harmoniser #{Harmoniser::VERSION}"
      exit(0)
    end
    opts.on_tail "-h", "--help", "Show help" do
      puts @option_parser
      exit(0)
    end
  end
end

Instance Method Details

#call(argv = []) ⇒ Object



34
35
36
37
# File 'lib/harmoniser/parser.rb', line 34

def call(argv = [])
  @option_parser.parse!(argv)
  @options
end