benry-cmdapp 0.1.0 → 0.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: f4cae92d627c080f4c25ca3cb607871ecd45ae815a7af19252bbeac7c48def32
4
- data.tar.gz: 32f9ac8fa0c8f3659e286553536b96ee7f21d8ecb706ddee36901ebd483e3dad
3
+ metadata.gz: 8b0a5dd7e1572d8202763acc806cd7299f40b5b4696f9a59c255afca03608f24
4
+ data.tar.gz: 56739d3a911e3027c8e7d632355db38531c64cca519b51ac4f8c2857d4c41b64
5
5
  SHA512:
6
- metadata.gz: ac4a3ac4ddec5f058fc4f0f7d7b19f18c5bed5c4a242b85eb2f2578c481c57807958c1e957b9db2ed8048185547573754feca0c6694ba6c9a5987adbc816d132
7
- data.tar.gz: bffae3d01e9852d10cfeaef85eaf7c3d6e6538c15402620f4e0088bb6d26bfe9c303d257f9d1ccd551ab7eb4eb3c6f7928ef902673dac404b8076ef4c816ea23
6
+ metadata.gz: 3581a4d1ac62a2ce6143e648eee9fd30a364977aec7b25b9896ee8f659e9b544d7d7fd8f8cafaacd49bae001df8384fcc6f58914fc511f8d281c4456e5cbf284
7
+ data.tar.gz: 274ac6bbfc184243eedbc37911c9d41397ff5271f8bffbc7e363d6feaa63d292f09e51d83d7a95aa13c2ed35b9f102909b254f2a36b66e9e39bccddc64aee3cc
data/CHANGES.md CHANGED
@@ -2,6 +2,14 @@ CHANGES
2
2
  =======
3
3
 
4
4
 
5
+ Release 0.2.0 (2023-10-18)
6
+ --------------------------
7
+
8
+ * [change] Requires Benry-CmdOpt 2.1.0 or higher.
9
+ * [enhance] `@action.()` and `@option.()` supports `hidden: true` keyword argument.
10
+ * [change] Rename `#run_action!()` in Action class to `#run_action_anyway()`.
11
+
12
+
5
13
  Release 0.1.0 (2023-10-12)
6
14
  --------------------------
7
15
 
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Benry-CmdApp
2
2
 
3
- ($Release: 0.1.0 $)
3
+ ($Release: 0.2.0 $)
4
4
 
5
5
 
6
6
  ## What's This?
@@ -1181,7 +1181,8 @@ Actions:
1181
1181
 
1182
1182
  ### Private (Hidden) Action
1183
1183
 
1184
- * If action method is private, Benry::CmdApp regards that action as private.
1184
+ * If `hidden: true` keyword argument passed to `@action.()`,
1185
+ or action method is private, then Benry::CmdApp regards that action as private.
1185
1186
  * Private actions are hidden in help message.
1186
1187
  * Private actions are shown when `-a` or `--all` option enabled and specified.
1187
1188
 
@@ -1198,13 +1199,12 @@ class SampleAction < Benry::CmdApp::Action
1198
1199
  puts __method__
1199
1200
  end
1200
1201
 
1201
- @action.("test action #2")
1202
+ @action.("test action #2", hidden: true) # !!!!
1202
1203
  def test2()
1203
1204
  puts __method__
1204
1205
  end
1205
- private :test2 # !!!! private method !!!!
1206
1206
 
1207
- private # !!!! private method !!!!
1207
+ private # !!!!
1208
1208
 
1209
1209
  @action.("test action #3")
1210
1210
  def test3()
@@ -1258,7 +1258,7 @@ Actions:
1258
1258
 
1259
1259
  ### Private (Hidden) Option
1260
1260
 
1261
- * Options which name stars with `_` are treated as private option.
1261
+ * Options defined with `hidden: true` keyword argument are treated as private option.
1262
1262
  * Private options are hidden in help message of action.
1263
1263
  * Private options are shown when `-a` or `--all` option enabled and specified.
1264
1264
 
@@ -1272,9 +1272,9 @@ class SampleAction < Benry::CmdApp::Action
1272
1272
 
1273
1273
  @action.("test action")
1274
1274
  @option.(:verbose, "-v", "verbose mode")
