summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorJohn Keiser <jkeiser@opscode.com>2011-08-25 09:35:09 -0700
committerJohn Keiser <jkeiser@opscode.com>2011-08-25 09:35:09 -0700
commit8b01a09e9cbf038441a3fbf86fd5632cacbb3faf (patch)
treee32f71c6044ed4fe25d2ea535649c6868fb4aad0 /spec
parent454317e034bfa863b28ac4b88e375656eac1fa30 (diff)
downloadmixlib-cli-8b01a09e9cbf038441a3fbf86fd5632cacbb3faf.tar.gz
CHEF-2571: support negated bool parameters
Using --[no-]xxx on a boolean parameter lets the user specify the value as false, like in OptionParser.
Diffstat (limited to 'spec')
-rw-r--r--spec/mixlib/cli_spec.rb11
1 files changed, 9 insertions, 2 deletions
diff --git a/spec/mixlib/cli_spec.rb b/spec/mixlib/cli_spec.rb
index 05c6491..aaa2d3a 100644
--- a/spec/mixlib/cli_spec.rb
+++ b/spec/mixlib/cli_spec.rb
@@ -156,18 +156,25 @@ describe Mixlib::CLI do
@cli.config[:i_am_boolean].should == true
end
+ it "should set the corresponding config value to false when a boolean is prefixed with --no" do
+ TestCLI.option(:i_am_boolean, :long => "--[no-]bool", :boolean => true)
+ @cli = TestCLI.new
+ @cli.parse_options([ '--no-bool' ])
+ @cli.config[:i_am_boolean].should == false
+ end
+
it "should exit if a config option has :exit set" do
TestCLI.option(:i_am_exit, :short => "-x", :boolean => true, :exit => 0)
@cli = TestCLI.new
lambda { @cli.parse_options(["-x"]) }.should raise_error(SystemExit)
end
-
+
it "should exit if a required option is missing" do
TestCLI.option(:require_me, :short => "-r", :boolean => true, :required => true)
@cli = TestCLI.new
lambda { @cli.parse_options([]) }.should raise_error(SystemExit)
end
-
+
it "should preserve all of the commandline arguments, ARGV" do
TestCLI.option(:config_file, :short => "-c CONFIG")
@cli = TestCLI.new