From 42a71a953dcd43a87124ac5c7eb781c865eac9ee Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sun, 24 Nov 2013 11:11:38 -0800 Subject: [PATCH] commands/status: add machine-readable output --- bin/vagrant | 2 +- lib/vagrant/ui.rb | 3 +++ plugins/commands/status/command.rb | 10 +++++++++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/bin/vagrant b/bin/vagrant index 3d61feae3..fbfdf58a3 100755 --- a/bin/vagrant +++ b/bin/vagrant @@ -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 diff --git a/lib/vagrant/ui.rb b/lib/vagrant/ui.rb index 6d4fb5e59..5f2cf6a6d 100644 --- a/lib/vagrant/ui.rb +++ b/lib/vagrant/ui.rb @@ -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") diff --git a/plugins/commands/status/command.rb b/plugins/commands/status/command.rb index 9dc5fb724..f51554943 100644 --- a/plugins/commands/status/command.rb +++ b/plugins/commands/status/command.rb @@ -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