1275
- @option.(:_debug , "-D", "debug mode") # !!!!
1276
- def test1(verbose: false, _debug: false)
1277
- puts "verbose=#{verbose}, _debug=#{_debug}"
1275
+ @option.(:debug , "-D", "debug mode", hidden: true) # !!!!
1276
+ def test1(verbose: false, debug: false)
1277
+ puts "verbose=#{verbose}, debug=#{_debug}"
1278
1278
  end
1279
1279
 
1280
1280
  end
data/benry-cmdapp.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "benry-cmdapp"
5
- spec.version = "$Release: 0.1.0 $".split()[1]
5
+ spec.version = "$Release: 0.2.0 $".split()[1]
6
6
  spec.author = "kwatch"
7
7
  spec.email = "kwatch@gmail.com"
8
8
  spec.platform = Gem::Platform::RUBY
@@ -21,9 +21,7 @@ END
21
21
  spec.files = Dir[
22
22
  "README.md", "MIT-LICENSE", "CHANGES.md",
23
23
  "#{spec.name}.gemspec",
24
- #"Rakefile.rb", "task/**/*.rb",,
25
- "lib/**/*.rb", "test/**/*.rb",
26
- #"bin/*", "examples/**/*",
24
+ "lib/**/*.rb", "test/**/*.rb", #"bin/*", "examples/**/*",
27
25
  "doc/*.html", "doc/css/*.css",
28
26
  ]
29
27
  #spec.executables = []
@@ -33,6 +31,6 @@ END
33
31
  #spec.extra_rdoc_files = ["README.md", "CHANGES.md"]
34
32
 
35
33
  spec.required_ruby_version = ">= 2.3"
36
- spec.add_runtime_dependency "benry-cmdopt" , "~> 2"
34
+ spec.add_runtime_dependency "benry-cmdopt" , "~> 2", ">= 2.1.0"
37
35
  spec.add_development_dependency "oktest" , "~> 1"
38
36
  end
@@ -21,7 +21,7 @@
21
21
  <ul class="nav">
22
22
  </ul>
23
23
  </nav>
24
- <p>($Release: 0.1.0 $)</p>
24
+ <p>($Release: 0.2.0 $)</p>
25
25
  <section class="section" id="whats-this">
26
26
  <h2>What's This?</h2>
27
27
  <p>Benry-CmdApp is a framework to create command-line application.
@@ -1116,7 +1116,8 @@ Actions:
1116
1116
  <section class="subsection" id="private-hidden-action">
1117
1117
  <h3>Private (Hidden) Action</h3>
1118
1118
  <ul>
1119
- <li>If action method is private, Benry::CmdApp regards that action as private.</li>
1119
+ <li>If <code>hidden: true</code> keyword argument passed to <code>@action.()</code>,
1120
+ or action method is private, then Benry::CmdApp regards that action as private.</li>
1120
1121
  <li>Private actions are hidden in help message.</li>
1121
1122
  <li>Private actions are shown when <code>-a</code> or <code>--all</code> option enabled and specified.</li>
1122
1123
  </ul>
@@ -1132,13 +1133,12 @@ class SampleAction &lt Benry::CmdApp::Action
1132
1133
  puts __method__
1133
1134
  end
1134
1135
 
1135
- @action.("test action #2")
1136
+ @action.("test action #2", <strong>hidden: true</strong>) # !!!!
1136
1137
  def test2()
1137
1138
  puts __method__
1138
1139
  end
1139
- <strong>private :test2</strong> # !!!! private method !!!!
1140
1140
 
1141
- <strong>private</strong> # !!!! private method !!!!
1141
+ <strong>private</strong> # !!!!
1142
1142
 
1143
1143
  @action.("test action #3")
1144
1144
  def test3()
@@ -1188,7 +1188,7 @@ Actions:
1188
1188
  <section class="subsection" id="private-hidden-option">
1189
1189
  <h3>Private (Hidden) Option</h3>
1190
1190
  <ul>
1191
- <li>Options which name stars with <code>_</code> are treated as private option.</li>
1191
+ <li>Options defined with <code>hidden: true</code> keyword argument are treated as private option.</li>
1192
1192
  <li>Private options are hidden in help message of action.</li>
