2015-11-18 18:59:29 +00:00
|
|
|
require "set"
|
|
|
|
|
2012-04-20 04:33:26 +00:00
|
|
|
module VagrantPlugins
|
|
|
|
module CommandUp
|
2012-03-10 21:54:59 +00:00
|
|
|
module StartMixins
|
|
|
|
# This adds the standard `start` command line flags to the given
|
|
|
|
# OptionParser, storing the result in the `options` dictionary.
|
|
|
|
#
|
|
|
|
# @param [OptionParser] parser
|
|
|
|
# @param [Hash] options
|
|
|
|
def build_start_options(parser, options)
|
|
|
|
# Setup the defaults
|
2013-01-31 03:42:54 +00:00
|
|
|
options[:provision_types] = nil
|
2012-03-10 21:54:59 +00:00
|
|
|
|
|
|
|
# Add the options
|
|
|
|
parser.on("--[no-]provision", "Enable or disable provisioning") do |p|
|
2013-01-31 03:39:21 +00:00
|
|
|
options[:provision_enabled] = p
|
2014-05-06 23:27:48 +00:00
|
|
|
options[:provision_ignore_sentinel] = true
|
2012-03-10 21:54:59 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
parser.on("--provision-with x,y,z", Array,
|
|
|
|
"Enable only certain provisioners, by type.") do |list|
|
2013-01-31 03:51:04 +00:00
|
|
|
options[:provision_types] = list.map { |type| type.to_sym }
|
2014-12-30 03:10:52 +00:00
|
|
|
options[:provision_enabled] = true
|
|
|
|
options[:provision_ignore_sentinel] = true
|
2012-03-10 21:54:59 +00:00
|
|
|
end
|
|
|
|
end
|
2013-09-02 22:06:03 +00:00
|
|
|
|
|
|
|
# This validates the provisioner flags and raises an exception
|
|
|
|
# if there are invalid ones.
|
2015-07-17 04:26:13 +00:00
|
|
|
def validate_provisioner_flags!(options, argv)
|
2015-11-18 18:59:29 +00:00
|
|
|
provisioner_names = Set.new
|
2015-07-17 04:26:13 +00:00
|
|
|
with_target_vms(argv) do |machine|
|
2015-11-18 18:59:29 +00:00
|
|
|
machine.config.vm.provisioners.map(&:name).each do |name|
|
|
|
|
provisioner_names.add(name)
|
|
|
|
end
|
2015-07-17 04:26:13 +00:00
|
|
|
end
|
|
|
|
|
2015-11-18 18:59:29 +00:00
|
|
|
if (provisioner_names & options[:provision_types]).empty?
|
2015-07-17 04:26:13 +00:00
|
|
|
(options[:provision_types] || []).each do |type|
|
|
|
|
klass = Vagrant.plugin("2").manager.provisioners[type]
|
|
|
|
if !klass
|
|
|
|
raise Vagrant::Errors::ProvisionerFlagInvalid,
|
|
|
|
name: type.to_s
|
|
|
|
end
|
|
|
|
end
|
2013-09-02 22:06:03 +00:00
|
|
|
end
|
|
|
|
end
|
2012-03-10 21:54:59 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|