cri 2.15.7 → 2.15.8

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
  SHA256:
3
- metadata.gz: 961c45fae4395d1aad6d4f3d79ccf4b00c32bbd38f816d52df500aea7c782da5
4
- data.tar.gz: 7917db80f32845b87f5cc6942623a1ee34e5d83058cc526100afc07ea412b246
3
+ metadata.gz: 8133dfa33226ec959daeea2060f7efc15672e642d6a9afb8c19d9e3fabd550ce
4
+ data.tar.gz: 5c2c3afb7da1a9ad6adff22b136cd0cea144bb8b8e451bf0b3f50849bac10c90
5
5
  SHA512:
6
- metadata.gz: 48b820bcb56c95e6ff4594db88a814c72b5c10868e971a03236d47d4826af789228e9f38e6b7d926450bbb0700aac84d575b4cd613ad5a20f8adfcfa5f220606
7
- data.tar.gz: f84359f5f263d1ab38400a8b4667e8b47c2cf0b9a8ef883e8896e7c86a39b5ecc874e146f215a855c116d1863e68e62f29164c50a61f99e00ec07938ca85aaee
6
+ metadata.gz: 4ce23dee547462ed7d5a2f5618250019f520663c0bcdd2ce4a83cdf4a69dbfebc90a22cc61368a512a250fe2960a0a452e8c40dc65cd71afdae6f249cfe3095b
7
+ data.tar.gz: a471a0036ced17f51a6acef3b9e04239c74cfca8a024b76bd97837c9fc19182739165412e31021d1371875cc6fcfcc55c71cdd5983e9c4208d2555160182e418
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cri (2.15.7)
4
+ cri (2.15.8)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -13,7 +13,7 @@ GEM
13
13
  term-ansicolor (~> 1.3)
14
14
  thor (>= 0.19.4, < 2.0)
15
15
  tins (~> 1.6)
16
- docile (1.3.1)
16
+ docile (1.3.2)
17
17
  jaro_winkler (1.5.2)
18
18
  json (2.2.0)
19
19
  m (1.5.1)
@@ -26,7 +26,7 @@ GEM
26
26
  ast (~> 2.4.0)
27
27
  rainbow (3.0.0)
28
28
  rake (12.3.2)
29
- rubocop (0.70.0)
29
+ rubocop (0.71.0)
30
30
  jaro_winkler (~> 1.5.1)
31
31
  parallel (~> 1.10)
32
32
  parser (>= 2.6)
@@ -42,7 +42,7 @@ GEM
42
42
  term-ansicolor (1.7.1)
43
43
  tins (~> 1.0)
44
44
  thor (0.20.3)
45
- tins (1.20.2)
45
+ tins (1.20.3)
46
46
  unicode-display_width (1.6.0)
47
47
  yard (0.9.19)
48
48
 
@@ -59,4 +59,4 @@ DEPENDENCIES
59
59
  yard
60
60
 
61
61
  BUNDLED WITH
62
- 2.0.1
62
+ 2.0.2
data/NEWS.md CHANGED
@@ -1,5 +1,58 @@
1
1
  # Cri News
2
2
 
