mixlib-cli 1.6.0 → 1.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d2d8c52004fea1ccbbacc8cc9eb27c90319169a7
4
- data.tar.gz: 02c491e6efbd0311e961fabdfa5104cac182f906
3
+ metadata.gz: 3a5fa5c9380ff647b7d3fa3be1bff7e2103c9f94
4
+ data.tar.gz: d384bc4569b4577a90bc20d06d9d2f9b5564178d
5
5
  SHA512:
6
- metadata.gz: f0ebca3acd4ff265dc86b78ad542b2400260167345d6d05334359e2e4e575160d26ccaa905e42cc36e8eaecf373ed5f7b6eafc6d0f0e72c8dd9541d6749e4cda
7
- data.tar.gz: 08c9482a936d10feea1f968effa75beba3f7f0911fa63dbf16755da7d0f674df9f64622f2941050ea7a16ed71efd4b963b7715956b819f67362469668b0d7d71
6
+ metadata.gz: ea74cdb6f6afc9758a24a143c0d1702423e87a3fcce4749c61e3c83da4b289967a47a1473513b8f695a9d2e66d0aad188f1fdf1f6aae91648e4ce30f5c33b6ea
7
+ data.tar.gz: 62421ca5582e801d8e3112bbef7e55f16cdff8bf77c5520f7539bffa36e7602644ef2ac4aaee2733dda90db95156d58e06dfd2e7d0e1ddfae6856704b5c5b323
data/lib/mixlib/cli.rb CHANGED
@@ -281,7 +281,18 @@ module Mixlib
281
281
 
282
282
  parse_block =
283
283
  Proc.new() do |c|
284
- config[opt_key] = (opt_val[:proc] && opt_val[:proc].call(c)) || c
284
+ config[opt_key] = if opt_val[:proc]
285
+ if opt_val[:proc].arity == 2
286
+ # New hotness to allow for reducer-style procs.
287
+ opt_val[:proc].call(c, config[opt_key])
288
+ else
289
+ # Older single-argument proc.
290
+ opt_val[:proc].call(c)
291
+ end
292
+ else
293
+ # No proc.
294
+ c
295
+ end
285
296
  puts opts if opt_val[:show_options]
286
297
  exit opt_val[:exit] if opt_val[:exit]
287
298
  end
@@ -1,5 +1,5 @@
1
1
  module Mixlib
2
2
  module CLI
3
- VERSION = "1.6.0"
3
+ VERSION = "1.7.0"
4
4
  end
5
5
  end
@@ -149,6 +149,16 @@ describe Mixlib::CLI do
149
149
  @cli.config[:number].should == 4
150
150
  end
151
151
 
152
+ it "should pass the existing value to two-argument procs" do
153
+ TestCLI.option(:number,
154
+ :short => "-n NUMBER",
155
+ :proc => Proc.new { |value, existing| existing ||= []; existing << value; existing }
156
+ )
157
+ @cli = TestCLI.new
158
+ @cli.parse_options([ "-n", "2", "-n", "3" ])
159
+ @cli.config[:number].should == %w{2 3}
160
+ end
161
+
152
162
  it "should set the corresponding config value to true for boolean arguments" do
153
163
  TestCLI.option(:i_am_boolean, :short => "-i", :boolean => true)
154
164
  @cli = TestCLI.new
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mixlib-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.0
4
+ version: 1.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chef Software, Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-05 00:00:00.000000000 Z
11
+ date: 2016-07-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake