Update shell provisioner to latest validation api

This commit is contained in:
Mitchell Hashimoto 2013-01-18 13:06:29 -08:00
parent e651eb3aa1
commit 5e42a99ab6
1 changed files with 12 additions and 8 deletions

View File

@ -10,32 +10,36 @@ module VagrantPlugins
@upload_path = "/tmp/vagrant-shell"
end
def validate(env, errors)
def validate(machine)
errors = []
# Validate that the parameters are properly set
if path && inline
errors.add(I18n.t("vagrant.provisioners.shell.path_and_inline_set"))
errors << I18n.t("vagrant.provisioners.shell.path_and_inline_set")
elsif !path && !inline
errors.add(I18n.t("vagrant.provisioners.shell.no_path_or_inline"))
errors << I18n.t("vagrant.provisioners.shell.no_path_or_inline")
end
# Validate the existence of a script to upload
if path
expanded_path = Pathname.new(path).expand_path(env.root_path)
expanded_path = Pathname.new(path).expand_path(machine.env.root_path)
if !expanded_path.file?
errors.add(I18n.t("vagrant.provisioners.shell.path_invalid",
:path => expanded_path))
errors << I18n.t("vagrant.provisioners.shell.path_invalid",
:path => expanded_path)
end
end
# There needs to be a path to upload the script to
if !upload_path
errors.add(I18n.t("vagrant.provisioners.shell.upload_path_not_set"))
errors << I18n.t("vagrant.provisioners.shell.upload_path_not_set")
end
# If there are args and its not a string, that is a problem
if args && !args.is_a?(String)
errors.add(I18n.t("vagrant.provisioners.shell.args_not_string"))
end
errors << I18n.t("vagrant.provisioners.shell.args_not_string")
end
{ "shell provisioner" => errors }
end
end
end