Move disk config validation messages to locales file

This commit is contained in:
Brian Cain 2019-11-19 13:48:29 -08:00
parent 57fd731fbf
commit ea7a230cb6
No known key found for this signature in database
GPG Key ID: 9FC4639B2E4510A0
2 changed files with 23 additions and 6 deletions

View File

@ -121,28 +121,34 @@ module VagrantPlugins
# validate type with list of known disk types
if !DEFAULT_DISK_TYPES.include?(@type)
errors << "Disk type '#{@type}' is not a valid type. Please pick one of the following supported disk types: #{DEFAULT_DISK_TYPES.join(', ')}"
errors << I18n.t("vagrant.config.disk.invalid_type", type: @type,
types: DEFAULT_DISK_TYPES.join(', '))
end
if @size && !@size.is_a?(Integer)
if @size.is_a?(String)
@size = Vagrant::Util::Numeric.string_to_bytes(@size)
else
errors << "Config option size for disk is not an integer"
end
if !@size
errors << I18n.t("vagrant.config.disk.invalid_size", name: @name, machine: machine.name)
end
end
if @file
if !@file.is_a?(String)
errors << "Config option `file` for #{machine.name} disk config is not a string"
errors << I18n.t("vagrant.config.disk.invalid_file_type", file: @file, machine: machine.name)
elsif !File.file?(@file)
errors << "Disk file '#{@file}' for disk '#{@name}' on machine '#{machine.name}' does not exist."
errors << I18n.t("vagrant.config.disk.missing_file", file_path: @file,
name: @name, machine: machine.name)
end
end
if @provider_config
if !@provider_config.keys.include?(machine.provider_name)
machine.env.ui.warn("Guest '#{machine.name}' using provider '#{machine.provider_name}' has provider specific config options for a provider other than '#{machine.provider_name}'. These provider config options will be ignored for this guest")
machine.env.ui.warn(I18n.t("vagrant.config.disk.missing_provider",
machine: machine.name,
provider_name: machine.provider_name))
end
end

View File

@ -1792,6 +1792,17 @@ en:
# Translations for config validation errors
#-------------------------------------------------------------------------------
config:
disk:
invalid_type: |-
Disk type '%{type}' is not a valid type. Please pick one of the following supported disk types: %{types}
invalid_size: |-
Config option 'size' for disk '%{name}' on guest '%{machine}' is not an integer
invalid_file_type: |-
Disk config option 'file' for '%{machine}' is not a string.
missing_file: |-
Disk file '%{file_path}' for disk '%{name}' on machine '%{machine}' does not exist.
missing_provider: |-
Guest '%{machine}' using provider '%{provider_name}' has provider specific config options for a provider other than '%{provider_name}'. These provider config options will be ignored for this guest
common:
bad_field: "The following settings shouldn't exist: %{fields}"
chef: