commands/status: add machine-readable output

This commit is contained in:
Mitchell Hashimoto 2013-11-24 11:11:38 -08:00
parent c5a7ab7953
commit 42a71a953d
3 changed files with 13 additions and 2 deletions

View File

@ -58,7 +58,7 @@ end
# Highest precedence is if we have enabled machine-readable output
if ARGV.include?("--machine-readable")
ARGV.delete("--machine-readable")
opts[:ui_class] = Vagrant::Ui::MachineReadable
opts[:ui_class] = Vagrant::UI::MachineReadable
end
# Default to colored output

View File

@ -60,6 +60,8 @@ module Vagrant
end
class MachineReadable < Interface
include Util::SafePuts
def initialize
super
@ -81,6 +83,7 @@ module Vagrant
# Prepare the data by replacing characters that aren't outputted
data.each_index do |i|
data[i] = data[i].to_s
data[i].gsub!(",", "%!(VAGRANT_COMMA)")
data[i].gsub!("\n", "\\n")
data[i].gsub!("\r", "\\r")

View File

@ -25,7 +25,15 @@ module VagrantPlugins
results = []
with_target_vms(argv) do |machine|
state = machine.state if !state
results << "#{machine.name.to_s.ljust(max_name_length)} #{machine.state.short_description} (#{machine.provider_name})"
current_state = machine.state
results << "#{machine.name.to_s.ljust(max_name_length)} " +
"#{current_state.short_description} (#{machine.provider_name})"
opts = { scope: machine.name.to_s }
@env.ui.machine("provider", machine.provider_name, opts)
@env.ui.machine("state", current_state.id, opts)
@env.ui.machine("state-human-short", current_state.short_description, opts)
@env.ui.machine("state-human-long", current_state.long_description, opts)
end
message = nil