Class: Geary::OptionParser

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

Instance Method Summary collapse

Instance Method Details

#parse(args) ⇒ Object



8
9
10
11
12
# File 'lib/geary/option_parser.rb', line 8

def parse(args)
  Configuration.new.tap do |configuration|
    parser_which_configures(configuration).parse!(Array(args))
  end
end

#parser_which_configures(configuration) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/geary/option_parser.rb', line 14

def parser_which_configures(configuration)
  ::OptionParser.new do |parser|
    parser.on('-s', '--server SERVERS', Array) do |server_addresses|
      configuration.server_addresses = server_addresses
    end

    parser.on('-r', '--require FILES', Array) do |files|
      configuration.required_files = files
    end

    parser.on('-I', '--include PATHS', Array) do |paths|
      configuration.included_paths = paths
    end

    parser.on('-c', '--concurrency NUMBER', 'number of concurrent tasks to run per server') do |number|
      configuration.concurrency = Integer(number)
    end

    parser.on('-l', '--level LOG_LEVEL', 'log level (FATAL|ERROR|WARN|INFO|DEBUG)') do |level|
      begin
        configuration.log_level = Logger.const_get(String(level).upcase)
      rescue NameError
      end
    end
  end
end