core: Can exclude providers

This commit is contained in:
Mitchell Hashimoto 2014-05-01 09:50:35 -07:00
parent ab9f91568e
commit cca9bffa90
2 changed files with 18 additions and 3 deletions

View File

@ -253,6 +253,7 @@ module Vagrant
# #
# @return [Symbol] Name of the default provider. # @return [Symbol] Name of the default provider.
def default_provider(**opts) def default_provider(**opts)
opts[:exclude] = Set.new(opts[:exclude]) if opts[:exclude]
opts[:force_default] = true if !opts.has_key?(:force_default) opts[:force_default] = true if !opts.has_key?(:force_default)
default = ENV["VAGRANT_DEFAULT_PROVIDER"] default = ENV["VAGRANT_DEFAULT_PROVIDER"]
@ -265,10 +266,13 @@ module Vagrant
ordered = [] ordered = []
Vagrant.plugin("2").manager.providers.each do |key, data| Vagrant.plugin("2").manager.providers.each do |key, data|
impl = data[0] impl = data[0]
opts = data[1] popts = data[1]
ordered << [opts[:priority], key, impl, opts] # Skip excluded providers
next if opts[:exclude] && opts[:exclude].include?(key)
ordered << [popts[:priority], key, impl, popts]
end end
# Order the providers by priority. Higher values are tried first. # Order the providers by priority. Higher values are tried first.

View File

@ -717,6 +717,17 @@ VF
end end
end end
it "is the highest matching usable provider that isn't excluded" do
plugin_providers[:foo] = [provider_usable_class(true), { priority: 5 }]
plugin_providers[:bar] = [provider_usable_class(true), { priority: 7 }]
plugin_providers[:baz] = [provider_usable_class(true), { priority: 2 }]
plugin_providers[:boom] = [provider_usable_class(true), { priority: 3 }]
with_temp_env("VAGRANT_DEFAULT_PROVIDER" => nil) do
expect(subject.default_provider(exclude: [:bar, :foo])).to eq(:boom)
end
end
it "is the default provider set if usable" do it "is the default provider set if usable" do
plugin_providers[:foo] = [provider_usable_class(true), { priority: 5 }] plugin_providers[:foo] = [provider_usable_class(true), { priority: 5 }]
plugin_providers[:bar] = [provider_usable_class(true), { priority: 7 }] plugin_providers[:bar] = [provider_usable_class(true), { priority: 7 }]