Class: VagrantRubydns::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-rubydns/command.rb

Constant Summary collapse

DAEMON_COMMANDS =
%w(start stop restart status)
DEPENDENT_VM_COMMADNS =
%w(dependentvms)

Instance Method Summary collapse

Instance Method Details

#boom(msg) ⇒ Object

Raises:

  • (Vagrant::Errors::CLIInvalidOptions)


25
26
27
# File 'lib/vagrant-rubydns/command.rb', line 25

def boom(msg)
  raise Vagrant::Errors::CLIInvalidOptions, :help => usage(msg)
end

#executeObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/vagrant-rubydns/command.rb', line 6

def execute
  ARGV.shift # flush rubydns from ARGV, RExec wants to use it for daemon commands

  command = ARGV.first
  if DAEMON_COMMANDS.include?(command)
    Server.daemonize
  elsif command == 'dependentvms'
    if DependentVMs.any?
      @env.ui.info(DependentVMs.list.map { |dvm| " - #{dvm}" }.join("\n"))
    else
      @env.ui.info("No dependent VMs")
    end
  else
    boom("'#{command}' is not a command")
  end

  0 # happy exit code
end

#usage(msg) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/vagrant-rubydns/command.rb', line 29

def usage(msg); <<-EOS.gsub(/^      /, '')
  ERROR: #{msg}

  vagrant rubydns <command>

  commands:
    {start|stop|restart|status}
      control the rubydns server daemon
    dependentvms
      list vms currently dependent on the rubydns server
  EOS
end