Merge pull request #2412 from maxlinc/config_validation

website/docs: document '_detected_errors' pattern in plugin configuration guide.
This commit is contained in:
Mitchell Hashimoto 2013-10-23 23:08:45 -07:00
commit e99fc28d8a
1 changed files with 6 additions and 3 deletions

View File

@ -148,11 +148,12 @@ class Config < Vagrant.plugin("2", :config)
# ... # ...
def validate(machine) def validate(machine)
errors = _detected_errors
if @widgets <= 5 if @widgets <= 5
return { "foo" => ["widgets must be greater than 5"] } errors << "widgets must be greater than 5"
end end
{} { "foo" => errors }
end end
end end
``` ```
@ -161,6 +162,8 @@ The validation method is given a `machine` object, since validation is
done for each machine that Vagrant is managing. This allows you to done for each machine that Vagrant is managing. This allows you to
conditionally validate some keys based on the state of the machine and so on. conditionally validate some keys based on the state of the machine and so on.
The `_detected_errors` method returns any errors already detected by Vagrant, like unknown configuration keys.
The return value is a Ruby Hash object, where the key is a section name, The return value is a Ruby Hash object, where the key is a section name,
and the value is a list of error messages. These will be displayed by and the value is a list of error messages. These will be displayed by
Vagrant. If there are no errors, an empty hash must be returned. Vagrant. The hash must not contain any values if there are no errors.