benry-cmdopt 2.0.2 → 2.2.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
  SHA256:
3
- metadata.gz: 1c4c465878a37b15c65090a251e576059ac389d2a3457379980e8bb353e43a97
4
- data.tar.gz: e0607fa34db598eb81014b7ed63bebe82985ad20a9a311e7be6b0c6c52f01a88
3
+ metadata.gz: 9308d0182f3f4a17d45f3b7a1f212a4f5f2112f4084d725b2de05271a908bb1d
4
+ data.tar.gz: f9b8e9066b9857d2693382f03bcbeacdd040695287d426d8ef8c28cf242f1cd1
5
5
  SHA512:
6
- metadata.gz: 01cc7b1487d89b9777478064f068c31b847038da6fda2841b9b59c0ee55fc9d62a4d3dac7eae5964c9b25fd0da5e52459c27cbb8eac0412293c0b4de8fb910d9
7
- data.tar.gz: 934952f9cc686d6014c69034b7aa5810341266b627f5f22719da543baf9f38267cab4214a0aeae8315bb601bc72f96597d976896977c1151fff50c37fe8dce59
6
+ metadata.gz: e231075a8a9fdd99a0379390ebc1fae07c812f8229d1689e0b7f04b91d5c0c596122835dde000c3ba609681898c3048fa51d08232cd33d4b9df0bacbc22036c6
7
+ data.tar.gz: bcabe45f475efd7c95e989c9f7f2c9b61c65396b6373cbb0a68427ce10798a942c4af3cfd8ae66a34928c710b2cac24388d8848a6a1271ca40d3e9458a217898
data/CHANGES.md CHANGED
@@ -2,6 +2,21 @@ CHANGES
2
2
  =======
3
3
 
4
4
 
5
+ Release 2.2.0 (2023-10-28)
6
+ --------------------------
7
+
8
+ * [enhance] Define `SchemaItem#add_item()` which adds option item into the schema. This is for Benry-CmdApp framework.
9
+ * [change] (EXPERIMENTAL) Make `desc`, `detail`, `hidden`, `important`, `tag` attrubtes of `SchemaItem` object to be writable. This is for Benry-CmdApp framework.
10
+
11
+
12
+ Release 2.1.0 (2023-10-15)
13
+ --------------------------
14
+
15
+ * [enhance] Add `hidden: true` keyword argument to `Benry::Schema#add()` and `Benry::Facade#add()`. This keyword argument makes the option as hidden option.
16
+ * [change] Option which name stars with '_' is now not regarded as hidden option. Use `hidden: true` instead.
17
+ * [enhance] Add `important: (true|false)` keyword argument to `Benry::Schema#add()` and `Benry::Facade#add()`. This keyword argument makes help message of the option printed in decorated format.
18
+
19
+
5
20
  Release 2.0.2 (2023-10-12)
6
21
  --------------------------
7
22
 
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Benry-CmdOpt
2
2
 
3
- ($Release: 2.0.2 $)
3
+ ($Release: 2.2.0 $)
4
4
 
5
5
 
6
6
 
