Module: Deadpool::Options

Defined in:
lib/deadpool/options.rb

Instance Method Summary collapse

Instance Method Details

#config_pathObject



56
57
58
# File 'lib/deadpool/options.rb', line 56

def config_path
  return @options[:config_path]
end

#help(message = nil) ⇒ Object



48
49
50
51
52
53
54
# File 'lib/deadpool/options.rb', line 48

def help(message=nil)
  unless message.nil?
    puts message
  end
  puts @option_parser.help
  exit 4
end

#parse_command_line(argv) ⇒ Object



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
40
41
42
43
44
45
46
# File 'lib/deadpool/options.rb', line 15

def parse_command_line(argv)
  options             = {}
  options[:config_path] = '/etc/deadpool'
  options[:daemonize] = nil

  @option_parser = OptionParser.new do |opts|
    opts.banner = "Usage: deadpool_hosts {help|full_report|nagios_report} [options]"

    opts.separator "Commands:"
    opts.on("-h", "--help", "Print this help message.") do |help|
      options[:help] = true
    end

    opts.on("-d", "--daemon", "Background the server.") do |daemon|
      options[:daemonize] = true
    end

    opts.separator "Options:"
    opts.on("--config_path=PATH", String,
        "Path to configs and custom plugins. #{options[:config_path]} by default.") do |config_path|
      options[:config_path] = config_path
    end
  end

  remaining_arguments = @option_parser.parse! argv

  unless remaining_arguments.empty?
    help "[#{remaining_arguments.join(' ')}] is not understood."
  end

  return options
end

#parse_options(argv) ⇒ Object



11
12
13
# File 'lib/deadpool/options.rb', line 11

def parse_options(argv)
  @options = self.parse_command_line(argv)
end