Class: Options

Inherits:
Object
  • Object
show all
Defined in:
lib/myaxes/options.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeOptions

Returns a new instance of Options.



7
8
9
10
11
12
13
# File 'lib/myaxes/options.rb', line 7

def initialize
@options = Hash.new

@options['mode'] = 'log'
@options['log'] = $stdout

end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



5
6
7
# File 'lib/myaxes/options.rb', line 5

def options
  @options
end

Instance Method Details

#parseObject



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

def parse
  OptionParser.new do |opt|
    opt.separator ""
    opt.separator "Usage: myaxes -g <group> -a <ip> -u <username> -p <password>[-H <hostnames>]"
    opt.separator ""
    opt.separator "shell> myaxes -g web -a 192.168.0.101 -u web301 -p qwerty"
    opt.separator ""
    opt.separator ""
    opt.separator "Options:"
    opt.separator "-------------"
    opt.on('-g', '--group GROUPNAME', 'Group from config') { |val| @options['group'] = val }
    opt.on('-a', '--address IP-ADDRESS', 'Ip address') { |val| @options['ip'] = val }
    opt.on('-u', '--user USERNAME', 'Username') { |val| @options['user'] = val }
    opt.on('-p', '--password PASSWORD', 'Password') { |val| @options['password'] = val }
    opt.on('-H', '--hosts HOSTNAME_X,HOSTNAME_Y,HOSTNAME_Z', Array, 'Other Hosts(not from config)')  { |val| @options['hosts'] = val }
    opt.separator ""
    opt.on_tail('-h', '--help')           { puts opt; exit }

    opt.parse!
  end

  self.options

end