vagrant/plugins/commands/push/command.rb

69 lines
1.9 KiB
Ruby
Raw Normal View History

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
name = validate_pushes!(@env.pushes, argv[0])
2014-10-23 17:51:18 +00:00
@logger.debug("'push' environment with strategy: `#{name}'")
@env.push(name)
2014-10-23 17:51:18 +00:00
0
end
# 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
# if the given push name do not correspond to a push strategy
2014-10-23 17:51:18 +00:00
#
# @param [Array<Symbol>] pushes
# the list of pushes defined by the environment
# @param [String] name
# the name provided by the user on the command line
2014-10-23 17:51:18 +00:00
#
# @return [Symbol]
# the compiled list of pushes
2014-10-23 17:51:18 +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
if name.nil?
if pushes.length == 1
return pushes.first.to_sym
else
2014-10-23 17:51:18 +00:00
raise Vagrant::Errors::PushStrategyNotProvided, pushes: pushes
end
end
if !pushes.include?(name)
raise Vagrant::Errors::PushStrategyNotDefined,
name: name,
pushes: pushes
2014-10-23 17:51:18 +00:00
end
return name.to_sym
2014-10-23 17:51:18 +00:00
end
end
end
end