benry-cmdapp 1.0.0 → 1.1.1

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: eed2f767ac217ab20e675f3f4d587f86c1f98555ce5e6905afa6c3b0899477dd
4
- data.tar.gz: 6efef4f285017450fe9643c9c8aece094480f913d09de3afabc88f40f243bc14
3
+ metadata.gz: dd749bd655750efee168dacda0d1f2609548a31fff1dd2c9d53e323c0fad145b
4
+ data.tar.gz: a3484ad1a239396af73c7173ac7272ac156d2e424b2a4d90f732cd1e1196bf95
5
5
  SHA512:
6
- metadata.gz: 7b091695b69be73c48e1dc9b91337be36a91814457ee606e1a2e605bc8960cf89db6af9f076cf7cdcb125cfe358ed0795165bc4772ec2c3380428d45892fc5eb
7
- data.tar.gz: 98fdbdcf533ed4d12b5886dd66cc50b7eca5d6f21069cb2478481594a00f0f15dde49a3e5efc4cfa20aa404a6daab09de290b72c8f12be4337000fc785ea2898
6
+ metadata.gz: 8ede7e8ca3b150642c064343ec3a310164986595a313e97a9e96cb7766fa6b5725102f482a40edfcfa3edafdea681cf58459d8845fa4b0622716e709dfe07024
7
+ data.tar.gz: 87a6c333685eb856704c37c62692a177384dae41475a55402904cd4d3c24d1dcfde8211e8df5d7718ec981e5a452b61f1d02894f7ed47671e13b71fb930f3a20
data/CHANGES.md CHANGED
@@ -2,6 +2,18 @@ CHANGES
2
2
  =======
3
3
 
4
4
 
5
+ Release 1.1.1 (2023-12-29)
6
+ --------------------------
7
+
8
+ * [bugfix] Fix to print method parameter 'foo_' as 'foo' in help message.
9
+
10
+
11
+ Release 1.1.0 (2023-12-04)
12
+ --------------------------
13
+
14
+ * [enhance] Supports multiple option by `@options.(..., multiple: true)`.
15
+
16
+
5
17
  Release 1.0.0 (2023-11-25)
6
18
  --------------------------
7
19
 
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Benry-CmdApp
2
2
 
3
- ($Release: 1.0.0 $)
3
+ ($Release: 1.1.1 $)
4
4
 
5
5
 
6
6
  ## What's This?
