Method: Vagrant::Provisioners::Shell::Config#validate

Defined in:
lib/vagrant/provisioners/shell.rb

#validate(env, errors) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/vagrant/provisioners/shell.rb', line 16

def validate(env, errors)
  # Validate that the parameters are properly set
  if path && inline
    errors.add(I18n.t("vagrant.provisioners.shell.path_and_inline_set"))
  elsif !path && !inline
    errors.add(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)
    if !expanded_path.file?
      errors.add(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"))
  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
end