1193
1193
  <li>Private options are shown when <code>-a</code> or <code>--all</code> option enabled and specified.</li>
1194
1194
  </ul>
@@ -1201,9 +1201,9 @@ class SampleAction &lt Benry::CmdApp::Action
1201
1201
 
1202
1202
  @action.("test action")
1203
1203
  @option.(:verbose, "-v", "verbose mode")
1204
- @option.(<strong>:_debug</strong> , "-D", "debug mode") # !!!!
1205
- def test1(verbose: false, _debug: false)
1206
- puts "verbose=#{verbose}, _debug=#{_debug}"
1204
+ @option.(:debug , "-D", "debug mode", <strong>hidden: true</strong>) # !!!!
1205
+ def test1(verbose: false, debug: false)
1206
+ puts "verbose=#{verbose}, debug=#{_debug}"
1207
1207
  end
1208
1208
 
1209
1209
  end
data/lib/benry/cmdapp.rb CHANGED
@@ -2,7 +2,7 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  ###
5
- ### $Release: 0.1.0 $
5
+ ### $Release: 0.2.0 $
6
6
  ### $Copyright: copyright(c) 2023 kwatch@gmail.com $
7
7
  ### $License: MIT License $
8
8
  ###
@@ -277,7 +277,7 @@ module Benry::CmdApp
277
277
 
278
278
  class ActionMetadata
279
279
 
280
- def initialize(name, klass, method, desc, schema, detail: nil, postamble: nil, important: nil, tag: nil)
280
+ def initialize(name, klass, method, desc, schema, detail: nil, postamble: nil, important: nil, tag: nil, hidden: nil)
281
281
  @name = name
282
282
  @klass = klass
283
283
  @method = method
@@ -287,14 +287,15 @@ module Benry::CmdApp
287
287
  @postamble = postamble if postamble != nil
288
288
  @important = important if important != nil
289
289
  @tag = tag if tag != nil
290
+ @hidden = hidden if hidden != nil
290
291
  end
291
292
 
292
- attr_reader :name, :method, :klass, :schema, :desc, :detail, :postamble, :important, :tag
293
+ attr_reader :name, :method, :klass, :schema, :desc, :detail, :postamble, :important, :tag, :hidden
293
294
 
294
295
  def hidden?()
295
296
  #; [!kp10p] returns true when action method is private.
296
297
  #; [!nw322] returns false when action method is not private.
297
- return ! @klass.method_defined?(@method)
298
+ return @hidden != nil ? @hidden : ! @klass.method_defined?(@method)
298
299
  end
299
300
 
300
301
  def important?()
@@ -581,7 +582,7 @@ module Benry::CmdApp
581
582
  return __run_action(action_name, true, args, kwargs)
582
583
  end
583
584
 
584
- def run_action!(action_name, *args, **kwargs)
585
+ def run_action_anyway(action_name, *args, **kwargs)
585
586
  #; [!2yrc2] invokes action even if already invoked.
586
587
  return __run_action(action_name, false, args, kwargs)
587
588
  end
@@ -636,18 +637,18 @@ module Benry::CmdApp
636
637
  @__aliasof__ = nil # ex: :method_name or "action-name"
637
638
  @__default__ = nil # ex: :method_name or "action-name"
638
639
  #; [!1qv12] @action is a Proc object and saves args.
639
- @action = proc do |desc, detail: nil, postamble: nil, important: nil, tag: nil|
640
- @__action__ = [desc, {detail: detail, postamble: postamble, important: important, tag: tag}]
640
+ @action = proc do |desc, detail: nil, postamble: nil, important: nil, tag: nil, hidden: nil|
641
+ @__action__ = [desc, {detail: detail, postamble: postamble, important: important, tag: tag, hidden: hidden}]
641
642
  end
642
643
  #; [!33ma7] @option is a Proc object and saves args.
643
- @option = proc do |param, optdef, desc, *rest, type: nil, rexp: nil, enum: nil, range: nil, value: nil, detail: nil, tag: nil, &block|
644
+ @option = proc do |param, optdef, desc, *rest, type: nil, rexp: nil, enum: nil, range: nil, value: nil, detail: nil, important: nil, tag: nil, hidden: nil, &block|
644
645
  #; [!gxybo] '@option.()' raises error when '@action.()' not called.
