Validate machine scopes from config object and show a nice looking message instead of a stacktrace :)
This should be enough to close #33
This commit is contained in:
parent
20e1176a10
commit
068d9cc8b8
2 changed files with 16 additions and 0 deletions
|
@ -4,6 +4,8 @@ module VagrantPlugins
|
||||||
attr_accessor :scope, :auto_detect, :enable_nfs
|
attr_accessor :scope, :auto_detect, :enable_nfs
|
||||||
attr_reader :buckets
|
attr_reader :buckets
|
||||||
|
|
||||||
|
ALLOWED_SCOPES = %w( box machine )
|
||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
@scope = UNSET_VALUE
|
@scope = UNSET_VALUE
|
||||||
@auto_detect = UNSET_VALUE
|
@auto_detect = UNSET_VALUE
|
||||||
|
@ -14,6 +16,18 @@ module VagrantPlugins
|
||||||
(@buckets ||= {})[bucket] = opts
|
(@buckets ||= {})[bucket] = opts
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def validate(machine)
|
||||||
|
errors = _detected_errors
|
||||||
|
|
||||||
|
if enabled? && ! ALLOWED_SCOPES.include?(@scope.to_s)
|
||||||
|
errors << I18n.t('vagrant_cachier.unknown_cache_scope',
|
||||||
|
allowed: ALLOWED_SCOPES.inspect,
|
||||||
|
cache_scope: @scope)
|
||||||
|
end
|
||||||
|
|
||||||
|
{ "vagrant cachier" => errors }
|
||||||
|
end
|
||||||
|
|
||||||
def finalize!
|
def finalize!
|
||||||
return unless enabled?
|
return unless enabled?
|
||||||
|
|
||||||
|
|
|
@ -4,3 +4,5 @@ en:
|
||||||
Removing cache buckets symlinks...
|
Removing cache buckets symlinks...
|
||||||
skipping_bucket: |-
|
skipping_bucket: |-
|
||||||
Skipping %{bucket} cache bucket as the guest machine does not support it
|
Skipping %{bucket} cache bucket as the guest machine does not support it
|
||||||
|
unknown_cache_scope: |-
|
||||||
|
Unknown cache scope '%{cache_scope}' (allowed scopes: %{allowed})
|
||||||
|
|
Loading…
Reference in a new issue