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

View File

@ -31,29 +31,10 @@ describe VagrantPlugins::CommandPush::Command do
end
it "validates the pushes" do
expect(subject).to receive(:validate_pushes!)
.with(nil, argv, kind_of(Hash))
.once
expect(subject).to receive(:validate_pushes!).once
subject.execute
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
expect(env).to receive(:push).once
subject.execute
@ -93,21 +74,14 @@ describe VagrantPlugins::CommandPush::Command do
context "when that strategy is defined" 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
context "when no strategy is given" do
it "returns the push" do
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])
expect(subject.validate_pushes!(pushes)).to eq(:noop)
end
end
end
@ -127,32 +101,18 @@ describe VagrantPlugins::CommandPush::Command do
context "when that strategy is defined" do
it "returns the strategy" do
expect(subject.validate_pushes!(pushes, :noop)).to eq([:noop])
expect(subject.validate_pushes!(pushes, :ftp)).to eq([:ftp])
expect(subject.validate_pushes!(pushes, :noop)).to eq(:noop)
expect(subject.validate_pushes!(pushes, :ftp)).to eq(:ftp)
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
it "raises an exception" do
expect { subject.validate_pushes!(pushes) }
.to raise_error(Vagrant::Errors::PushStrategyNotProvided)
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

View File

@ -52,16 +52,6 @@ subcommand:
$ 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
in the documentation links on the sidebar.