Do not support multiple strategies right now

This commit is contained in:
Seth Vargo 2014-12-02 13:44:42 -05:00
parent 6b48199346
commit 70b61047c7
3 changed files with 21 additions and 84 deletions

View File

@ -8,24 +8,18 @@ module VagrantPlugins
end end
def execute def execute
options = { all: false }
opts = OptionParser.new do |o| opts = OptionParser.new do |o|
o.banner = "Usage: vagrant push [strategy] [options]" o.banner = "Usage: vagrant push [strategy] [options]"
o.on("-a", "--all", "Run all defined push strategies") do
options[:all] = true
end
end end
# Parse the options # Parse the options
argv = parse_options(opts) argv = parse_options(opts)
return if !argv return if !argv
names = validate_pushes!(@env.pushes, argv, options) name = validate_pushes!(@env.pushes, argv[0])
names.each do |name|
@logger.debug("'push' environment with strategy: `#{name}'") @logger.debug("'push' environment with strategy: `#{name}'")
@env.push(name) @env.push(name)
end
0 0
end end
@ -36,44 +30,37 @@ module VagrantPlugins
# if there are no pushes defined # if there are no pushes defined
# @raise Vagrant::Errors::PushStrategyNotProvided # @raise Vagrant::Errors::PushStrategyNotProvided
# if there are multiple push strategies defined and none were specified # if there are multiple push strategies defined and none were specified
# and `--all` was not given
# @raise Vagrant::Errors::PushStrategyNotDefined # @raise Vagrant::Errors::PushStrategyNotDefined
# if any of the given push names do not correspond to a push strategy # if the given push name do not correspond to a push strategy
# #
# @param [Array<Symbol>] pushes # @param [Array<Symbol>] pushes
# the list of pushes defined by the environment # the list of pushes defined by the environment
# @param [Array<String>] names # @param [String] name
# the list of names provided by the user on the command line # the name provided by the user on the command line
# @param [Hash] options
# a list of options to pass to the validation
# #
# @return [Array<Symbol>] # @return [Symbol]
# the compiled list of pushes # the compiled list of pushes
# #
def validate_pushes!(pushes, names = [], options = {}) def validate_pushes!(pushes, name = nil)
if pushes.nil? || pushes.empty? if pushes.nil? || pushes.empty?
raise Vagrant::Errors::PushesNotDefined raise Vagrant::Errors::PushesNotDefined
end end
names = Array(names).flatten.compact.map(&:to_sym) if name.nil?
if pushes.length == 1
if names.empty? || options[:all] return pushes.first.to_sym
if options[:all] || pushes.length == 1
return pushes.map(&:to_sym)
else else
raise Vagrant::Errors::PushStrategyNotProvided, pushes: pushes raise Vagrant::Errors::PushStrategyNotProvided, pushes: pushes
end end
end end
names.each do |name|
if !pushes.include?(name) if !pushes.include?(name)
raise Vagrant::Errors::PushStrategyNotDefined, raise Vagrant::Errors::PushStrategyNotDefined,
name: name, name: name,
pushes: pushes pushes: pushes
end end
end
return names return name.to_sym
end end
end end
end end

View File

@ -31,29 +31,10 @@ describe VagrantPlugins::CommandPush::Command do
end end
it "validates the pushes" do it "validates the pushes" do
expect(subject).to receive(:validate_pushes!) expect(subject).to receive(:validate_pushes!).once
.with(nil, argv, kind_of(Hash))
.once
subject.execute subject.execute
end end
it "parses arguments" do
list = ["noop", "ftp"]
instance = described_class.new(list, env)
expect(instance).to receive(:validate_pushes!)
.with(nil, list, kind_of(Hash))
.and_return([])
instance.execute
end
it "parses options" do
instance = described_class.new(["--all"], env)
expect(instance).to receive(:validate_pushes!)
.with(nil, argv, all: true)
.and_return([])
instance.execute
end
it "delegates to Environment#push" do it "delegates to Environment#push" do
expect(env).to receive(:push).once expect(env).to receive(:push).once
subject.execute subject.execute
@ -93,21 +74,14 @@ describe VagrantPlugins::CommandPush::Command do
context "when that strategy is defined" do context "when that strategy is defined" do
it "returns that push" do it "returns that push" do
expect(subject.validate_pushes!(pushes, :noop)).to eq([:noop]) expect(subject.validate_pushes!(pushes, :noop)).to eq(:noop)
end end
end end
end end
context "when no strategy is given" do context "when no strategy is given" do
it "returns the push" do it "returns the push" do
expect(subject.validate_pushes!(pushes)).to eq([:noop]) expect(subject.validate_pushes!(pushes)).to eq(:noop)
end
end
context "when --all is given" do
it "returns the push" do
expect(subject.validate_pushes!(pushes, [], all: true))
.to eq([:noop])
end end
end end
end end
@ -127,32 +101,18 @@ describe VagrantPlugins::CommandPush::Command do
context "when that strategy is defined" do context "when that strategy is defined" do
it "returns the strategy" do it "returns the strategy" do
expect(subject.validate_pushes!(pushes, :noop)).to eq([:noop]) expect(subject.validate_pushes!(pushes, :noop)).to eq(:noop)
expect(subject.validate_pushes!(pushes, :ftp)).to eq([:ftp]) expect(subject.validate_pushes!(pushes, :ftp)).to eq(:ftp)
end end
end end
end end
context "when multiple strategies are given" do
it "returns the pushes" do
expect(subject.validate_pushes!(pushes, [:noop, :ftp]))
.to eq([:noop, :ftp])
end
end
context "when no strategy is given" do context "when no strategy is given" do
it "raises an exception" do it "raises an exception" do
expect { subject.validate_pushes!(pushes) } expect { subject.validate_pushes!(pushes) }
.to raise_error(Vagrant::Errors::PushStrategyNotProvided) .to raise_error(Vagrant::Errors::PushStrategyNotProvided)
end end
end end
context "when --all is given" do
it "returns the pushes" do
expect(subject.validate_pushes!(pushes, [], all: true))
.to eq([:noop, :ftp])
end
end
end end
end end
end end

View File

@ -52,16 +52,6 @@ subcommand:
$ vagrant push staging $ vagrant push staging
``` ```
Pushes will be run in the order you specify on the command line, **not the order
they are specified in the `Vagrantfile`!**
To execute all the Vagrant Push strategies, specify the `--all` flag with no
other arguments:
```shell
$ vagrant push --all
```
Vagrant Push is the easiest way to deploy your application. You can read more Vagrant Push is the easiest way to deploy your application. You can read more
in the documentation links on the sidebar. in the documentation links on the sidebar.