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
|
||||
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
|
||||
# trigger
|
||||
#
|
||||
# @param [Symbol] command Vagrant command to create trigger on
|
||||
# @param [Block] block The defined before block
|
||||
def before(*command, &block)
|
||||
command.flatten!
|
||||
blk = block
|
||||
|
||||
if !block_given? && command.last.is_a?(Hash)
|
||||
# We were given a hash rather than a 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 [Block] block The defined after block
|
||||
def after(*command, &block)
|
||||
command.flatten!
|
||||
blk = block
|
||||
if !block_given? && command.last.is_a?(Hash)
|
||||
# We were given a hash rather than a block,
|
||||
|
@ -77,20 +99,23 @@ module VagrantPlugins
|
|||
else
|
||||
block.call(trigger, VagrantConfigTrigger)
|
||||
end
|
||||
trigger.finalize!
|
||||
return trigger
|
||||
end
|
||||
|
||||
def finalize!
|
||||
# read through configured settings blocks and set their values
|
||||
# and then set up action hooks here?
|
||||
#if !@_before_triggers.empty?
|
||||
# binding.pry
|
||||
#end
|
||||
if !@_before_triggers.empty?
|
||||
@_before_triggers.map { |t| t.finalize! }
|
||||
end
|
||||
|
||||
if !@_after_triggers.empty?
|
||||
@_after_triggers.map { |t| t.finalize! }
|
||||
end
|
||||
end
|
||||
|
||||
# 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)
|
||||
errors = _detected_errors
|
||||
@_before_triggers.each do |bt|
|
||||
|
@ -110,7 +135,7 @@ module VagrantPlugins
|
|||
#
|
||||
# @return [String]
|
||||
def to_s
|
||||
"Trigger"
|
||||
"trigger"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -12,7 +12,7 @@ module VagrantPlugins
|
|||
# Note: This is for internal use only.
|
||||
#
|
||||
# @return [String]
|
||||
attr_reader :id
|
||||
attr_accessor :id
|
||||
|
||||
# Name for the given Trigger. Defaults to nil.
|
||||
#
|
||||
|
@ -96,18 +96,23 @@ module VagrantPlugins
|
|||
|
||||
# these values are expected to always be an Array internally,
|
||||
# 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)
|
||||
end
|
||||
|
||||
if @ignore.is_a?(String)
|
||||
@logger.debug("Updating @ignore variable to be an Array and Symbol")
|
||||
if !@ignore.nil?
|
||||
@ignore = Array(@ignore.to_sym)
|
||||
elsif @ignore.is_a?(Symbol)
|
||||
@logger.debug("Updating @ignore variable to be an Array")
|
||||
@ignore = Array(@ignore)
|
||||
end
|
||||
|
||||
# Convert @run and @run_remote to be a "Shell provisioner"
|
||||
if @run
|
||||
end
|
||||
|
||||
if @run_remote
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
def validate(machine)
|
||||
|
@ -119,7 +124,7 @@ module VagrantPlugins
|
|||
end
|
||||
|
||||
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))
|
||||
end
|
||||
|
||||
|
@ -138,6 +143,10 @@ module VagrantPlugins
|
|||
if !@run_remote.is_a?(Hash)
|
||||
errors << I18n.t("vagrant.config.triggers.run_remote.bad_type", cmd: @command)
|
||||
end
|
||||
|
||||
if !@run_remote.key?(:inline) && !@run_remote.key?(:file)
|
||||
errors << I18n.t("vagrant.config.triggers.run_remote.missing_context", cmd: @command)
|
||||
end
|
||||
end
|
||||
|
||||
if !@name.nil? && !@name.is_a?(String)
|
||||
|
|
Loading…
Reference in New Issue