2014-10-23 17:51:18 +00:00
|
|
|
require 'optparse'
|
|
|
|
|
|
|
|
module VagrantPlugins
|
|
|
|
module CommandPush
|
|
|
|
class Command < Vagrant.plugin("2", :command)
|
|
|
|
def self.synopsis
|
|
|
|
"deploys code in this environment to a configured destination"
|
|
|
|
end
|
|
|
|
|
2014-12-02 18:46:22 +00:00
|
|
|
# @todo support multiple strategies if requested by the community
|
2014-10-23 17:51:18 +00:00
|
|
|
def execute
|
|
|
|
opts = OptionParser.new do |o|
|
|
|
|
o.banner = "Usage: vagrant push [strategy] [options]"
|
|
|
|
end
|
|
|
|
|
|
|
|
# Parse the options
|
|
|
|
argv = parse_options(opts)
|
|
|
|
return if !argv
|
|
|
|
|
2014-12-02 18:44:42 +00:00
|
|
|
name = validate_pushes!(@env.pushes, argv[0])
|
2014-10-23 17:51:18 +00:00
|
|
|
|
2014-12-02 18:44:42 +00:00
|
|
|
@logger.debug("'push' environment with strategy: `#{name}'")
|
|
|
|
@env.push(name)
|
2014-10-23 17:51:18 +00:00
|
|
|
|
|
|
|
0
|
|
|
|
end
|
|
|
|
|
2014-12-02 18:30:16 +00:00
|
|
|
# Validate that the given list of names corresponds to valid pushes.
|
|
|
|
#
|
|
|
|
# @raise Vagrant::Errors::PushesNotDefined
|
|
|
|
# if there are no pushes defined
|
|
|
|
# @raise Vagrant::Errors::PushStrategyNotProvided
|
|
|
|
# if there are multiple push strategies defined and none were specified
|
|
|
|
# @raise Vagrant::Errors::PushStrategyNotDefined
|
2014-12-02 18:44:42 +00:00
|
|
|
# if the given push name do not correspond to a push strategy
|
2014-10-23 17:51:18 +00:00
|
|
|
#
|
2014-12-02 18:30:16 +00:00
|
|
|
# @param [Array<Symbol>] pushes
|
|
|
|
# the list of pushes defined by the environment
|
2014-12-02 18:44:42 +00:00
|
|
|
# @param [String] name
|
|
|
|
# the name provided by the user on the command line
|
2014-10-23 17:51:18 +00:00
|
|
|
#
|
2014-12-02 18:44:42 +00:00
|
|
|
# @return [Symbol]
|
2014-12-02 18:30:16 +00:00
|
|
|
# the compiled list of pushes
|
2014-10-23 17:51:18 +00:00
|
|
|
#
|
2014-12-02 18:44:42 +00:00
|
|
|
def validate_pushes!(pushes, name = nil)
|
2014-10-23 17:51:18 +00:00
|
|
|
if pushes.nil? || pushes.empty?
|
|
|
|
raise Vagrant::Errors::PushesNotDefined
|
|
|
|
end
|
|
|
|
|
2014-12-02 18:44:42 +00:00
|
|
|
if name.nil?
|
|
|
|
if pushes.length == 1
|
|
|
|
return pushes.first.to_sym
|
2014-12-02 18:30:16 +00:00
|
|
|
else
|
2014-12-15 06:27:40 +00:00
|
|
|
raise Vagrant::Errors::PushStrategyNotProvided,
|
|
|
|
pushes: pushes.map(&:to_s)
|
2014-10-23 17:51:18 +00:00
|
|
|
end
|
2014-12-02 18:30:16 +00:00
|
|
|
end
|
|
|
|
|
2014-12-12 09:27:22 +00:00
|
|
|
name = name.to_sym
|
2014-12-02 18:44:42 +00:00
|
|
|
if !pushes.include?(name)
|
|
|
|
raise Vagrant::Errors::PushStrategyNotDefined,
|
2014-12-12 09:27:22 +00:00
|
|
|
name: name.to_s,
|
|
|
|
pushes: pushes.map(&:to_s)
|
2014-10-23 17:51:18 +00:00
|
|
|
end
|
|
|
|
|
2014-12-12 09:27:22 +00:00
|
|
|
return name
|
2014-10-23 17:51:18 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|