From 7941748db743ca03139e1bab1d2500982e1dcaf3 Mon Sep 17 00:00:00 2001 From: Michael Stillwell Date: Sun, 27 Jan 2013 19:52:43 +0000 Subject: [PATCH] Return exit status of 1 on invalid command Makes "vagrant destroyjj" and similar return an exit code of 1, so that "vagrant destroyjj && vagrant up" works as expected. --- lib/vagrant/cli.rb | 2 +- test/unit/vagrant/plugin/v1/cli_test.rb | 31 +++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 test/unit/vagrant/plugin/v1/cli_test.rb diff --git a/lib/vagrant/cli.rb b/lib/vagrant/cli.rb index aeae3ec25..a224f7424 100644 --- a/lib/vagrant/cli.rb +++ b/lib/vagrant/cli.rb @@ -38,7 +38,7 @@ module Vagrant if !command_class || !@sub_command help - return 0 + return 1 end @logger.debug("Invoking command class: #{command_class} #{@sub_args.inspect}") diff --git a/test/unit/vagrant/plugin/v1/cli_test.rb b/test/unit/vagrant/plugin/v1/cli_test.rb new file mode 100644 index 000000000..3546c7a09 --- /dev/null +++ b/test/unit/vagrant/plugin/v1/cli_test.rb @@ -0,0 +1,31 @@ +describe Vagrant::CLI do + + describe "parsing options" do + let(:klass) do + Class.new(described_class) + end + + let(:environment) do + ui = double("UI::Silent") + ui.stub(:info => "bar") + env = double("Vagrant::Environment") + env.stub(:ui => ui) + env.stub(:root_path => "foo") + env.stub(:machine_names => []) + env + end + + it "returns a non-zero exit status if an invalid command is given" do + result = klass.new(["destroypp"], environment).execute + result.should_not == 0 + end + + it "returns an exit status of zero if a valid command is given" do + result = klass.new(["destroy"], environment).execute + result.should == 0 + end + + end + +end +