645
646
  @__action__ != nil or
646
647
  raise OptionDefError.new("@option.(#{param.inspect}): `@action.()` Required but not called.")
647
648
  schema = (@__option__ ||= SCHEMA_CLASS.new)
648
649
  #; [!ga6zh] '@option.()' raises error when invalid option info specified.
649
650
  begin
650
- schema.add(param, optdef, desc, *rest, type: type, rexp: rexp, enum: enum, range: range, value: value, detail: detail, tag: nil, &block)
651
+ schema.add(param, optdef, desc, *rest, type: type, rexp: rexp, enum: enum, range: range, value: value, detail: detail, important: important, tag: tag, hidden: hidden, &block)
651
652
  rescue Benry::CmdOpt::SchemaError => exc
652
653
  raise OptionDefError.new(exc.message)
653
654
  end
data/test/action_test.rb CHANGED
@@ -389,19 +389,19 @@ END
389
389
  end
390
390
 
391
391
 
392
- topic '#run_action!()' do
392
+ topic '#run_action_anyway()' do
393
393
 
394
394
  spec "[!2yrc2] invokes action even if already invoked." do
395
395
  sout, serr = capture_sio() do
396
- @action.run_action!("test3:foo:invoke3", "Alice", lang: "fr")
396
+ @action.run_action_anyway("test3:foo:invoke3", "Alice", lang: "fr")
397
397
  end
398
398
  ok {sout} == "Bonjour, Alice!\n"
399
399
  sout, serr = capture_sio() do
400
- @action.run_action!("test3:foo:invoke3", "Alice", lang: "fr")
400
+ @action.run_action_anyway("test3:foo:invoke3", "Alice", lang: "fr")
401
401
  end
402
402
  ok {sout} == "Bonjour, Alice!\n"
403
403
  sout, serr = capture_sio() do
404
- @action.run_action!("test3:foo:invoke3", "Alice", lang: "en")
404
+ @action.run_action_anyway("test3:foo:invoke3", "Alice", lang: "en")
405
405
  end
406
406
  ok {sout} == "Hello, Alice!\n"
407
407
  end
@@ -510,10 +510,10 @@ END
510
510
 
511
511
  spec "[!1qv12] @action is a Proc object and saves args." do
512
512
  class InheritedTest2 < Benry::CmdApp::ActionScope
513
- @action.("description", detail: "xxx", postamble: "yyy", important: true, tag: "zzz")
513
+ @action.("description", detail: "xxx", postamble: "yyy", important: true, tag: "zzz", hidden: false)
514
514
  end
515
515
  x = InheritedTest2.instance_variable_get('@__action__')
516
- ok {x} == ["description", {detail: "xxx", postamble: "yyy", important: true, tag: "zzz"}]
516
+ ok {x} == ["description", {detail: "xxx", postamble: "yyy", important: true, tag: "zzz", hidden: false}]
517
517
  end
518
518
 
519
519
  spec "[!33ma7] @option is a Proc object and saves args." do
data/test/app_test.rb CHANGED
@@ -1013,8 +1013,8 @@ END
1013
1013
  class HiddenTest < Benry::CmdApp::ActionScope
1014
1014
  private
1015
1015
  @action.("hidden test")
1016
- @option.(:_trace, "-T", "enable tracing")
1017
- def hidden1(_trace: false)
1016
+ @option.(:trace, "-T", "enable tracing", hidden: true)
1017
+ def hidden1(trace: false)
1018
1018
  end
1019
1019
  end
1020
1020
  #
data/test/help_test.rb CHANGED
@@ -84,7 +84,7 @@ END
84
84
 
85
85
  spec "[!8b02e] ignores '[<options>]' in 'Usage:' when only hidden options speicified." do
86
86
  schema = new_schema(lang: false)
87
- schema.add(:_lang, "-l, --lang=<en|fr|it>", "language")
87
+ schema.add(:lang, "-l, --lang=<en|fr|it>", "language", hidden: true)
88
88
  msg = new_metadata(schema).help_message("testapp")
89
89
  msg = uncolorize(msg)
