Class: ServerStatus::Commands::Add

Inherits:
BaseCommand show all
Defined in:
lib/server-status/commands/add.rb

Instance Attribute Summary

Attributes inherited from BaseCommand

#config

Instance Method Summary collapse

Methods inherited from BaseCommand

#settings

Constructor Details

#initialize(config, host, name = nil) ⇒ Add

Returns a new instance of Add.



4
5
6
7
8
9
# File 'lib/server-status/commands/add.rb', line 4

def initialize(config, host, name=nil)
  super(config)

  @host = host
  @name = name || host
end

Instance Method Details

#performObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/server-status/commands/add.rb', line 11

def perform
  settings['hosts'] ||= {}

  # Check to see if we're already tracking
  settings['hosts'].each do |name, host|
    if name == @name
      puts "#{name} already exists"
      exit(1)
    end
  end

  settings['hosts'][@name] = @host
  config.save

  puts "Added #{@name}"
end