Add validate command for validating Vagrantfile

This commit is contained in:
Hasyimi Bahrudin 2017-02-07 13:43:49 +08:00
parent fbad6c370a
commit cbda9f0906
3 changed files with 51 additions and 0 deletions

View File

@ -0,0 +1,31 @@
require 'optparse'
module VagrantPlugins
module CommandValidate
class Command < Vagrant.plugin("2", :command)
def self.synopsis
"validates the Vagrantfile"
end
def execute
opts = OptionParser.new do |o|
o.banner = "Usage: vagrant validate"
end
# Parse the options
argv = parse_options(opts)
return if !argv
# Validate the configuration
@env.machine(@env.machine_names.first, @env.default_provider).action_raw(
:config_validate,
Vagrant::Action::Builtin::ConfigValidate)
@env.ui.info(I18n.t("vagrant.commands.validate.success"))
# Success, exit status 0
0
end
end
end
end

View File

@ -0,0 +1,17 @@
require "vagrant"
module VagrantPlugins
module CommandValidate
class Plugin < Vagrant.plugin("2")
name "validate command"
description <<-DESC
The `validate` command validates the Vagrantfile.
DESC
command("validate") do
require File.expand_path("../command", __FILE__)
Command
end
end
end
end

View File

@ -1726,6 +1726,9 @@ en:
up: up:
upping: |- upping: |-
Bringing machine '%{name}' up with '%{provider}' provider... Bringing machine '%{name}' up with '%{provider}' provider...
validate:
success: |-
Vagrantfile validated successfully.
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
# Translations for Vagrant middleware actions # Translations for Vagrant middleware actions