3
+ ## 2.15.8
4
+
5
+ Fixes:
6
+
7
+ * Don’t explicitly set default values for options (#99)
8
+
9
+ This release reverts a backwards-incompatible change introduced in 2.15.7.
10
+
11
+ To illustrate this, compare the behavior of the following command in recent versions of Cri:
12
+
13
+ ```ruby
14
+ option :f, :force, 'use force', argument: :forbidden
15
+
16
+ run do |opts, args, cmd|
17
+ puts "Options = #{opts.inspect}"
18
+ puts "Force? #{opts[:force]}"
19
+ puts "Option given? #{opts.key?(:force)}"
20
+ end
21
+ ```
22
+
23
+ In Cri 2.15.6, the default is not set in the options hash, so the value is `nil` and `#key?` returns false:
24
+
25
+ ```sh
26
+ % ./run
27
+ Options = {}
28
+ Force? nil
29
+ Option given? false
30
+ ```
31
+
32
+ This behavior was inconsistent with what was documented: flag options were (and still are) documented to default to `false` rather than `nil`.
33
+
34
+ In Cri 2.15.7, the default value is `false`, and explicitly set in the options hash (`#key?` returns `true`):
35
+
36
+ ```sh
37
+ % ./run
38
+ Options = {:force=>false}
39
+ Force? false
40
+ Option given? true
41
+ ```
42
+
43
+ This change made it impossible to detect options that were not explicitly specified, because the behavior of `#key?` also changed.
44
+
45
+ In Cri 2.15.8, the default value is also `false` (as in 2.15.7), but not explicitly set in the options hash (`#key?` returns `false`, as in 2.15.6):
46
+
47
+ ```sh
48
+ % ./run
49
+ Options = {}
50
+ Force? false
51
+ Option given? false
52
+ ```
53
+
54
+ This backwards-incompatible change was not intentional. To fix issue #94, a change in behavior was needed, but this change also affected other, previously-undefined behavior. The new behavior in 2.15.8 should fix the bug fixed in 2.15.7 (#94, #96), without causing the problems introduced in that version.
55
+
3
56
  ## 2.15.7
4
57
 
5
58
  Fixes:
data/README.md CHANGED
@@ -267,6 +267,33 @@ OPTIONS
267
267
  -a --animal[=<value>] add animal (default: giraffe)
268
268
  ```
269
269
 
270
+ If the option is not given on the command line, the `options` hash will not have key for this option, but will still have a default value:
271
+
272
+ ```ruby
273
+ option :a, :animal, 'add animal', default: 'giraffe', argument: :required
274
+
275
+ run do |opts, args, cmd|
276
+ puts "Animal = #{opts[:animal]}"
277
+ puts "Option given? #{opts.key?(:animal)}"
278
+ end
279
+ ```
280
+
281
+ ```sh
282
+ % ./run --animal=donkey
283
+ Animal = donkey
284
+ Option given? true
285
+
286
+ % ./run --animal=giraffe
287
+ Animal = giraffe
288
+ Option given? true
289
+
290
+ % ./run
291
+ Animal = giraffe
292
+ Option given? false
293
+ ```
294
+
295
+ This can be useful to distinguish between an explicitly-passed-in value and a default value. In the example above, the `animal` option is set to `giraffe` in the second and third cases, but it is possible to detect whether the value is a default or not.
296
+
270
297
  #### Multivalued options (`multiple:`)
271
298
 
272
299
  The `:multiple` parameter allows an option to be specified more than once on the command line. When set to `true`, multiple option valus are accepted, and the option values will be stored in an array.
@@ -345,16 +345,7 @@ module Cri
345
345
  handle_errors_while { parser.run }
346
346
  local_opts = parser.options
347
347
  global_opts = parent_opts.merge(parser.options)
348
-
349
- # Set defaults
350
- all_opt_defns.each do |opt_defn|
351
- key = (opt_defn.long || opt_defn.short).to_sym
352
-
353
- next if opt_defn.default.nil?
354
- next if global_opts.key?(key)
355
-
356
- global_opts[key] = opt_defn.default
357
- end
348
+ global_opts = add_defaults(global_opts)
358
349
 
359
350
  # Handle options
360
351
  handle_options(local_opts)
@@ -442,5 +433,23 @@ module Cri
442
433
  warn "#{name}: #{e.message}"
443
434
  raise CriExitException.new(is_error: true)
444
435
  end
436
+
437
+ def add_defaults(options)
438
+ all_opt_defns_by_key =
439
+ all_opt_defns.each_with_object({}) do |opt_defn, hash|
440
+ key = (opt_defn.long || opt_defn.short).to_sym
441
+ hash[key] = opt_defn
442
+ end
443
+
444
+ new_options = Hash.new do |hash, key|
445
+ hash.fetch(key) { all_opt_defns_by_key[key]&.default }
446
+ end
447
+
448
+ options.each do |key, value|
449
+ new_options[key] = value
450
+ end
451
+
452
+ new_options
453
+ end
445
454
  end
446
455
  end
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Cri
4
4
  # The current Cri version.
5
- VERSION = '2.15.7'
5
+ VERSION = '2.15.8'
6
6
  end
@@ -126,7 +126,7 @@ module Cri
126
126
  simple_cmd.run(%w[])
127
127
  end
128
128
 
129
- assert_equal ['Awesome moo!', '', 'ddd=false,eee=false'], lines(out)
129
+ assert_equal ['Awesome moo!', '', ''], lines(out)
130
130
  assert_equal [], lines(err)
131
131
  end
132
132
 
@@ -135,7 +135,7 @@ module Cri
135
135
  simple_cmd.run(%w[abc xyz])
136
136
  end
137
137
 
138
- assert_equal ['Awesome moo!', 'abc,xyz', 'ddd=false,eee=false'], lines(out)
138
+ assert_equal ['Awesome moo!', 'abc,xyz', ''], lines(out)
139
139
  assert_equal [], lines(err)
140
140
  end
141
141
 
@@ -144,7 +144,7 @@ module Cri
144
144
  simple_cmd.run(%w[-c -b x])
145
145
  end
146
146
 
147
- assert_equal ['Awesome moo!', '', 'bbb=x,ccc=true,ddd=false,eee=false'], lines(out)
147
+ assert_equal ['Awesome moo!', '', 'bbb=x,ccc=true'], lines(out)
148
148
  assert_equal [], lines(err)
149
149
  end
150
150
 
@@ -216,7 +216,7 @@ module Cri
216
216
  simple_cmd.run(%w[-a 123])
217
217
  end
218
218
 
219
- assert_equal ['moo:123', 'Awesome moo!', '', 'aaa=123,ddd=false,eee=false'], lines(out)
219
+ assert_equal ['moo:123', 'Awesome moo!', '', 'aaa=123'], lines(out)
220
220
  assert_equal [], lines(err)
221
221
  end
222
222
 
@@ -246,7 +246,7 @@ module Cri
246
246
  nested_cmd.run(%w[sub])
247
247
  end
248
248
 
249
- assert_equal ['Sub-awesome!', '', 'ddd=false,eee=false,ppp=false,qqq=false'], lines(out)
249
+ assert_equal ['Sub-awesome!', '', ''], lines(out)
250
250
  assert_equal [], lines(err)
251
251
  end
252
252
 
@@ -297,7 +297,7 @@ module Cri
297
297
  nested_cmd.run(%w[sup])
298
298
  end
299
299
 
300
- assert_equal ['Sub-awesome!', '', 'ddd=false,eee=false,ppp=false,qqq=false'], lines(out)
300
+ assert_equal ['Sub-awesome!', '', ''], lines(out)
301
301
  assert_equal [], lines(err)
302
302
  end
303
303
 
@@ -306,7 +306,7 @@ module Cri
306
306
  nested_cmd.run(%w[-a 666 sub])
307
307
  end
308
308
 
309
- assert_equal ['super:666', 'Sub-awesome!', '', 'aaa=666,ddd=false,eee=false,ppp=false,qqq=false'], lines(out)
309
+ assert_equal ['super:666', 'Sub-awesome!', '', 'aaa=666'], lines(out)
310
310
  assert_equal [], lines(err)
311
311
  end
312
312
 
@@ -902,14 +902,14 @@ module Cri
902
902
  option :f, :force2, 'push with force', argument: :forbidden
903
903
 
904
904
  run do |opts, _args, _cmd|
905
- puts "Force? #{opts[:force2].inspect}!"
905
+ puts "Force? #{opts[:force2].inspect}! Key present? #{opts.key?(:force2)}!"
906
906
  end
907
907
  end
908
908
 
909
909
  out, err = capture_io_while do
910
910
  cmd.run(%w[])
911
911
  end
912
- assert_equal ['Force? false!'], lines(out)
912
+ assert_equal ['Force? false! Key present? false!'], lines(out)
913
913
  assert_equal [], lines(err)
914
914
  end
915
915
 
@@ -919,14 +919,14 @@ module Cri
919
919
  option :a, :animal, 'specify animal', argument: :required, default: 'cow'
920
920
 
921
921
  run do |opts, _args, _cmd|
922
- puts "Animal = #{opts[:animal]}"
922
+ puts "Animal = #{opts[:animal]}! Key present? #{opts.key?(:animal)}!"
923
923
  end
924
924
  end
925
925
 
926
926
  out, err = capture_io_while do
927
927
  cmd.run(%w[])
928
928
  end
929
- assert_equal ['Animal = cow'], lines(out)
929
+ assert_equal ['Animal = cow! Key present? false!'], lines(out)
930
930
  assert_equal [], lines(err)
931
931
  end
932
932
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cri
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.15.7
4
+ version: 2.15.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Denis Defreyne
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-05-30 00:00:00.000000000 Z
11
+ date: 2019-06-14 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Cri allows building easy-to-use command-line interfaces with support
14
14
  for subcommands.
@@ -74,7 +74,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  requirements: []
77
- rubygems_version: 3.0.3
77
+ rubygems_version: 3.0.4
78
78
  signing_key:
79
79
  specification_version: 4
80
80
  summary: a library for building easy-to-use command-line tools