From 70b61047c748e05b39aa838460d8f697edecdfae Mon Sep 17 00:00:00 2001 From: Seth Vargo Date: Tue, 2 Dec 2014 13:44:42 -0500 Subject: [PATCH] Do not support multiple strategies right now --- plugins/commands/push/command.rb | 45 ++++++----------- .../plugins/commands/push/command_test.rb | 50 ++----------------- website/docs/source/v2/push/index.html.md | 10 ---- 3 files changed, 21 insertions(+), 84 deletions(-) diff --git a/plugins/commands/push/command.rb b/plugins/commands/push/command.rb index f3390723b..5fde89175 100644 --- a/plugins/commands/push/command.rb +++ b/plugins/commands/push/command.rb @@ -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] pushes # the list of pushes defined by the environment - # @param [Array] 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] + # @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 diff --git a/test/unit/plugins/commands/push/command_test.rb b/test/unit/plugins/commands/push/command_test.rb index 292e2ee0e..113908ebf 100644 --- a/test/unit/plugins/commands/push/command_test.rb +++ b/test/unit/plugins/commands/push/command_test.rb @@ -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 diff --git a/website/docs/source/v2/push/index.html.md b/website/docs/source/v2/push/index.html.md index 5f061862a..310039176 100644 --- a/website/docs/source/v2/push/index.html.md +++ b/website/docs/source/v2/push/index.html.md @@ -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.