Class: Collectd::Interface::Options

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Singleton
Defined in:
lib/collectd/interface/options.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeOptions

Returns a new instance of Options.



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/collectd/interface/options.rb', line 11

def initialize
  @help = String.new
  @options = GetoptLong.new(
    ['--debug','-d',GetoptLong::NO_ARGUMENT],
    ['--help','-h',GetoptLong::NO_ARGUMENT],
    ['--port','-p',GetoptLong::REQUIRED_ARGUMENT],
    ['--log-file-path','-l',GetoptLong::REQUIRED_ARGUMENT],
    ['--pid-file-path','-P',GetoptLong::REQUIRED_ARGUMENT],
    ['--plugin-path','-I',GetoptLong::REQUIRED_ARGUMENT],
    ['--version',GetoptLong::NO_ARGUMENT],
    ['--config-dump','-C',GetoptLong::NO_ARGUMENT]
  )
end

Instance Attribute Details

#help=(value) ⇒ Object (writeonly)

Sets the attribute help

Parameters:

  • value

    the value to set the attribute help to.



10
11
12
# File 'lib/collectd/interface/options.rb', line 10

def help=(value)
  @help = value
end

Instance Method Details

#parseObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/collectd/interface/options.rb', line 24

def parse
 @options.each do |opt,arg|
     case opt
     when '--port'
       Config['service']['port'] = arg.to_i
     when '--log-file-path'
       if File.directory? arg
         Config['service']['log_path'] = arg
       else
         raise("#{arg} is not a directory!")
       end
     when '--pid-file-path'
       if File.directory? arg
         Config['service']['pid_path'] = arg
       else
         raise("#{arg} is not a directory!")
       end
     when '--plugin-path'
       _path = File.expand_path(arg)
       if File.directory? arg
         Config.plugin_path(_path)
       else
         raise("#{arg} is not a directory!")
       end
     when '--config-dump'
       $stdout.puts Config.inspect
       exit 0
     when '--debug'
       Config['debug'] = true
     when '--help'
       $stdout.puts @help
       exit 0
     when '--version'
       $stdout.puts '0.5.0'
       exit 0 
    end
  end
end