Class: VagrantPlugins::MRO::Command

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.synopsisObject



6
7
8
# File 'lib/vagrant-mro/command.rb', line 6

def self.synopsis
  "Outputs machine-readable global status."
end

Instance Method Details

#executeObject



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
# File 'lib/vagrant-mro/command.rb', line 10

def execute
  attrs = [:id, :name, :state]
  entries = []
  Vagrant::Util::SilenceWarnings.silence! do
    @env.machine_index.each do |entry|
      # Always prune invalid entries.
      if !entry.valid?(@env.home_path)
        @env.machine_index.delete(entry.id)
      end
      entries << entry
    end
  end

  if entries.empty?
    @env.ui.info(I18n.t("vagrant.global_status_none"))
    return 0
  end

  entries.each do |entry|
    v = {}
    attrs.each do |method|
      v[method] = entry.send(method).to_s
      v[method] = v[method][0...7] if method == :id
    end
    @env.ui.info("#{v[:id]},#{v[:name]},#{v[:state]}", new_line: true)
  end

  # Success, exit status 0
  0
end