From 3e9e422ce0656875d05a0934a57358e67edf22b4 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 18 Jan 2013 12:33:37 -0800 Subject: [PATCH] Convert existing validate methods to new API for kernel --- plugins/kernel_v2/config/ssh.rb | 11 ++++++++--- plugins/kernel_v2/config/vm.rb | 21 +++++++++++++-------- templates/locales/en.yml | 2 +- 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/plugins/kernel_v2/config/ssh.rb b/plugins/kernel_v2/config/ssh.rb index 582f1361d..a296c83fd 100644 --- a/plugins/kernel_v2/config/ssh.rb +++ b/plugins/kernel_v2/config/ssh.rb @@ -15,15 +15,20 @@ module VagrantPlugins attr_accessor :forward_x11 attr_accessor :shell - def validate(env, errors) + def validate(env) + errors = [] + [:username, :max_tries, :timeout].each do |field| value = instance_variable_get("@#{field}".to_sym) - errors.add(I18n.t("vagrant.config.common.error_empty", :field => field)) if !value + errors << I18n.t("vagrant.config.common.error_empty", :field => field) if !value end if private_key_path && !File.file?(File.expand_path(private_key_path, env.root_path)) - errors.add(I18n.t("vagrant.config.ssh.private_key_missing", :path => private_key_path)) + errors << I18n.t("vagrant.config.ssh.private_key_missing", :path => private_key_path) end + + # Return the errors + { "ssh" => errors } end end end diff --git a/plugins/kernel_v2/config/vm.rb b/plugins/kernel_v2/config/vm.rb index 803a892d5..3c340c014 100644 --- a/plugins/kernel_v2/config/vm.rb +++ b/plugins/kernel_v2/config/vm.rb @@ -122,26 +122,31 @@ module VagrantPlugins define(DEFAULT_VM_NAME) if defined_vm_keys.empty? end - def validate(env, errors) - errors.add(I18n.t("vagrant.config.vm.box_missing")) if !box - errors.add(I18n.t("vagrant.config.vm.box_not_found", :name => box)) if box && !box_url && !env.boxes.find(box, :virtualbox) - errors.add(I18n.t("vagrant.config.vm.base_mac_invalid")) if env.boxes.find(box, :virtualbox) && !base_mac + def validate(env) + errors = [] + errors << I18n.t("vagrant.config.vm.box_missing") if !box + errors << I18n.t("vagrant.config.vm.box_not_found", :name => box) if \ + box && !box_url && !env.boxes.find(box, :virtualbox) + errors << I18n.t("vagrant.config.vm.base_mac_invalid") if \ + env.boxes.find(box, :virtualbox) && !base_mac shared_folders.each do |name, options| hostpath = Pathname.new(options[:hostpath]).expand_path(env.root_path) if !hostpath.directory? && !options[:create] - errors.add(I18n.t("vagrant.config.vm.shared_folder_hostpath_missing", + errors << I18n.t("vagrant.config.vm.shared_folder_hostpath_missing", :name => name, - :path => options[:hostpath])) + :path => options[:hostpath]) end if options[:nfs] && (options[:owner] || options[:group]) # Owner/group don't work with NFS - errors.add(I18n.t("vagrant.config.vm.shared_folder_nfs_owner_group", - :name => name)) + errors << I18n.t("vagrant.config.vm.shared_folder_nfs_owner_group", + :name => name) end end + + { "vm" => errors } end end end diff --git a/templates/locales/en.yml b/templates/locales/en.yml index 76bcfc7b0..c42e6492e 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -306,7 +306,7 @@ en: #------------------------------------------------------------------------------- config: common: - error_empty: "`%{field}` must be filled in." + error_empty: "`%{field}` must be not be empty." chef: cookbooks_path_empty: "Must specify a cookbooks path for chef solo." run_list_empty: "Run list must not be empty."