From 1102eb77ccdceaf78595ab30f688a4d6aa60bdb1 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 26 Aug 2010 22:39:54 -0700 Subject: [PATCH] `vagrant status` output now uses the new I18n locale --- lib/vagrant/command/status.rb | 45 ++++++++--------------------------- lib/vagrant/errors.rb | 4 ++-- lib/vagrant/ui.rb | 6 +++-- templates/locales/en.yml | 22 +++++++++++++++++ templates/strings.yml | 38 +---------------------------- 5 files changed, 39 insertions(+), 76 deletions(-) diff --git a/lib/vagrant/command/status.rb b/lib/vagrant/command/status.rb index ffd6db26a..f71c0eaea 100644 --- a/lib/vagrant/command/status.rb +++ b/lib/vagrant/command/status.rb @@ -7,44 +7,19 @@ module Vagrant def route require_environment - return show_multivm if target_vms.length > 1 - show_single(target_vms.first) - end - protected - - def show_multivm - puts Util::Translator.t(:status_listing) - puts "" - - env.vms.each do |name, vm| - state = vm.created? ? vm.vm.state : "not created" - puts "#{name.to_s.ljust(30)}#{state}" - end - end - - def show_single(vm) - string_key = nil - - if !vm.created? - string_key = :status_not_created - else - additional_key = nil - if vm.vm.running? - additional_key = :status_created_running - elsif vm.vm.saved? - additional_key = :status_created_saved - elsif vm.vm.powered_off? - additional_key = :status_created_powered_off - end - - string_key = [:status_created, { - :vm_state => vm.vm.state, - :additional_message => additional_key ? Util::Translator.t(additional_key) : "" - }] + state = nil + results = env.vms.collect do |name, vm| + state ||= vm.created? ? vm.vm.state.to_s : "not_created" + "#{name.to_s.ljust(25)}#{state.gsub("_", " ")}" end - puts Util::Translator.t(*string_key) + state = env.vms.length == 1 ? state : "listing" + + env.ui.info("vagrant.commands.status.output", + :states => results.join("\n"), + :message => I18n.t("vagrant.commands.status.#{state}"), + :_prefix => false) end end end diff --git a/lib/vagrant/errors.rb b/lib/vagrant/errors.rb index 135d08126..a4afc71c3 100644 --- a/lib/vagrant/errors.rb +++ b/lib/vagrant/errors.rb @@ -31,7 +31,7 @@ module Vagrant class CLIMissingEnvironment < VagrantError status_code(1) - error_key(:cli_missing_environment) + error_key(:cli_missing_env) end class MultiVMEnvironmentRequired < VagrantError @@ -46,7 +46,7 @@ module Vagrant class NoEnvironmentError < VagrantError status_code(3) - error_key(:no_environment) + error_key(:no_env) end class VMNotCreatedError < VagrantError diff --git a/lib/vagrant/ui.rb b/lib/vagrant/ui.rb index 61ae9360a..7b006f833 100644 --- a/lib/vagrant/ui.rb +++ b/lib/vagrant/ui.rb @@ -26,8 +26,10 @@ module Vagrant end [[:warn, :yellow], [:error, :red], [:info, nil], [:confirm, :green]].each do |method, color| - define_method(method) do |message, prepend_vm_name=true| - message = format_message(message) if prepend_vm_name + define_method(method) do |key, opts=nil| + opts = { :_prefix => true }.merge(opts || {}) + message = I18n.t(key, opts) + message = format_message(message) if opts[:_prefix] @shell.say("#{line_reset}#{message}", color) end end diff --git a/templates/locales/en.yml b/templates/locales/en.yml index 4a02864a8..c24e4284b 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -9,3 +9,25 @@ en: no_env: No Vagrant environment detected. Run `vagrant init` to set one up. vm_creation_required: VM must be created before running this command. Run `vagrant up` first. vm_not_found: A VM by the name of %{name} was not found. + commands: + status: + output: |- + Current VM states: + + %{states} + + %{message} + not_created: |- + The environment has not yet been created. Run `vagrant up` to + create the environment. + powered_off: The VM is powered off. To restart the VM, simply run `vagrant up` + running: |- + The VM is running. To stop this VM, you can run `vagrant halt` to + shut it down forcefully, or you can run `vagrant suspend` to simply + suspend the virtual machine. In either case, to restart it again, + simply run `vagrant up`. + saved: To resume this VM, simply run `vagrant up`. + listing: |- + This environment represents multiple VMs. The VMs are all listed + above with their current state. For more information about a specific + VM, run `vagrant status NAME`. diff --git a/templates/strings.yml b/templates/strings.yml index d4deab908..f259898fd 100644 --- a/templates/strings.yml +++ b/templates/strings.yml @@ -1,45 +1,9 @@ + # Using YAMLs Block Literals to preserve new lines # http://en.wikipedia.org/wiki/YAML#Newlines_preserved # In short, | means keep new lines, trim whitespace left and right # The |- does the above, but trims the new line at the end of all text -#--------------------------------------------------------------------- -# CATEGORY: Status Messages -#--------------------------------------------------------------------- -:status_listing: |- - This environment represents multiple VMs. The VMs will be listed - below with a short status. For more detailed information about a - VM, run `vagrant status NAME`. -:status_no_environment: |- - No vagrant environment detected. Run `vagrant init` to setup a Vagrantfile - in the current directory to get started with Vagrant. -:status_not_created: |- - The environment has not yet been created. Run `vagrant up` to create the - environment. -:status_created: |- - The environment has been created. The status of the current environment's - virtual machine is: "<%= vm_state %>" - - <%= additional_message %> -:status_created_running: |- - To stop this VM, you can run `vagrant halt` to shut it down forcefully, - or you can run `vagrant suspend` to simply suspend the virtual machine. - In either case, to restart it again, simply run a `vagrant up`. -:status_created_saved: |- - To resume this VM, simply run `vagrant up`. -:status_created_powered_off: |- - To restart this VM, simply run `vagrant up`. -:status_global: |- - Below is a list of virtual machines which are currently created and were - created by a Vagrant environment. The path listed was the "last known path" - of the environment (it may have moved). - - <%= entries.join("\n\n") %> -:status_global_entry: |- - Name: <%= vm.vm.name %> - Path: <%= data["path"] %> - Created at: <%= Time.at(data["created_at"]) %> - #--------------------------------------------------------------------- # CATEGORY: Warning Messages #---------------------------------------------------------------------