Convert existing validate methods to new API for kernel

This commit is contained in:
Mitchell Hashimoto 2013-01-18 12:33:37 -08:00
parent a8b57ba13f
commit 3e9e422ce0
3 changed files with 22 additions and 12 deletions

View File

@ -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

View File

@ -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

View File

@ -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."