summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMehrez Alachheb <lachheb.mehrez@gmail.com>2014-06-12 10:53:20 +0200
committerMehrez Alachheb <lachheb.mehrez@gmail.com>2014-06-12 10:53:20 +0200
commit0c00fdb5775cd2e5cd0d6d70ec73fc2133b72956 (patch)
tree1dd8a88898792be245a43f2cef1ba9a25281803c
parent0c6ce30635400bee50ee205990031ae39edaa3dc (diff)
downloadmixlib-cli-0c00fdb5775cd2e5cd0d6d70ec73fc2133b72956.tar.gz
Fix code review notes
-rw-r--r--lib/mixlib/cli.rb8
-rw-r--r--spec/mixlib/cli_spec.rb10
2 files changed, 8 insertions, 10 deletions
diff --git a/lib/mixlib/cli.rb b/lib/mixlib/cli.rb
index f0b62d2..90adc49 100644
--- a/lib/mixlib/cli.rb
+++ b/lib/mixlib/cli.rb
@@ -234,15 +234,13 @@ module Mixlib
puts @opt_parser
exit 2
end
- if opt_value[:in]
+ if opt_value[:in]
unless opt_value[:in].kind_of?(Array)
- raise(ArgumentError, "Options config key :in must recieve an Array")
- puts @opt_parser
- exit 2
+ raise(ArgumentError, "Options config key :in must receive an Array")
end
if !opt_value[:in].include?(config[opt_key])
reqarg = opt_value[:short] || opt_value[:long]
- puts "#{reqarg}: #{config[opt_key]} is not included in the list #{opt_value[:in]}"
+ puts "#{reqarg}: #{config[opt_key]} is not included in the list ['#{opt_value[:in].join("', '")}'] "
puts @opt_parser
exit 2
end
diff --git a/spec/mixlib/cli_spec.rb b/spec/mixlib/cli_spec.rb
index e2fa647..550b26f 100644
--- a/spec/mixlib/cli_spec.rb
+++ b/spec/mixlib/cli_spec.rb
@@ -175,26 +175,26 @@ describe Mixlib::CLI do
@cli = TestCLI.new
lambda { @cli.parse_options([]) }.should raise_error(SystemExit)
end
-
+
it "should exit if option is not included in the list" do
TestCLI.option(:inclusion, :short => "-i val", :in => ['one', 'two'])
@cli = TestCLI.new
lambda { @cli.parse_options(['-i', 'three']) }.should raise_error(SystemExit)
end
-
- it "should exit if options key :in is not an array" do
+
+ it "should raise ArgumentError if options key :in is not an array" do
TestCLI.option(:inclusion, :short => "-i val", :in => 'foo')
@cli = TestCLI.new
lambda { @cli.parse_options(['-i', 'three']) }.should raise_error(ArgumentError)
end
-
+
it "should not exit if option is included in the list" do
TestCLI.option(:inclusion, :short => "-i val", :in => ['one', 'two'])
@cli = TestCLI.new
@cli.parse_options(['-i', 'one'])
@cli.config[:inclusion].should == 'one'
end
-
+
it "should change description if :in key is specified" do
TestCLI.option(:inclusion, :short => "-i val", :in => ['one', 'two'], :description => 'desc')
@cli = TestCLI.new