90
90
  ok {msg} =~ /^ \$ testapp halo1 \[<user>\]\n/
@@ -116,7 +116,7 @@ END
116
116
 
117
117
  spec "[!hghuj] ignores 'Options:' section when only hidden options speicified." do
118
118
  schema = new_schema(lang: false)
119
- schema.add(:_lang, "-l, --lang=<en|fr|it>", "language") # hidden option
119
+ schema.add(:lang, "-l, --lang=<en|fr|it>", "language", hidden: true) # hidden option
120
120
  msg = new_metadata(schema).help_message("testapp")
121
121
  msg = uncolorize(msg)
122
122
  ok {msg}.NOT.include?("Options:\n")
@@ -125,7 +125,7 @@ END
125
125
  spec "[!vqqq1] hidden option should be shown in weak format." do
126
126
  schema = new_schema(lang: false)
127
127
  schema.add(:file , "-f, --file=<file>", "filename")
128
- schema.add(:_lang, "-l, --lang=<lang>", "language") # hidden option
128
+ schema.add(:lang, "-l, --lang=<lang>", "language", hidden: true) # hidden option
129
129
  msg = new_metadata(schema).help_message("testapp", true)
130
130
  ok {msg}.end_with?(<<"END")
131
131
  \e[34mOptions:\e[0m
@@ -436,7 +436,7 @@ END
436
436
  @config.option_debug = false
437
437
  app = Benry::CmdApp::Application.new(@config)
438
438
  schema = app.instance_variable_get('@schema')
439
- schema.add(:_log, "-L", "private option")
439
+ schema.add(:log, "-L", "private option", hidden: true)
440
440
  msg = app.help_message()
441
441
  msg = uncolorize(msg)
442
442
  ok {msg} !~ /^ -L /
@@ -454,7 +454,7 @@ END
454
454
  @config.option_debug = false
455
455
  app = Benry::CmdApp::Application.new(@config)
456
456
  schema = app.instance_variable_get('@schema')
457
- schema.add(:_log, "-L", "private option")
457
+ schema.add(:log, "-L", "private option", hidden: true)
458
458
  msg = app.help_message(true)
459
459
  msg = uncolorize(msg)
460
460
  ok {msg} =~ /^ -L /
@@ -477,7 +477,7 @@ END
477
477
 
478
478
  spec "[!p1tu9] prints option in weak format if option is hidden." do
479
479
  |app3|
480
- app3.schema.add(:_log, "-L", "private option") # !!!
480
+ app3.schema.add(:log, "-L", "private option", hidden: true) # !!!
481
481
  msg = app3.help_message(true)
482
482
  ok {msg}.include?(<<END)
483
483
  \e[34mOptions:\e[0m
@@ -494,7 +494,7 @@ END
494
494
  @config.option_debug = false
495
495
  app = Benry::CmdApp::Application.new(@config)
496
496
  schema = app.instance_variable_get('@schema')
497
- schema.add(:_log, "-L", "private option")
497
+ schema.add(:log, "-L", "private option", hidden: true)
498
498
  msg = app.help_message()
499
499
  msg = uncolorize(msg)
500
500
  ok {msg} !~ /^Options:$/
data/test/util_test.rb CHANGED
@@ -47,7 +47,7 @@ Oktest.scope do
47
47
 
48
48
  spec "[!c4ljy] returns true if schema contains only private (hidden) options." do
49
49
  sc = Benry::CmdOpt::Schema.new
50
- sc.add(:_help, "-h", "help")
50
+ sc.add(:help, "-h", "help", hidden: true)
51
51
  ok {Benry::CmdApp::Util.schema_empty?(sc)} == true
52
52
  sc.add(:version, "-V", "version")
53
53
  ok {Benry::CmdApp::Util.schema_empty?(sc)} == false
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: benry-cmdapp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.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-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: benry-cmdopt
@@ -17,6 +17,9 @@ dependencies:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '2'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 2.1.0
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -24,6 +27,9 @@ dependencies:
24
27
  - - "~>"
25
28
  - !ruby/object:Gem::Version
26
29
  version: '2'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 2.1.0
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: oktest
29
35
  requirement: !ruby/object:Gem::Requirement