Brian Cain 6051f3598e
Fixes #10224: Allow validation of config while ignoring provider
This commit adds a new flag to the `vagrant validate` command which
allows users to completely ignore the provider block of a config file.
This is useful for when you are running `vagrant validate` in CI and
don't want to install a valid provider to check the syntax of your
Vagratnfile. When the flag is invoked, a warning will be displayed
saying that the provider block will be ignored and not validated.
2018-10-30 13:37:22 -07:00

47 lines
1.2 KiB
Ruby

require 'optparse'
module VagrantPlugins
module CommandValidate
class Command < Vagrant.plugin("2", :command)
def self.synopsis
"validates the Vagrantfile"
end
def execute
options = {}
opts = OptionParser.new do |o|
o.banner = "Usage: vagrant validate [options]"
o.separator ""
o.separator "Validates a Vagrantfile config"
o.separator ""
o.separator "Options:"
o.separator ""
o.on("-p", "--ignore-provider", "Ignores provider config options") do |p|
options[:ignore_provider] = p
end
end
# Parse the options
argv = parse_options(opts)
return if !argv
action_env = {}
if options[:ignore_provider]
action_env[:ignore_provider] = true
end
# Validate the configuration of all machines
with_target_vms() do |machine|
machine.action_raw(:config_validate, Vagrant::Action::Builtin::ConfigValidate, action_env)
end
@env.ui.info(I18n.t("vagrant.commands.validate.success"))
# Success, exit status 0
0
end
end
end
end