Warn users about unknown requested experimental features

This commit is contained in:
Brian Cain 2018-12-07 13:31:18 -08:00
parent 01ec72cac2
commit accabdd7ca
No known key found for this signature in database
GPG Key ID: 9FC4639B2E4510A0
4 changed files with 39 additions and 7 deletions

View File

@ -172,6 +172,13 @@ begin
logger.debug("Experimental flag is enabled")
if Vagrant::Util::Experimental.global_enabled?
ui.warn(I18n.t("vagrant.general.experimental.all"), bold: true, prefix: true, channel: :error)
else
ui.warn(I18n.t("vagrant.general.experimental.features", features: experimental.join(", ")), bold: true, prefix: true, channel: :error)
diff = Vagrant::Util::Experimental.features_valid?
if !diff.empty?
ui.error(I18n.t("vagrant.general.experimental.unknown_features", unknown: diff.join(", ")), bold: true, prefix: true, channel: :error)
end
end
end

View File

@ -45,14 +45,19 @@ module Vagrant
experimental = features_requested
feature = feature.to_s
if experimental.size == 1 && experimental.first == "1"
return true
elsif VALID_FEATURES.include?(feature) &&
experimental.include?(feature)
return true
else
return false
return global_enabled? || (VALID_FEATURES.include?(feature) && experimental.include?(feature))
end
# Determines if there are any unrecognized requested features
#
# @return [Array]
def features_valid?
if !defined?(@_features_diff)
@_features_diff = []
features = features_requested
features.each { |f| @_features_diff << f if !VALID_FEATURES.include?(f) }
end
@_features_diff
end
# Returns the features requested for the experimental flag

View File

@ -405,6 +405,10 @@ en:
Please use with caution, as some of the features may not be fully
functional yet.
unknown_features: |-
Requested unknown feature flags will be ignored:
Unknown: %{unknown}
not_in_installer: |-
You appear to be running Vagrant outside of the official installers.
Note that the installers are what ensure that Vagrant has all required

View File

@ -98,6 +98,22 @@ describe Vagrant::Util::Experimental do
end
end
describe "#features_valid" do
before(:each) do
stub_const("Vagrant::Util::Experimental::VALID_FEATURES", ["cool_feature", "other_feature", "secret_feature"])
end
it "returns an empty array if no diffs found" do
allow(ENV).to receive(:[]).with("VAGRANT_EXPERIMENTAL").and_return("cool_feature,other_feature")
expect(subject.features_valid?).to eq([])
end
it "returns the invalid flag if found" do
allow(ENV).to receive(:[]).with("VAGRANT_EXPERIMENTAL").and_return("fake_feature")
expect(subject.features_valid?).to eq(["fake_feature"])
end
end
describe "#features_requested" do
it "returns an array of requested features" do
allow(ENV).to receive(:[]).with("VAGRANT_EXPERIMENTAL").and_return("secret_feature,other_secret")