@@ -38,6 +38,7 @@ Benry-CmdOpt requires Ruby >= 2.3.
38
38
  * [Global Options with Sub-Commands](#global-options-with-sub-commands)
39
39
  * [Detailed Description of Option](#detailed-description-of-option)
40
40
  * [Option Tag](#option-tag)
41
+ * [Important Options](#important-options)
41
42
  * [Not Supported](#not-supported)
42
43
  * [Internal Classes](#internal-classes)
43
44
  * [License and Copyright](#license-and-copyright)
@@ -470,22 +471,20 @@ p options #=> {:lib=>["foo", "bar", "baz"]}
470
471
 
471
472
  Benry-CmdOpt regards the following options as hidden.
472
473
 
473
- * Key name starts with `_` (for example `:_debug`).
474
+ * Keyword argument `hidden: true` is passed to `.add()` method.
474
475
  * Or description is nil.
475
476
 
476
- The former is better than the latter, because even hidden option should have its own description.
477
-
478
- These hidden options are not included in help message.
477
+ Hidden options are not included in help message.
479
478
 
480
479
  ```ruby
481
480
  require 'benry/cmdopt'
482
481
  cmdopt = Benry::CmdOpt.new
483
- cmdopt.add(:help , '-h', "help message")
484
- cmdopt.add(:debug, '-D', nil) # hidden (because description is nil)
485
- cmdopt.add(:_log , '-L', "logging") # hidden (because key starts with '_')
482
+ cmdopt.add(:help , '-h', "help message")
483
+ cmdopt.add(:logging, '-L', "logging", hidden: true) # hidden
484
+ cmdopt.add(:debug , '-D', nil) # hidden (desc is nil)
486
485
  puts cmdopt.to_s()
487
486
 
488
- ### output (neither '-D' nor '-L' is shown because hidden options)
487
+ ### output (neither '-L' nor '-D' is shown because hidden options)
489
488
  # -h : help message
490
489
  ```
491
490
 
@@ -497,8 +496,8 @@ puts cmdopt.to_s(all: true) # or: cmdopt.to_s(nil, all: true)
497
496
 
498
497
  ### output
499
498
  # -h : help message
500
- # -D :
501
499
  # -L : logging
500
+ # -D :
502
501
  ```
503
502
 
504
503
 
@@ -613,11 +612,37 @@ end
613
612
  ```
614
613
 
615
614
 
615
+ ### Important Options
616
+
617
+ You can specify that the option is important or not.
618
+ Pass `important: true` or `important: false` keyword argument to `#add()` method of `Benry::CmdOpt` or `Benry::CmdOpt::Schema` object.
619
+
620
+ The help message of options is decorated according to value of `important:` keyword argument.
621
+
622
+ * Printed in bold font when `important: true` specified to the option.
623
+ * Printed in gray color when `important: false` specified to the option.
624
+
625
+ ```ruby
626
+ require 'benry/cmdopt'
627
+
628
+ cmdopt = Benry::CmdOpt.new()
629
+ cmdopt.add(:help , "-h", "help message")
630
+ cmdopt.add(:verbose, "-v", "verbose mode", important: true) # !!!
631
+ cmdopt.add(:debug , "-D", "debug mode" , important: false) # !!!
632
+ puts cmdopt.option_help()
633
+
634
+ ## output:
635
+ # -h : help message
636
+ # -v : verbose mode # bold font
637
+ # -D : debug mode # gray color
638
+ ```
639
+
640
+
616
641
  ### Not Supported
617
642
 
618
- * default value
643
+ * default value when the option not specified in command-line
619
644
  * `--no-xxx` style option
620
- * bash/zsh completion
645
+ * bash/zsh completion (may be supported in the future)
621
646
  * I18N of error message (may be supported in the future)
622
647
 
623
648
 
data/benry-cmdopt.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "benry-cmdopt"
5
- spec.version = "$Release: 2.0.2 $".split()[1]
5
+ spec.version = "$Release: 2.2.0 $".split()[1]
6
6
  spec.author = "kwatch"
7
7
  spec.email = "kwatch@gmail.com"
8
8
  spec.platform = Gem::Platform::RUBY
@@ -21,7 +21,7 @@
21
21
  <ul class="nav">
22
22
  </ul>
23
23
  </nav>
24
- <p>($Release: 2.0.2 $)</p>
24
+ <p>($Release: 2.2.0 $)</p>
25
25
  <section class="section" id="whats-this">
26
26
  <h2>What's This?</h2>
27
27
  <p>Benry-CmdOpt is a command option parser library, like <code>optparse.rb</code>
@@ -53,6 +53,7 @@ and easy to understahnd.</p>
53
53
  <li><a href="#global-options-with-sub-commands">Global Options with Sub-Commands</a></li>
54
54
  <li><a href="#detailed-description-of-option">Detailed Description of Option</a></li>
55
55
  <li><a href="#option-tag">Option Tag</a></li>
56
+ <li><a href="#important-options">Important Options</a></li>
56
57
  <li><a href="#not-supported">Not Supported</a></li>
57
58
  </ul></li>
58
59
  <li><a href="#internal-classes">Internal Classes</a></li>
@@ -462,20 +463,19 @@ p options #=&gt; <strong>{:lib=&gt;["foo", "bar", "baz"]}</strong>
462
463
  <h3>Hidden Option</h3>
463
464
  <p>Benry-CmdOpt regards the following options as hidden.</p>
464
465
  <ul>
465
- <li>Key name starts with <code>_</code> (for example <code>:_debug</code>).</li>
466
+ <li>Keyword argument <code>hidden: true</code> is passed to <code>.add()</code> method.</li>
466
467
  <li>Or description is nil.</li>
467
468
  </ul>
468
- <p>The former is better than the latter, because even hidden option should have its own description.</p>
469
- <p>These hidden options are not included in help message.</p>
469
+ <p>Hidden options are not included in help message.</p>
470
470
  <pre class="language-ruby">
471
471
  require 'benry/cmdopt'
472
472
  cmdopt = Benry::CmdOpt.new
473
- cmdopt.add(:help , '-h', "help message")
474
- cmdopt.add(:debug, '-D', <strong>nil</strong>) # hidden (because description is nil)
475
- cmdopt.add(<strong>:_log</strong> , '-L', "logging") # hidden (because key starts with '_')
473
+ cmdopt.add(:help , '-h', "help message")
474
+ cmdopt.add(:logging, '-L', "logging", <strong>hidden: true</strong>) # hidden
475
+ cmdopt.add(:debug , '-D', <strong>nil</strong>) # hidden (desc is nil)
476
476
  puts cmdopt.to_s()
477
477
 
478
- ### output (neither '-D' nor '-L' is shown because hidden options)
478
+ ### output (neither '-L' nor '-D' is shown because hidden options)
479
479
  # -h : help message
480
480
  </pre>
481
481
  <p>To show all options including hidden ones, add <code>all: true</code> to <code>cmdopt.to_s()</code>.</p>
@@ -485,8 +485,8 @@ puts cmdopt.to_s(<strong>all: true</strong>) # or: cmdopt.to_s(nil, all: true)
485
485
 
486
486
  ### output
487
487
  # -h : help message
488
- # <strong>-D :</strong>
489
488
  # <strong>-L : logging</strong>
489
+ # <strong>-D : </strong>
490
490
  </pre>
491
491
  </section>
492
492
  <section class="subsection" id="global-options-with-sub-commands">
@@ -591,12 +591,36 @@ end
591
591
  #version: <strong>tag=nil</strong>
592
592
  </pre>
593
593
  </section>
594
+ <section class="subsection" id="important-options">
595
+ <h3>Important Options</h3>
596
+ <p>You can specify that the option is important or not.
597
+ Pass <code>important: true</code> or <code>important: false</code> keyword argument to <code>#add()</code> method of <code>Benry::CmdOpt</code> or <code>Benry::CmdOpt::Schema</code> object.</p>
598
+ <p>The help message of options is decorated according to value of <code>important:</code> keyword argument.</p>
599
+ <ul>
600
+ <li>Printed in bold font when <code>important: true</code> specified to the option.</li>
601
+ <li>Printed in gray color when <code>important: false</code> specified to the option.</li>
602
+ </ul>
603
+ <pre class="language-ruby">
604
+ require 'benry/cmdopt'
605
+
606
+ cmdopt = Benry::CmdOpt.new()
607
+ cmdopt.add(:help , "-h", "help message")
608
+ cmdopt.add(:verbose, "-v", "verbose mode", <strong>important: true</strong>) # !!!
609
+ cmdopt.add(:debug , "-D", "debug mode" , <strong>important: false</strong>) # !!!
610
+ puts cmdopt.option_help()
611
+
612
+ ## output:
613
+ # -h : help message
614
+ # -v : verbose mode # bold font
615
+ # -D : debug mode # gray color
616
+ </pre>
617
+ </section>
594
618
  <section class="subsection" id="not-supported">
595
619
  <h3>Not Supported</h3>
596
620
  <ul>
597
- <li>default value</li>
621
+ <li>default value when the option not specified in command-line</li>
598
622
  <li><code>--no-xxx</code> style option</li>
599
- <li>bash/zsh completion</li>
623
+ <li>bash/zsh completion (may be supported in the future)</li>
600
624
  <li>I18N of error message (may be supported in the future)</li>
601
625
  </ul>
602
626
  </section>
data/lib/benry/cmdopt.rb CHANGED
@@ -2,7 +2,7 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  ###
5
- ### $Release: 2.0.2 $
5
+ ### $Release: 2.2.0 $
6
6
  ### $Copyright: copyright(c) 2021 kwatch@gmail.com $
7
7
  ### $License: MIT License $
8
8
  ###
@@ -23,7 +23,7 @@ end
23
23
  module Benry::CmdOpt
24
24
 
25
25
 
26
- VERSION = '$Release: 2.0.2 $'.split()[1]
26
+ VERSION = '$Release: 2.2.0 $'.split()[1]
27
27
 
28
28
 
29
29
  def self.new()
@@ -40,11 +40,11 @@ module Benry::CmdOpt
40
40
 
41
41
  attr_reader :schema
42
42
 
43
- def add(key, optdef, desc, *rest, type: nil, rexp: nil, pattern: nil, enum: nil, range: nil, value: nil, detail: nil, tag: nil, &callback)
43
+ def add(key, optdef, desc, *rest, type: nil, rexp: nil, pattern: nil, enum: nil, range: nil, value: nil, detail: nil, hidden: nil, important: nil, tag: nil, &callback)
44
44
  rexp ||= pattern # for backward compatibility
45
45
  #; [!vmb3r] defines command option.
46
46
  #; [!71cvg] type, rexp, enum, and range are can be passed as positional args as well as keyword args.
47
- @schema.add(key, optdef, desc, *rest, type: type, rexp: rexp, enum: enum, range: range, value: value, detail: detail, tag: tag, &callback)
47
+ @schema.add(key, optdef, desc, *rest, type: type, rexp: rexp, enum: enum, range: range, value: value, detail: detail, hidden: hidden, important: important, tag: tag, &callback)
48
48
  #; [!tu4k3] returns self.
49
49
  self
50
50
  end
@@ -103,7 +103,7 @@ module Benry::CmdOpt
103
103
  self
104
104
  end
105
105
 
106
- def add(key, optdef, desc, *rest, type: nil, rexp: nil, pattern: nil, enum: nil, range: nil, value: nil, detail: nil, tag: nil, &callback)
106
+ def add(key, optdef, desc, *rest, type: nil, rexp: nil, pattern: nil, enum: nil, range: nil, value: nil, detail: nil, hidden: nil, important: nil, tag: nil, &callback)
107
107
  rexp ||= pattern # for backward compatibility
108
108
  #; [!kuhf9] type, rexp, enum, and range are can be passed as positional args as well as keyword args.
109
109
  rest.each do |x|
@@ -137,11 +137,17 @@ module Benry::CmdOpt
137
137
  end
138
138
  #; [!yht0v] keeps command option definitions.
139
139
  item = SchemaItem.new(key, optdef, desc, short, long, param, required,
140
- type: type, rexp: rexp, enum: enum, range: range, value: value, detail: detail, tag: tag, &callback)
140
+ type: type, rexp: rexp, enum: enum, range: range, value: value, detail: detail, hidden: hidden, important: important, tag: tag, &callback)
141
141
  @items << item
142
142
  item
143
143
  end
144
144
 
145
+ def add_item(item)
146
+ #; [!a693h] adds option item into current schema.
147
+ @items << item
148
+ self
149
+ end
150
+
145
151
  def option_help(width_or_format=nil, all: false)
146
152
  #; [!0aq0i] can take integer as width.
147
153
  #; [!pcsah] can take format string.
@@ -157,10 +163,16 @@ module Benry::CmdOpt
157
163
  #; [!to1th] includes all option help when `all` is true.
158
164
  #; [!a4qe4] option should not be hidden if description is empty string.
159
165
  sb = []
160
- width = nil; indent = nil
161
- each_option_and_desc(all: all) do |opt, desc, detail|
162
- sb << format % [opt, desc || ""] << "\n"
166
+ width = nil; indent = nil; color_p = $stdout.tty?
167
+ @items.each do |item|
168
+ next if ! all && item.hidden?
169
+ #; [!jrwb6] decorates help message according to `important:` value of option.
170
+ #; [!9nlfb] not decorate help message when stdout is not a tty.
171
+ s = format % [item.optdef, item.desc || ""]
172
+ s = _decorate_str(s, item.important?) if color_p
173
+ sb << s << "\n"
163
174
  #; [!848rm] supports multi-lines help message.
175
+ detail = item.detail
164
176
  if detail
165
177
  width ||= (format % ['', '']).length
166
178
  indent ||= ' ' * width
@@ -276,12 +288,20 @@ module Benry::CmdOpt
276
288
  return short_p ? 8 : long_p ? 20 : 14
277
289
  end
278
290
 
291
+ def _decorate_str(str, important)
292
+ case important
293
+ when true ; return "\e[1m#{str}\e[0m" # bold
294
+ when false ; return "\e[2m#{str}\e[0m" # gray
295
+ else ; return str
296
+ end
297
+ end
298
+
279
299
  end
280
300
 
281
301
 
282
302
  class SchemaItem # avoid Struct
283
303
 
284
- def initialize(key, optdef, desc, short, long, param, required, type: nil, rexp: nil, pattern: nil, enum: nil, range: nil, detail: nil, value: nil, tag: nil, &callback)
304
+ def initialize(key, optdef, desc, short, long, param, required, type: nil, rexp: nil, pattern: nil, enum: nil, range: nil, detail: nil, value: nil, hidden: nil, important: nil, tag: nil, &callback)
285
305
  rexp ||= pattern # for backward compatibility
286
306
  _init_validation(param, required, type, rexp, enum, range, value)
287
307
  @key = key unless nil == key
@@ -297,6 +317,8 @@ module Benry::CmdOpt
297
317
  @range = range unless nil == range
298
318
  @detail = detail unless nil == detail
299
319
  @value = value unless nil == value
320
+ @hidden = hidden unless nil == hidden
321
+ @important = important unless nil == important
300
322
  @tag = tag unless nil == tag
301
323
  @callback = callback unless nil == callback
302
324
  #; [!nn4cp] freezes enum object.
@@ -304,6 +326,7 @@ module Benry::CmdOpt
304
326
  end
305
327
 
306
328
  attr_reader :key, :optdef, :desc, :short, :long, :param, :type, :rexp, :enum, :range, :detail, :value, :tag, :callback
329
+ attr_writer :desc, :detail, :hidden, :important, :tag # !!experimental!!
307
330
  alias pattern rexp # for backward compatibility
308
331
  alias help desc # for backward compatibility
309
332
 
@@ -324,10 +347,18 @@ module Benry::CmdOpt
324
347
  end
325
348
 
326
349
  def hidden?()
350
+ #; [!no6ov] returns true if @hidden is true.
351
+ #; [!ej8ot] returns false if @hidden is false.
352
+ return @hidden if @hidden != nil
327
353
  #; [!h0uxs] returns true if desc is nil.
328
- #; [!su00g] returns true if key starts with '_'.
329
354
  #; [!28vzx] returns false if else.
330
- return @desc == nil || @key.to_s.start_with?('_')
355
+ return @desc == nil
356
+ end
357
+
358
+ def important?()
359
+ #; [!ua8kt] returns true/false if `important:` kwarg passed to constructor.
360
+ #; [!hz9sx] returns nil if `important:` kwarg not passed to constructor.
361
+ return @important
331
362
  end
332
363
 
333
364
  def validate_and_convert(val, optdict)
data/test/cmdopt_test.rb CHANGED
@@ -256,6 +256,19 @@ Oktest.scope do
256
256
  end
257
257
 
258
258
 
259
+ topic '#add_item()' do
260
+
261
+ spec "[!a693h] adds option item into current schema." do
262
+ item = Benry::CmdOpt::SchemaItem.new(:quiet, "-q", "quiet", "q", nil, nil, false)
263
+ sc = Benry::CmdOpt::Schema.new
264
+ sc.add_item(item)
265
+ ok {sc.to_s} == <<"END"
266
+ -q : quiet
267
+ END
268
+ end
269
+
270
+ end
271
+
259
272
  topic '#option_help()' do
260
273
 
261
274
  before do
@@ -342,13 +355,49 @@ END
342
355
  spec "[!a4qe4] option should not be hidden if description is empty string." do
343
356
  sc = Benry::CmdOpt::Schema.new
344
357
  sc.add(:debug , "-D", nil) # hidden
345
- sc.add(:_trace, "-T", "trace") # hidden
358
+ sc.add(:trace, "-T", "trace", hidden: true) # hidden
346
359
  sc.add(:what , "-W", "") # NOT hidden!
347
360
  ok {sc.option_help()} == <<END
348
361
  -W :
349
362
  END
350
363
  end
351
364
 
365
+ fixture :schema_with_importance do
366
+ sc = Benry::CmdOpt::Schema.new
367
+ sc.add(:help , "-h, --help" , "help message")
368
+ sc.add(:trace , "-T, --trace", "trace" , important: true)
369
+ sc.add(:debug , "-D, --debug", "debug mode" , important: false)
370
+ sc.add(:quiet , "-q, --quiet", "quiet mode")
371
+ sc
372
+ end
373
+
374
+ spec "[!jrwb6] decorates help message according to `important:` value of option." do
375
+ |schema_with_importance|
376
+ sc = schema_with_importance
377
+ ok {sc.option_help()} == <<END
378
+ -h, --help : help message
379
+ \e[1m -T, --trace : trace\e[0m
380
+ \e[2m -D, --debug : debug mode\e[0m
381
+ -q, --quiet : quiet mode
382
+ END
383
+ end
384
+
385
+ spec "[!9nlfb] not decorate help message when stdout is not a tty." do
386
+ |schema_with_importance|
387
+ sc = schema_with_importance
388
+ output = nil
389
+ capture_sio() {
390
+ ok {$stdout}.NOT.tty?
391
+ output = sc.option_help()
392
+ }
393
+ ok {output} == <<END
394
+ -h, --help : help message
395
+ -T, --trace : trace
396
+ -D, --debug : debug mode
397
+ -q, --quiet : quiet mode
398
+ END
399
+ end
400
+
352
401
  end
353
402
 
354
403
 
@@ -445,7 +494,7 @@ END
445
494
  sc.add(:help, "-h, --help", "show help message")
446
495
  sc.add(:version, " --version", "print version")
447
496
  sc.add(:debug , "-d, --debug" , nil) # hidden
448
- sc.add(:_DEBUG , "-D, --DEBUG" , "debug mode") # hidden
497
+ sc.add(:DEBUG , "-D, --DEBUG" , "debug mode", hidden: true) # hidden
449
498
  @schema = sc
450
499
  end
451
500
 
@@ -532,7 +581,7 @@ END
532
581
  spec "[!icvm1] ignores hidden items if 'all: false' kwarg specified." do
533
582
  schema = Benry::CmdOpt::Schema.new
534
583
  schema.add(:debug , "-D", nil)
535
- schema.add(:_trace, "-T", "trace")
584
+ schema.add(:trace, "-T", "trace", hidden: true)
536
585
  ok {schema.empty?()} == false
537
586
  ok {schema.empty?(all: true)} == false
538
587
  ok {schema.empty?(all: false)} == true
@@ -898,15 +947,19 @@ END
898
947
 
899
948
  topic '#hidden?()' do
900
949
 
901
- spec "[!h0uxs] returns true if desc is nil." do
902
- desc = nil
903
- item = Benry::CmdOpt::SchemaItem.new(:debug, "-D", desc, "D", nil, nil, nil)
950
+ spec "[!no6ov] returns true if @hidden is true." do
951
+ item = Benry::CmdOpt::SchemaItem.new(:debug, "-D", "debug mode", "D", nil, nil, nil, hidden: true)
904
952
  ok {item.hidden?} == true
905
953
  end
906
954
 
907
- spec "[!su00g] returns true if key starts with '_'." do
908
- desc = "debug mode"
909
- item = Benry::CmdOpt::SchemaItem.new(:_debug, "-D", desc, "D", nil, nil, nil)
955
+ spec "[!ej8ot] returns false if @hidden is false." do
956
+ item = Benry::CmdOpt::SchemaItem.new(:debug, "-D", "debug mode", "D", nil, nil, nil, hidden: false)
957
+ ok {item.hidden?} == false
958
+ end
959
+
960
+ spec "[!h0uxs] returns true if desc is nil." do
961
+ desc = nil
962
+ item = Benry::CmdOpt::SchemaItem.new(:debug, "-D", desc, "D", nil, nil, nil)
910
963
  ok {item.hidden?} == true
911
964
  end
912
965
 
@@ -919,6 +972,23 @@ END
919
972
  end
920
973
 
921
974
 
975
+ topic '#important?()' do
976
+
977
+ spec "[!ua8kt] returns true/false if `important:` kwarg passed to constructor." do
978
+ item1 = Benry::CmdOpt::SchemaItem.new(:debug, "-D", "debug mode", "D", nil, nil, nil, important: true)
979
+ ok {item1.important?} == true
980
+ item2 = Benry::CmdOpt::SchemaItem.new(:debug, "-D", "debug mode", "D", nil, nil, nil, important: false)
981
+ ok {item2.important?} == false
982
+ end
983
+
984
+ spec "[!hz9sx] returns nil if `important:` kwarg not passed to constructor." do
985
+ item3 = Benry::CmdOpt::SchemaItem.new(:debug, "-D", "debug mode", "D", nil, nil, nil)
986
+ ok {item3.important?} == nil
987
+ end
988
+
989
+ end
990
+
991
+
922
992
  topic '#validate_and_convert()' do
923
993
 
924
994
  def new_item(key, optstr, desc, short, long, param, required,
@@ -1520,7 +1590,7 @@ END
1520
1590
  @cmdopt.add(:help , "-h, --help" , "show help message")
1521
1591
  @cmdopt.add(:version, " --version" , "print version")
1522
1592
  @cmdopt.add(:debug , "-D" , nil) # hidden option
1523
- @cmdopt.add(:_trace , "-T" , "trace") # hidden option
1593
+ @cmdopt.add(:trace , "-T" , "trace", hidden: true) # hidden option
1524
1594
  end
1525
1595
 
1526
1596
  spec "[!bw9qx] yields each option definition string and help message." do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: benry-cmdopt
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.2
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - kwatch
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-10-12 00:00:00.000000000 Z
11
+ date: 2023-10-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oktest