Class: Landrush::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/landrush/command.rb

Constant Summary collapse

DAEMON_COMMANDS =
%w(start stop restart status).freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.synopsisObject



5
6
7
# File 'lib/landrush/command.rb', line 5

def self.synopsis
  "manages DNS for both guest and host"
end

Instance Method Details

#boom(msg) ⇒ Object

Raises:

  • (Vagrant::Errors::CLIInvalidOptions)


42
43
44
# File 'lib/landrush/command.rb', line 42

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

#executeObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/landrush/command.rb', line 9

def execute
  # Make sure we use the right data directory for Landrush
  Server.working_dir = File.join(@env.data_dir, 'landrush')

  ARGV.shift # flush landrush from ARGV
  command = ARGV.first || 'help'
  if DAEMON_COMMANDS.include?(command)
    Server.send(command)
  elsif command == 'dependentvms' || command == 'vms'
    if DependentVMs.any?
      @env.ui.info(DependentVMs.list.map { |dvm| " - #{dvm}" }.join("\n"))
    else
      @env.ui.info("No dependent VMs")
    end
  elsif command == 'ls' || command == 'list'
    Landrush::Store.hosts.each do |key, value|
      printf "%-30s %s\n", key, value
    end
  elsif command == 'set'
    host, ip = ARGV[1, 2]
    Landrush::Store.hosts.set(host, ip)
  elsif command == 'del' || command == 'rm'
    key = ARGV[1]
    Landrush::Store.hosts.delete(key)
  elsif command == 'help'
    @env.ui.info(help)
  else
    boom("'#{command}' is not a command")
  end

  0 # happy exit code
end

#helpObject



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/landrush/command.rb', line 53

def help; <<-EOS.gsub(/^      /, '')
  vagrant landrush <command>

  commands:
    {start|stop|restart|status}
      control the landrush server daemon
    list, ls
      list all DNS entries known to landrush
    dependentvms, vms
      list vms currently dependent on the landrush server
    set { <host> <ip> | <alias> <host> }
      adds the given host-to-ip or alias-to-hostname mapping.
      existing host ip addresses will be overwritten
    rm, del { <host> | <alias> }
      delete the given hostname or alias from the server
    help
      you're lookin at it!
  EOS
end

#usage(msg) ⇒ Object



46
47
48
49
50
51
# File 'lib/landrush/command.rb', line 46

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

  #{help}
  EOS
end