benry-cmdapp 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGES.md +6 -0
- data/README.md +48 -15
- data/benry-cmdapp.gemspec +2 -2
- data/doc/benry-cmdapp.html +44 -16
- data/doc/css/style.css +2 -2
- data/lib/benry/cmdapp.rb +3 -3
- data/test/scope_test.rb +10 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 93ac71b6b3c1d20a3b3fda343372b791c284e77e3a1b475ff9ac6a7c6adec123
|
4
|
+
data.tar.gz: 01a0568d79c5e94c4be53aaa9eb0766406a695c55b4c2c11222cf1c396700b87
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 71a365339d5b71b5acb46558e116991fcce7c900261b98b15dddeb50ba4fa7d50b7b6e278b22db4b3413fb171432f92369a0860df86c484b35fca8aacbb76bc3
|
7
|
+
data.tar.gz: e795e95e65f1c50f3ba7123f050747f8c504f1b233839df775c8451b33983f7da5ca7829df7b6854a1e17ea6b410c336829d023a4b5659bb19b1725c66345d97
|
data/CHANGES.md
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Benry-CmdApp
|
2
2
|
|
3
|
-
($Release: 1.
|
3
|
+
($Release: 1.1.0 $)
|
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
|
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
|
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.("
|
3040
|
-
@option.(:
|
3041
|
-
|
3042
|
-
|
3043
|
-
|
3044
|
-
|
3045
|
-
|
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 -
|
3060
|
-
|
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.
|
5
|
+
spec.version = "$Release: 1.1.0 $".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.
|
34
|
+
spec.add_runtime_dependency "benry-cmdopt" , "~> 2", ">= 2.4.0"
|
35
35
|
spec.add_development_dependency "oktest" , "~> 1"
|
36
36
|
end
|
data/doc/benry-cmdapp.html
CHANGED
@@ -21,7 +21,7 @@
|
|
21
21
|
<ul class="nav">
|
22
22
|
</ul>
|
23
23
|
</nav>
|
24
|
-
<p>($Release: 1.
|
24
|
+
<p>($Release: 1.1.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.
|
@@ -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-
|
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 <topic></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 < Benry::CmdApp::Action
|
1938
|
+
|
1939
|
+
@action.("multiple option test")
|
1940
|
+
@option.(:path, "-I <path>", "path", <strong>multiple: true</strong>)
|
1941
|
+
def test_(path: [])
|
1942
|
+
puts "path=#{path.inspect}" #=> 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-
|
2783
|
-
<h3>Q: How to define
|
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 < Benry::CmdApp::Action
|
2790
2817
|
|
2791
|
-
@action.("
|
2792
|
-
@option.(:
|
2793
|
-
<strong>
|
2794
|
-
<strong>
|
2795
|
-
|
2796
|
-
|
2797
|
-
|
2798
|
-
<strong>}</strong> # !!!!
|
2799
|
-
def test_(path: [])
|
2800
|
-
puts "path=#{path.inspect}" #=> 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>-
|
2810
|
-
|
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.
|
5
|
+
### $Release: 1.1.0 $
|
6
6
|
### $Copyright: copyright(c) 2023 kwatch@gmail.com $
|
7
7
|
### $License: MIT License $
|
8
8
|
###
|
@@ -525,7 +525,7 @@ module Benry::CmdApp
|
|
525
525
|
#; [!en6n0] sets Proc object to `@option` in subclass.
|
526
526
|
@option = lambda do |key, optstr, desc,
|
527
527
|
type: nil, rexp: nil, pattern: nil, enum: nil,
|
528
|
-
range: nil, value: nil, detail: nil,
|
528
|
+
range: nil, value: nil, multiple: nil, detail: nil,
|
529
529
|
tag: nil, important: nil, hidden: nil, &callback|
|
530
530
|
#; [!68hf8] raises DefinitionError if `@option.()` called without `@action.()`.
|
531
531
|
@__actiondef__ != nil or
|
@@ -534,7 +534,7 @@ module Benry::CmdApp
|
|
534
534
|
schema = @__actiondef__[1]
|
535
535
|
schema.add(key, optstr, desc,
|
536
536
|
type: type, rexp: rexp, pattern: pattern, enum: enum,
|
537
|
-
range: range, value: value, detail: detail,
|
537
|
+
range: range, value: value, multiple: multiple, detail: detail,
|
538
538
|
tag: tag, important: important, hidden: hidden, &callback)
|
539
539
|
end
|
540
540
|
#; [!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
|
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.
|
4
|
+
version: 1.1.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-
|
11
|
+
date: 2023-12-04 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.
|
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.
|
32
|
+
version: 2.4.0
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: oktest
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|