Merge pull request #8264 from hasyimibhar/command-validate
Add validate command
This commit is contained in:
commit
256ce3b0d5
|
@ -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
|
|
@ -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
|
|
@ -1732,6 +1732,9 @@ en:
|
|||
up:
|
||||
upping: |-
|
||||
Bringing machine '%{name}' up with '%{provider}' provider...
|
||||
validate:
|
||||
success: |-
|
||||
Vagrantfile validated successfully.
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Translations for Vagrant middleware actions
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
require_relative "../../../base"
|
||||
require_relative "../../../../../plugins/commands/validate/command"
|
||||
|
||||
describe VagrantPlugins::CommandValidate::Command do
|
||||
include_context "unit"
|
||||
include_context "command plugin helpers"
|
||||
|
||||
let(:iso_env) do
|
||||
isolated_environment
|
||||
end
|
||||
|
||||
let(:env) do
|
||||
iso_env.create_vagrant_env
|
||||
end
|
||||
|
||||
let(:argv) { [] }
|
||||
|
||||
before(:all) do
|
||||
I18n.load_path << Vagrant.source_root.join("plugins/commands/port/locales/en.yml")
|
||||
I18n.reload!
|
||||
end
|
||||
|
||||
subject { described_class.new(argv, env) }
|
||||
|
||||
describe "#execute" do
|
||||
it "validates correct Vagrantfile" do
|
||||
iso_env.vagrantfile(<<-EOH)
|
||||
Vagrant.configure("2") do |config|
|
||||
config.vm.box = "hashicorp/precise64"
|
||||
end
|
||||
EOH
|
||||
|
||||
expect(env.ui).to receive(:info).with { |message, _|
|
||||
expect(message).to include("Vagrantfile validated successfully.")
|
||||
}
|
||||
|
||||
expect(subject.execute).to eq(0)
|
||||
end
|
||||
|
||||
it "validates the configuration" do
|
||||
iso_env.vagrantfile <<-EOH
|
||||
Vagrant.configure("2") do |config|
|
||||
config.vm.bix = "hashicorp/precise64"
|
||||
end
|
||||
EOH
|
||||
|
||||
expect { subject.execute }.to raise_error(Vagrant::Errors::ConfigInvalid) { |err|
|
||||
expect(err.message).to include("The following settings shouldn't exist: bix")
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,20 @@
|
|||
---
|
||||
layout: "docs"
|
||||
page_title: "vagrant validate - Command-Line Interface"
|
||||
sidebar_current: "cli-validate"
|
||||
description: |-
|
||||
The "vagrant validate" command is used to validate your Vagrantfile.
|
||||
---
|
||||
|
||||
# Validate
|
||||
|
||||
**Command: `vagrant validate`**
|
||||
|
||||
This command validates your [Vagrantfile](/docs/vagrantfile/).
|
||||
|
||||
## Examples
|
||||
|
||||
```sh
|
||||
$ vagrant validate
|
||||
Vagrantfile validated successfully.
|
||||
```
|
|
@ -62,6 +62,7 @@
|
|||
<li<%= sidebar_current("cli-status") %>><a href="/docs/cli/status.html">status</a></li>
|
||||
<li<%= sidebar_current("cli-suspend") %>><a href="/docs/cli/suspend.html">suspend</a></li>
|
||||
<li<%= sidebar_current("cli-up") %>><a href="/docs/cli/up.html">up</a></li>
|
||||
<li<%= sidebar_current("cli-validate") %>><a href="/docs/cli/validate.html">validate</a></li>
|
||||
<li<%= sidebar_current("cli-version") %>><a href="/docs/cli/version.html">version</a></li>
|
||||
<li<%= sidebar_current("cli-nonprimary") %>><a href="/docs/cli/non-primary.html">More Commands</a></li>
|
||||
<li<%= sidebar_current("cli-machinereadable") %>><a href="/docs/cli/machine-readable.html">Machine Readable Output</a></li>
|
||||
|
|
Loading…
Reference in New Issue