Finalize config in plugins finalize, improve docs
This commit is contained in:
parent
b04f13657b
commit
5ca1d1ab64
|
@ -15,13 +15,34 @@ module VagrantPlugins
|
||||||
@_after_triggers = [] # An array of VagrantConfigTrigger objects
|
@_after_triggers = [] # An array of VagrantConfigTrigger objects
|
||||||
end
|
end
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------
|
||||||
|
# Trigger before/after functions
|
||||||
|
#-------------------------------------------------------------------
|
||||||
|
#
|
||||||
|
# Commands are expected to be ether:
|
||||||
|
# - splat
|
||||||
|
# + config.trigger.before :up, :destroy, :halt do |trigger|....
|
||||||
|
# - array
|
||||||
|
# + config.trigger.before [:up, :destroy, :halt] do |trigger|....
|
||||||
|
#
|
||||||
|
# Config is expected to be given as a block, or the last parameter as a hash
|
||||||
|
#
|
||||||
|
# - block
|
||||||
|
# + config.trigger.before :up, :destroy, :halt do |trigger|
|
||||||
|
# trigger.option = "option"
|
||||||
|
# end
|
||||||
|
# - hash
|
||||||
|
# + config.trigger.before :up, :destroy, :halt, options: "option"
|
||||||
|
|
||||||
# Reads in and parses Vagrant command whitelist and settings for a defined
|
# Reads in and parses Vagrant command whitelist and settings for a defined
|
||||||
# trigger
|
# trigger
|
||||||
#
|
#
|
||||||
# @param [Symbol] command Vagrant command to create trigger on
|
# @param [Symbol] command Vagrant command to create trigger on
|
||||||
# @param [Block] block The defined before block
|
# @param [Block] block The defined before block
|
||||||
def before(*command, &block)
|
def before(*command, &block)
|
||||||
|
command.flatten!
|
||||||
blk = block
|
blk = block
|
||||||
|
|
||||||
if !block_given? && command.last.is_a?(Hash)
|
if !block_given? && command.last.is_a?(Hash)
|
||||||
# We were given a hash rather than a block,
|
# We were given a hash rather than a block,
|
||||||
# so the last element should be the "config block"
|
# so the last element should be the "config block"
|
||||||
|
@ -43,6 +64,7 @@ module VagrantPlugins
|
||||||
# @param [Symbol] command Vagrant command to create trigger on
|
# @param [Symbol] command Vagrant command to create trigger on
|
||||||
# @param [Block] block The defined after block
|
# @param [Block] block The defined after block
|
||||||
def after(*command, &block)
|
def after(*command, &block)
|
||||||
|
command.flatten!
|
||||||
blk = block
|
blk = block
|
||||||
if !block_given? && command.last.is_a?(Hash)
|
if !block_given? && command.last.is_a?(Hash)
|
||||||
# We were given a hash rather than a block,
|
# We were given a hash rather than a block,
|
||||||
|
@ -77,20 +99,23 @@ module VagrantPlugins
|
||||||
else
|
else
|
||||||
block.call(trigger, VagrantConfigTrigger)
|
block.call(trigger, VagrantConfigTrigger)
|
||||||
end
|
end
|
||||||
trigger.finalize!
|
|
||||||
return trigger
|
return trigger
|
||||||
end
|
end
|
||||||
|
|
||||||
def finalize!
|
def finalize!
|
||||||
# read through configured settings blocks and set their values
|
# read through configured settings blocks and set their values
|
||||||
# and then set up action hooks here?
|
# and then set up action hooks here?
|
||||||
#if !@_before_triggers.empty?
|
if !@_before_triggers.empty?
|
||||||
# binding.pry
|
@_before_triggers.map { |t| t.finalize! }
|
||||||
#end
|
end
|
||||||
|
|
||||||
|
if !@_after_triggers.empty?
|
||||||
|
@_after_triggers.map { |t| t.finalize! }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Validate Trigger settings
|
# Validate Trigger settings
|
||||||
# TODO: Validate not called if there are providers defined in vagrantfile
|
# TODO: Validate not called if there are guests defined in vagrantfile
|
||||||
def validate(machine)
|
def validate(machine)
|
||||||
errors = _detected_errors
|
errors = _detected_errors
|
||||||
@_before_triggers.each do |bt|
|
@_before_triggers.each do |bt|
|
||||||
|
@ -110,7 +135,7 @@ module VagrantPlugins
|
||||||
#
|
#
|
||||||
# @return [String]
|
# @return [String]
|
||||||
def to_s
|
def to_s
|
||||||
"Trigger"
|
"trigger"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -12,7 +12,7 @@ module VagrantPlugins
|
||||||
# Note: This is for internal use only.
|
# Note: This is for internal use only.
|
||||||
#
|
#
|
||||||
# @return [String]
|
# @return [String]
|
||||||
attr_reader :id
|
attr_accessor :id
|
||||||
|
|
||||||
# Name for the given Trigger. Defaults to nil.
|
# Name for the given Trigger. Defaults to nil.
|
||||||
#
|
#
|
||||||
|
@ -96,18 +96,23 @@ module VagrantPlugins
|
||||||
|
|
||||||
# these values are expected to always be an Array internally,
|
# these values are expected to always be an Array internally,
|
||||||
# but can be set as a single String or Symbol
|
# but can be set as a single String or Symbol
|
||||||
if @only_on.is_a?(String)
|
#
|
||||||
@logger.debug("Updating @only_on variable to be an Array")
|
# map to all be strings
|
||||||
|
if !@only_on.nil?
|
||||||
@only_on = Array(@only_on)
|
@only_on = Array(@only_on)
|
||||||
end
|
end
|
||||||
|
|
||||||
if @ignore.is_a?(String)
|
if !@ignore.nil?
|
||||||
@logger.debug("Updating @ignore variable to be an Array and Symbol")
|
|
||||||
@ignore = Array(@ignore.to_sym)
|
@ignore = Array(@ignore.to_sym)
|
||||||
elsif @ignore.is_a?(Symbol)
|
|
||||||
@logger.debug("Updating @ignore variable to be an Array")
|
|
||||||
@ignore = Array(@ignore)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Convert @run and @run_remote to be a "Shell provisioner"
|
||||||
|
if @run
|
||||||
|
end
|
||||||
|
|
||||||
|
if @run_remote
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def validate(machine)
|
def validate(machine)
|
||||||
|
@ -119,7 +124,7 @@ module VagrantPlugins
|
||||||
end
|
end
|
||||||
|
|
||||||
if !commands.include?(@command)
|
if !commands.include?(@command)
|
||||||
@logger.warn(I18n.t("vagrant.config.triggers.bad_command_warning",
|
machine.ui.warn(I18n.t("vagrant.config.triggers.bad_command_warning",
|
||||||
cmd: @command))
|
cmd: @command))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -138,6 +143,10 @@ module VagrantPlugins
|
||||||
if !@run_remote.is_a?(Hash)
|
if !@run_remote.is_a?(Hash)
|
||||||
errors << I18n.t("vagrant.config.triggers.run_remote.bad_type", cmd: @command)
|
errors << I18n.t("vagrant.config.triggers.run_remote.bad_type", cmd: @command)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if !@run_remote.key?(:inline) && !@run_remote.key?(:file)
|
||||||
|
errors << I18n.t("vagrant.config.triggers.run_remote.missing_context", cmd: @command)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if !@name.nil? && !@name.is_a?(String)
|
if !@name.nil? && !@name.is_a?(String)
|
||||||
|
|
Loading…
Reference in New Issue