Class: VagrantAutoDNS::Command::List

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-autodns/commands/list.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/list.rb', line 14

def execute
  require_relative '../autodnsdb'

  opts = OptionParser.new do |optp|
    optp.banner = "Usage: vagrant autodns list"
  end
  argv = parse_options(opts) || return
  #Takes no arguments
  raise Vagrant::Errors::CLIInvalidUsage, :help => opts.help.chomp if (argv.length != 0)

  records = VagrantAutoDNS.autodnsdb.list_all_records
  if records.empty?
    @env.ui.error("No records found")
  else
    records.each do |record|
      @env.ui.success("Host #{record["hostname"]} has IP #{record["ip"]}")
    end
  end
  0
end