@@ -61,6 +61,7 @@ Benry-CmdApp requires Ruby >= 2.3.
61
61
  * [Hidden Action](#hidden-action)
62
62
  * [Hidden Option](#hidden-option)
63
63
  * [Important Actions or Options](#important-actions-or-options)
64
+ * [Multiple Option](#multiple-option)
64
65
  * [Configuratoin and Customization](#configuratoin-and-customization)
65
66
  * [Application Configuration](#application-configuration)
66
67
  * [Customization of Global Options](#customization-of-global-options)
@@ -77,7 +78,7 @@ Benry-CmdApp requires Ruby >= 2.3.
77
78
  * [Q: How to re-define an existing action?](#q-how-to-re-define-an-existing-action)
78
79
  * [Q: How to show entering into or exitting from actions?](#q-how-to-show-entering-into-or-exitting-from-actions)
79
80
  * [Q: How to enable/disable color mode?](#q-how-to-enabledisable-color-mode)
80
- * [Q: How to define a multiple option, like `-I` option of Ruby?](#q-how-to-define-a-multiple-option-like--i-option-of-ruby)
81
+ * [Q: How to define `-vvv` style option?](#q-how-to-define--vvv-style-option)
81
82
  * [Q: How to show global option `-L <topic>` in help message?](#q-how-to-show-global-option--l-topic-in-help-message)
82
83
  * [Q: How to specify detailed description of options?](#q-how-to-specify-detailed-description-of-options)
83
84
  * [Q: How to list only aliases (or actions) excluding actions (or aliases) ?](#q-how-to-list-only-aliases-or-actions-excluding-actions-or-aliases-)
@@ -2100,6 +2101,37 @@ Options:
2100
2101
  ```
2101
2102
 
2102
2103
 
2104
+ ### Multiple Option
2105
+
2106
+ If you need multiple options like `-I` option of Ruby,
2107
+ pass `multiple: true` to `@option.()`.
2108
+
2109
+ File: ex39.rb
2110
+
2111
+ ```ruby
2112
+ require 'benry/cmdapp'
2113
+
2114
+ class TestAction < Benry::CmdApp::Action
2115
+
2116
+ @action.("multiple option test")
2117
+ @option.(:path, "-I <path>", "path", multiple: true)
2118
+ def test_(path: [])
2119
+ puts "path=#{path.inspect}" #=> path=["/tmp", "/var/tmp"]
2120
+ end
2121
+
2122
+ end
2123
+
2124
+ exit Benry::CmdApp.main("test app")
2125
+ ```
2126
+
2127
+ Output:
2128
+
2129
+ ```console
2130
+ [bash]$ ruby ex39.rb test -I /tmp -I /var/tmp # !!!!
2131
+ path=["/tmp", "/var/tmp"] # !!!!
2132
+ ```
2133
+
2134
+
2103
2135
 
2104
2136
  ## Configuratoin and Customization
2105
2137
 
@@ -3025,7 +3057,7 @@ Actions:
3025
3057
  ```
3026
3058
 
3027
3059
 
3028
- ### Q: How to define a multiple option, like `-I` option of Ruby?
3060
+ ### Q: How to define `-vvv` style option?
3029
3061
 
3030
3062
  A: Provide block parameter on `@option.()`.
3031
3063
 
@@ -3036,16 +3068,13 @@ require 'benry/cmdapp'
3036
3068
 
3037
3069
  class TestAction < Benry::CmdApp::Action
3038
3070
 
3039
- @action.("multiple option test")
3040
- @option.(:path, "-I <path>", "path") {|options, key, val| # !!!!
3041
- arr = options[key] || [] # !!!!
3042
- arr << val # !!!!
3043
- arr # !!!!
3044
- ## or: # !!!!
3045
- #(options[key] || []) << val # !!!!
3046
- } # !!!!
3047
- def test_(path: [])
3048
- puts "path=#{path.inspect}" #=> path=["/tmp", "/var/tmp"]
3071
+ @action.("set verbose level")
3072
+ @option.(:verbose, "-v", "verbose level") {|opts, key, val| # !!!!
3073
+ opts[key] ||= 0 # !!!!
3074
+ opts[key] += 1 # !!!!
3075
+ } # !!!!
3076
+ def test_(verbose: 0)
3077
+ puts "verbose=#{verbose}"
3049
3078
  end
3050
3079
 
3051
3080
  end
@@ -3056,8 +3085,12 @@ exit Benry::CmdApp.main("test app")
3056
3085
  Output:
3057
3086
 
3058
3087
  ```console
3059
- [bash]$ ruby ex65.rb test -I /tmp -I /var/tmp # !!!!
3060
- path=["/tmp", "/var/tmp"] # !!!!
3088
+ [bash]$ ruby ex65.rb test -v # !!!!
3089
+ verbose=1
3090
+ [bash]$ ruby ex65.rb test -vv # !!!!
3091
+ verbose=2
3092
+ [bash]$ ruby ex65.rb test -vvv # !!!!
3093
+ verbose=3
3061
3094
  ```
3062
3095
 
3063
3096
 
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: 1.0.0 $".split()[1]
5
+ spec.version = "$Release: 1.1.1 $".split()[1]
6
6
  spec.author = "kwatch"
7
7
  spec.email = "kwatch@gmail.com"
8
8
  spec.platform = Gem::Platform::RUBY
@@ -31,6 +31,6 @@ END
31
31
  #spec.extra_rdoc_files = ["README.md", "CHANGES.md"]
32
32
 
33
33
  spec.required_ruby_version = ">= 2.3"
34
- spec.add_runtime_dependency "benry-cmdopt" , "~> 2", ">= 2.2.0"
34
+ spec.add_runtime_dependency "benry-cmdopt" , "~> 2", ">= 2.4.0"
35
35
  spec.add_development_dependency "oktest" , "~> 1"
36
36
  end
@@ -21,7 +21,7 @@
21
21
  <ul class="nav">
22
22
  </ul>
23
23
  </nav>
24
- <p>($Release: 1.0.0 $)</p>
24
+ <p>($Release: 1.1.1 $)</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.
@@ -80,6 +80,7 @@ like <code>git</code>, <code>docker</code>, or <code>npm</code>, Benry-CmdApp is
80
80
  <li><a href="#hidden-action">Hidden Action</a></li>
81
81
  <li><a href="#hidden-option">Hidden Option</a></li>
82
82
  <li><a href="#important-actions-or-options">Important Actions or Options</a></li>
83
+ <li><a href="#multiple-option">Multiple Option</a></li>
83
84
  </ul></li>
84
85
  <li><a href="#configuratoin-and-customization">Configuratoin and Customization</a>
85
86
  <ul>
@@ -100,7 +101,7 @@ like <code>git</code>, <code>docker</code>, or <code>npm</code>, Benry-CmdApp is
100
101
  <li><a href="#q-how-to-re-define-an-existing-action">Q: How to re-define an existing action?</a></li>
101
102
  <li><a href="#q-how-to-show-entering-into-or-exitting-from-actions">Q: How to show entering into or exitting from actions?</a></li>
102
103
  <li><a href="#q-how-to-enabledisable-color-mode">Q: How to enable/disable color mode?</a></li>
103
- <li><a href="#q-how-to-define-a-multiple-option-like--i-option-of-ruby">Q: How to define a multiple option, like <code>-I</code> option of Ruby?</a></li>
104
+ <li><a href="#q-how-to-define--vvv-style-option">Q: How to define <code>-vvv</code> style option?</a></li>
104
105
  <li><a href="#q-how-to-show-global-option--l-topic-in-help-message">Q: How to show global option <code>-L &lttopic&gt;</code> in help message?</a></li>
105
106
  <li><a href="#q-how-to-specify-detailed-description-of-options">Q: How to specify detailed description of options?</a></li>
106
107
  <li><a href="#q-how-to-list-only-aliases-or-actions-excluding-actions-or-aliases-">Q: How to list only aliases (or actions) excluding actions (or aliases) ?</a></li>
@@ -1925,6 +1926,32 @@ Options:
1925
1926
  <strong>--bar : not important option</strong> # !!!! gray color !!!!
1926
1927
  </pre>
1927
1928
  </section>
1929
+ <section class="subsection" id="multiple-option">
1930
+ <h3>Multiple Option</h3>
1931
+ <p>If you need multiple options like <code>-I</code> option of Ruby,
1932
+ pass <code>multiple: true</code> to <code>@option.()</code>.</p>
1933
+ <p>File: ex39.rb</p>
1934
+ <pre class="language-ruby">
1935
+ require 'benry/cmdapp'
1936
+
1937
+ class TestAction &lt Benry::CmdApp::Action
1938
+
1939
+ @action.("multiple option test")
1940
+ @option.(:path, "-I &ltpath&gt;", "path", <strong>multiple: true</strong>)
1941
+ def test_(path: [])
1942
+ puts "path=#{path.inspect}" #=&gt; path=["/tmp", "/var/tmp"]
1943
+ end
1944
+
1945
+ end
1946
+
1947
+ exit Benry::CmdApp.main("test app")
1948
+ </pre>
1949
+ <p>Output:</p>
1950
+ <pre class="language-console">
1951
+ [bash]$ ruby ex39.rb test <strong>-I /tmp -I /var/tmp</strong> # !!!!
1952
+ path=<strong>["/tmp", "/var/tmp"]</strong> # !!!!
1953
+ </pre>
1954
+ </section>
1928
1955
  </section>
1929
1956
  <section class="section" id="configuratoin-and-customization">
1930
1957
  <h2>Configuratoin and Customization</h2>
@@ -2779,8 +2806,8 @@ Actions:
2779
2806
  [bash]$ ruby ex64.rb -h <strong>--color</strong> # !!!!
2780
2807
  </pre>
2781
2808
  </section>
2782
- <section class="subsection" id="q-how-to-define-a-multiple-option-like--i-option-of-ruby">
2783
- <h3>Q: How to define a multiple option, like <code>-I</code> option of Ruby?</h3>
2809
+ <section class="subsection" id="q-how-to-define--vvv-style-option">
2810
+ <h3>Q: How to define <code>-vvv</code> style option?</h3>
2784
2811
  <p>A: Provide block parameter on <code>@option.()</code>.</p>
2785
2812
  <p>File: ex65.rb</p>
2786
2813
  <pre class="language-ruby">
@@ -2788,16 +2815,13 @@ require 'benry/cmdapp'
2788
2815
 
2789
2816
  class TestAction &lt Benry::CmdApp::Action
2790
2817
 
2791
- @action.("multiple option test")
2792
- @option.(:path, "-I &ltpath&gt;", "path") <strong>{|options, key, val|</strong> # !!!!
2793
- <strong>arr = options[key] || []</strong> # !!!!
2794
- <strong>arr &lt&lt val</strong> # !!!!
2795
- <strong>arr</strong> # !!!!
2796
- ## or: # !!!!
2797
- #<strong>(options[key] || []) &lt&lt val</strong> # !!!!
2798
- <strong>}</strong> # !!!!
2799
- def test_(path: [])
2800
- puts "path=#{path.inspect}" #=&gt; path=["/tmp", "/var/tmp"]
2818
+ @action.("set verbose level")
2819
+ @option.(:verbose, "-v", "verbose level") <strong>{|opts, key, val|</strong> # !!!!
2820
+ <strong>opts[key] ||= 0</strong> # !!!!
2821
+ <strong>opts[key] += 1</strong> # !!!!
2822
+ <strong>}</strong> # !!!!
2823
+ def test_(verbose: 0)
2824
+ puts "verbose=#{verbose}"
2801
2825
  end
2802
2826
 
2803
2827
  end
@@ -2806,8 +2830,12 @@ exit Benry::CmdApp.main("test app")
2806
2830
  </pre>
2807
2831
  <p>Output:</p>
2808
2832
  <pre class="language-console">
2809
- [bash]$ ruby ex65.rb test <strong>-I /tmp -I /var/tmp</strong> # !!!!
2810
- path=["/tmp", "/var/tmp"] # !!!!
2833
+ [bash]$ ruby ex65.rb test <strong>-v</strong> # !!!!
2834
+ verbose=<strong>1</strong>
2835
+ [bash]$ ruby ex65.rb test <strong>-vv</strong> # !!!!
2836
+ verbose=<strong>2</strong>
2837
+ [bash]$ ruby ex65.rb test <strong>-vvv</strong> # !!!!
2838
+ verbose=<strong>3</strong>
2811
2839
  </pre>
2812
2840
  </section>
2813
2841
  <section class="subsection" id="q-how-to-show-global-option--l-topic-in-help-message">
data/doc/css/style.css CHANGED
@@ -74,12 +74,12 @@ pre > strong {
74
74
  font-weight: bold;
75
75
  color: #900;
76
76
  }
77
- pre.language-terminal {
77
+ pre.language-terminal, pre.language-console {
78
78
  background: #333;
79
79
  color: #fff;
80
80
  border-color: #000;
81
81
  }
82
- pre.language-terminal > strong {
82
+ pre.language-terminal > strong, pre.language-console > strong {
83
83
  color: #f66;
84
84
  }
85
85
  code {
data/lib/benry/cmdapp.rb CHANGED
@@ -2,7 +2,7 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  ###
5
- ### $Release: 1.0.0 $
5
+ ### $Release: 1.1.1 $
6
6
  ### $Copyright: copyright(c) 2023 kwatch@gmail.com $
7
7
  ### $License: MIT License $
8
8
  ###
@@ -91,18 +91,22 @@ module Benry::CmdApp
91
91
  sb << ("]" * n) if n > 0
92
92
  #; [!mbxy5] converts `.foo(x, *x_)` into `' <x>...'`.
93
93
  #; [!mh9ni] converts `.foo(x, *x2)` into `' <x>...'`.
94
- return sb.join().sub(/<([^>]+)> \[<\1[-_2]>\.\.\.\]/, "<\\1>...")
94
+ return sb.join().sub(/<([^>]+)> \[<\1[-_2]?>\.\.\.\]/, "<\\1>...")
95
95
  end
96
96
 
97
97
  def param2arg(param)
98
98
  #; [!ahvsn] converts parameter name (Symbol) into argument name (String).
99
99
  #; [!27dpw] converts `:aa_or_bb_or_cc` into `'aa|bb|cc'`.
100
100
  #; [!to41h] converts `:aa__bb__cc` into `'aa.bb.cc'`.
101
+ #; [!cldax] converts `:aa_` into `'aa'`.
101
102
  #; [!2ma08] converts `:aa_bb_cc` into `'aa-bb-cc'`.
103
+ #; [!5d0qf] lefts `:_aa` as `'_aa'`.
102
104
  s = param.to_s
103
105
  s = s.gsub('_or_', '|') # ex: 'file_or_dir' => 'file|dir'
104
106
  s = s.gsub('__' , '.') # ex: 'file__html' => 'file.html'
107
+ s = s.gsub(/_+\z/, '') # ex: 'end_' => 'end'
105
108
  s = s.gsub('_' , '-') # ex: 'foo_bar_baz' => 'foo-bar-baz'
109
+ s = s.gsub(/\A-/ , '_') # ex: '-aa' => '_aa'
106
110
  return s
107
111
  end
108
112
 
@@ -525,7 +529,7 @@ module Benry::CmdApp
525
529
  #; [!en6n0] sets Proc object to `@option` in subclass.
526
530
  @option = lambda do |key, optstr, desc,
527
531
  type: nil, rexp: nil, pattern: nil, enum: nil,
528
- range: nil, value: nil, detail: nil,
532
+ range: nil, value: nil, multiple: nil, detail: nil,
529
533
  tag: nil, important: nil, hidden: nil, &callback|
530
534
  #; [!68hf8] raises DefinitionError if `@option.()` called without `@action.()`.
531
535
  @__actiondef__ != nil or
@@ -534,7 +538,7 @@ module Benry::CmdApp
534
538
  schema = @__actiondef__[1]
535
539
  schema.add(key, optstr, desc,
536
540
  type: type, rexp: rexp, pattern: pattern, enum: enum,
537
- range: range, value: value, detail: detail,
541
+ range: range, value: value, multiple: multiple, detail: detail,
538
542
  tag: tag, important: important, hidden: hidden, &callback)
539
543
  end
540
544
  #; [!aiwns] `@copy_options.()` copies options from other action.
data/test/scope_test.rb CHANGED
@@ -116,8 +116,9 @@ Oktest.scope do
116
116
  @action.("foobar")
117
117
  @option.(:lang, "-l <lang>", "language", detail: "blabla", hidden: true) {|val| val }
118
118
  @option.(:color, "--color[=<on|off>]", "color mode", type: TrueClass)
119
+ @option.(:ints, "-n <N>", "integers", multiple: true, type: Integer)
119
120
  tuple = @__actiondef__
120
- def s2055(help: false, lang: nil, color: nil)
121
+ def s2055(help: false, lang: nil, color: nil, ints: nil)
121
122
  end
122
123
  end
123
124
  schema = tuple[1]
@@ -130,6 +131,7 @@ Oktest.scope do
130
131
  ok {x.desc} == "language"
131
132
  ok {x.type} == nil
132
133
  ok {x.detail} == "blabla"
134
+ ok {x.multiple?} == false
133
135
  ok {x.hidden?} == true
134
136
  ok {x.callback}.is_a?(Proc)
135
137
  #
@@ -140,8 +142,15 @@ Oktest.scope do
140
142
  ok {x.desc} == "color mode"
141
143
  ok {x.type} == TrueClass
142
144
  ok {x.detail} == nil
145
+ ok {x.multiple?} == false
143
146
  ok {x.hidden?} == false
144
147
  ok {x.callback} == nil
148
+ #
149
+ x = schema.get(:ints)
150
+ ok {x.key} == :ints
151
+ ok {x.short} == "n"
152
+ ok {x.long} == nil
153
+ ok {x.multiple?} == true
145
154
  end
146
155
 
147
156
  spec "[!aiwns] `@copy_options.()` copies options from other action." do
data/test/util_test.rb CHANGED
@@ -109,10 +109,18 @@ Oktest.scope do
109
109
  ok {Benry::CmdApp::Util.param2arg(:aa__bb__cc)} == "aa.bb.cc"
110
110
  end
111
111
 
112
+ spec "[!cldax] converts `:aa_` into `'aa'`." do
113
+ ok {Benry::CmdApp::Util.param2arg(:aa_)} == "aa"
114
+ end
115
+
112
116
  spec "[!2ma08] converts `:aa_bb_cc` into `'aa-bb-cc'`." do
113
117
  ok {Benry::CmdApp::Util.param2arg(:aa_bb_cc)} == "aa-bb-cc"
114
118
  end
115
119
 
120
+ spec "[!5d0qf] lefts `:_aa` as `'_aa'`." do
121
+ ok {Benry::CmdApp::Util.param2arg(:_aa_bb_cc_)} == "_aa-bb-cc"
122
+ end
123
+
116
124
  end
117
125
 
118
126
 
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: 1.0.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - kwatch
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-11-25 00:00:00.000000000 Z
11
+ date: 2023-12-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: benry-cmdopt
@@ -19,7 +19,7 @@ dependencies:
19
19
  version: '2'
20
20
  - - ">="
21
21
  - !ruby/object:Gem::Version
22
- version: 2.2.0
22
+ version: 2.4.0
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -29,7 +29,7 @@ dependencies:
29
29
  version: '2'
30
30
  - - ">="
31
31
  - !ruby/object:Gem::Version
32
- version: 2.2.0
32
+ version: 2.4.0
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: oktest
35
35
  requirement: !ruby/object:Gem::Requirement