Class: VagrantAutoDNS::Command::Add

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-autodns/commands/add.rb

Instance Method Summary collapse

Instance Method Details

#executeObject

Raises:

  • (Vagrant::Errors::CLIInvalidUsage)


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/vagrant-autodns/commands/add.rb', line 14

def execute
  require_relative '../autodnsdb'

  opts = OptionParser.new do |optp|
    optp.banner = "Usage: vagrant autodns add <hostname> <ip> [vagrant_id]"
  end
  argv = parse_options(opts) || return
  #vagrant_id is an option parameter
  raise Vagrant::Errors::CLIInvalidUsage, :help => opts.help.chomp if (argv.length < 2 || argv.length > 3)

  hostname, ip, vagrant_id = argv

  if VagrantAutoDNS.autodnsdb.update_record(hostname, ip, vagrant_id)
    @env.ui.info("Entry #{ip} added for host #{hostname}")
    0
  else
    @env.ui.error("Entry #{ip} not added for host #{hostname}")
    1
  end
end