Sha256: 5608b69c9116bfcc8db97ce4aafc4b036ec372f446a6b6f6a3c99e32a8e1d154

Contents?: true

Size: 1.58 KB

Versions: 9

Compression:

Stored size: 1.58 KB

Contents

module Landrush
  class Command < Vagrant.plugin('2', :command)
    DAEMON_COMMANDS = %w(start stop restart status)

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

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

      command = ARGV.first
      if DAEMON_COMMANDS.include?(command)
        Server.daemonize
      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'
        IO.popen("/usr/bin/pr -2 -t -a", "w") do |io|
          Landrush::Store.hosts.each do |key, value|
            io.puts "#{key}"
            io.puts "#{value}"
          end
        end
      elsif command == 'help'
        @env.ui.info(help)
      else
        boom("'#{command}' is not a command")
      end

      0 # happy exit code
    end

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

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

      #{help}
      EOS
    end

    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
        help
          you're lookin at it!
      EOS
    end

  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
landrush-0.16.0 lib/landrush/command.rb
landrush-0.15.4 lib/landrush/command.rb
landrush-0.15.3 lib/landrush/command.rb
landrush-0.15.2 lib/landrush/command.rb
landrush-0.15.1 lib/landrush/command.rb
landrush-0.15.0 lib/landrush/command.rb
landrush-0.14.1 lib/landrush/command.rb
landrush-0.14.0 lib/landrush/command.rb
landrush-0.13.1 lib/landrush/command.rb