benry-cmdapp 0.2.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.md +6 -0
- data/README.md +1693 -852
- data/benry-cmdapp.gemspec +3 -3
- data/doc/benry-cmdapp.html +1582 -906
- data/lib/benry/cmdapp.rb +1894 -1060
- data/test/app_test.rb +882 -1078
- data/test/config_test.rb +71 -0
- data/test/context_test.rb +382 -0
- data/test/func_test.rb +302 -82
- data/test/help_test.rb +1054 -553
- data/test/metadata_test.rb +191 -0
- data/test/misc_test.rb +175 -0
- data/test/registry_test.rb +402 -0
- data/test/run_all.rb +4 -3
- data/test/scope_test.rb +1210 -0
- data/test/shared.rb +112 -49
- data/test/util_test.rb +154 -99
- metadata +17 -9
- data/test/action_test.rb +0 -1038
- data/test/index_test.rb +0 -185
data/test/help_test.rb
CHANGED
@@ -1,215 +1,301 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
|
-
require 'oktest'
|
4
4
|
|
5
|
-
|
6
|
-
require_relative './shared'
|
5
|
+
require_relative 'shared'
|
7
6
|
|
8
7
|
|
9
|
-
|
8
|
+
class HelpTestAction < Benry::CmdApp::Action
|
10
9
|
|
10
|
+
@action.("preamble and postamble",
|
11
|
+
detail: "See https://....",
|
12
|
+
postamble: [{"Examples:"=>" $ echo\n"}, "(Tips: blabla)"])
|
13
|
+
def prepostamble()
|
14
|
+
end
|
11
15
|
|
12
|
-
|
16
|
+
@action.("no options")
|
17
|
+
def noopt(aa, bb=nil)
|
18
|
+
puts "aa=#{aa.inspect}, bb=#{bb.inspect}"
|
19
|
+
end
|
13
20
|
|
21
|
+
@action.("usage sample", usage: "input.txt > output.txt")
|
22
|
+
def usagesample1(aa, bb, cc=nil)
|
23
|
+
end
|
14
24
|
|
15
|
-
|
16
|
-
|
25
|
+
@action.("usage sample", usage: ["input.txt | less", "input.txt > output.txt"])
|
26
|
+
@option.(:file, "-f <file>", "filename")
|
27
|
+
def usagesample2(aa, bb, cc=nil, file: nil)
|
28
|
+
end
|
29
|
+
|
30
|
+
@action.("arguments sample")
|
31
|
+
@option.(:xx, "--xx", "XX")
|
32
|
+
@option.(:yy, "--yy", "YY")
|
33
|
+
def argsample(aa, bb, cc=nil, dd=nil, *rest, xx: nil, yy: nil)
|
34
|
+
puts "aa=#{aa.inspect}, bb=#{bb.inspect}, cc=#{cc.inspect}, dd=#{dd.inspect}, rest=#{rest.inspect}, xx=#{xx.inspect}, yy=#{yy.inspect}"
|
35
|
+
end
|
36
|
+
|
37
|
+
category "secret:" do
|
38
|
+
@action.("secret action", hidden: true)
|
39
|
+
def crypt()
|
17
40
|
end
|
41
|
+
end
|
18
42
|
|
43
|
+
category "descdemo:", "category description demo" do
|
44
|
+
@action.("demo #1")
|
45
|
+
def demo1()
|
46
|
+
end
|
47
|
+
@action.("demo #2")
|
48
|
+
def demo2()
|
49
|
+
end
|
50
|
+
end
|
19
51
|
|
20
|
-
|
52
|
+
## alias test
|
53
|
+
@action.("sample action")
|
54
|
+
@option.(:aa, "-a, --aa", "option A")
|
55
|
+
@option.(:bb, " --bb", "option B")
|
56
|
+
def alitest1(xx, yy=0, *zz, aa: nil, bb: nil)
|
57
|
+
end
|
58
|
+
define_alias "alitest1x", "alitest1"
|
59
|
+
define_alias "alitest1y", ["alitest1", "--aa"]
|
60
|
+
Benry::CmdApp.define_alias! "alitest1z", ["alitest1y", "foobar"] # error
|
21
61
|
|
22
|
-
|
23
|
-
msg = @builder.build_section("Example", " $ echo 'Hello, world!'")
|
24
|
-
ok {msg} == <<"END"
|
25
|
-
\e[34mExample:\e[0m
|
26
|
-
$ echo 'Hello, world!'
|
27
|
-
END
|
28
|
-
end
|
62
|
+
end
|
29
63
|
|
30
|
-
spec "[!09jzn] third argument can be nil." do
|
31
|
-
msg = @builder.build_section("Example", " $ echo 'Hello, world!'", "(see https://...)")
|
32
|
-
ok {msg} == <<"END"
|
33
|
-
\e[34mExample:\e[0m (see https://...)
|
34
|
-
$ echo 'Hello, world!'
|
35
|
-
END
|
36
|
-
end
|
37
64
|
|
38
|
-
|
65
|
+
class HelpTestBuilder < Benry::CmdApp::BaseHelpBuilder
|
66
|
+
HEADER_ACTIONS = "<ACTIONS>"
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
Oktest.scope do
|
39
71
|
|
40
72
|
|
73
|
+
def with_dummy_registry(registry=nil, &b)
|
74
|
+
registry ||= Benry::CmdApp::Registry.new()
|
75
|
+
bkup = nil
|
76
|
+
Benry::CmdApp.module_eval {
|
77
|
+
bkup = const_get :REGISTRY
|
78
|
+
remove_const :REGISTRY
|
79
|
+
const_set :REGISTRY, registry
|
80
|
+
}
|
81
|
+
yield registry
|
82
|
+
return registry
|
83
|
+
ensure
|
84
|
+
Benry::CmdApp.module_eval {
|
85
|
+
remove_const :REGISTRY
|
86
|
+
const_set :REGISTRY, bkup
|
87
|
+
}
|
41
88
|
end
|
42
89
|
|
90
|
+
def new_registry_with_filter(*categories)
|
91
|
+
idx = Benry::CmdApp::Registry.new()
|
92
|
+
Benry::CmdApp::REGISTRY.metadata_each do |md|
|
93
|
+
if md.name.start_with?(*categories)
|
94
|
+
idx.metadata_add(md)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
return idx
|
98
|
+
end
|
43
99
|
|
44
|
-
|
45
|
-
|
100
|
+
|
101
|
+
topic Benry::CmdApp::BaseHelpBuilder do
|
102
|
+
|
103
|
+
|
104
|
+
before do
|
105
|
+
@config = Benry::CmdApp::Config.new("test app", "1.2.3", app_command: "testapp")
|
106
|
+
@builder = Benry::CmdApp::BaseHelpBuilder.new(@config)
|
107
|
+
end
|
46
108
|
|
47
109
|
|
48
110
|
topic '#build_help_message()' do
|
49
111
|
|
50
|
-
spec "[!
|
51
|
-
|
52
|
-
|
112
|
+
spec "[!0hy81] this is an abstract method." do
|
113
|
+
pr = proc { @builder.build_help_message(nil) }
|
114
|
+
ok {pr}.raise?(NotImplementedError,
|
115
|
+
"Benry::CmdApp::BaseHelpBuilder#build_help_message(): not implemented yet.")
|
116
|
+
end
|
53
117
|
|
54
|
-
|
118
|
+
end
|
55
119
|
|
56
|
-
Usage:
|
57
|
-
$ testapp halo1 [<options>] [<user>]
|
58
120
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
msg = metadata.help_message("testapp")
|
66
|
-
msg = uncolorize(msg)
|
67
|
-
ok {msg} == expected
|
68
|
-
end
|
121
|
+
topic '#render_section()' do
|
122
|
+
|
123
|
+
spec "[!61psk] returns section string with decorating header." do
|
124
|
+
s = @builder.__send__(:render_section, "Document:", "http://example.com/doc/\n")
|
125
|
+
ok {s} == ("\e[1;34mDocument:\e[0m\n" \
|
126
|
+
"http://example.com/doc/\n")
|
69
127
|
end
|
70
128
|
|
71
|
-
spec "[!
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
ok {
|
76
|
-
" $ testapp halo1 [<user>]\n")
|
77
|
-
#
|
78
|
-
schema = new_schema(lang: true)
|
79
|
-
msg = new_metadata(schema).help_message("testapp")
|
80
|
-
msg = uncolorize(msg)
|
81
|
-
ok {msg}.include?("Usage:\n" +
|
82
|
-
" $ testapp halo1 [<options>] [<user>]\n")
|
129
|
+
spec "[!0o8w4] appends '\n' to content if it doesn't end with '\n'." do
|
130
|
+
s = @builder.__send__(:render_section, "Document:", "http://...")
|
131
|
+
ok {s} == ("\e[1;34mDocument:\e[0m\n" \
|
132
|
+
"http://...\n")
|
133
|
+
ok {s}.end_with?("\n")
|
83
134
|
end
|
84
135
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
ok {
|
136
|
+
end
|
137
|
+
|
138
|
+
|
139
|
+
topic '#render_sections()' do
|
140
|
+
|
141
|
+
spec "[!tqau1] returns nil if value is nil or empty." do
|
142
|
+
ok {@builder.__send__(:render_sections, nil, 'config.app_postamble')} == nil
|
143
|
+
ok {@builder.__send__(:render_sections, [] , 'config.app_postamble')} == nil
|
144
|
+
end
|
145
|
+
|
146
|
+
spec "[!ezb0d] returns value unchanged if value is a string." do
|
147
|
+
ok {@builder.__send__(:render_sections, "ABC\n", 'xxx')} == "ABC\n"
|
92
148
|
end
|
93
149
|
|
94
|
-
spec "[!
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
ok {msg} =~ /^Usage:\n \$ testapp halo3 \[<options>\]$/
|
150
|
+
spec "[!gipxn] builds sections of help message if value is a hash object." do
|
151
|
+
ok {@builder.__send__(:render_sections, {"Doc:"=>"ABC\n"}, 'xxx')} == <<"END"
|
152
|
+
\e[1;34mDoc:\e[0m
|
153
|
+
ABC
|
154
|
+
END
|
100
155
|
end
|
101
156
|
|
102
|
-
spec "[!
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
ok {msg}.include?("Options:\n" +
|
107
|
-
" -l, --lang=<en|fr|it> : language\n")
|
157
|
+
spec "[!944rt] raises ActionError if unexpected value found in value." do
|
158
|
+
pr = proc { @builder.__send__(:render_sections, 123, 'xxx') }
|
159
|
+
ok {pr}.raise?(Benry::CmdApp::ActionError,
|
160
|
+
"123: Unexpected value found in `xxx`.")
|
108
161
|
end
|
109
162
|
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
163
|
+
end
|
164
|
+
|
165
|
+
|
166
|
+
topic '#render_option_help()' do
|
167
|
+
|
168
|
+
before do
|
169
|
+
@schema = Benry::CmdApp::ACTION_OPTION_SCHEMA_CLASS.new()
|
170
|
+
#@schema.add(:help , "-h, --help" , "help message")
|
171
|
+
@schema.add(:silent, "-s, --silent", "silent mode")
|
172
|
+
@schema.add(:file , "-f <file>" , "filename")
|
173
|
+
@schema.add(:debug , " --debug" , "debug mode", hidden: true)
|
174
|
+
config = Benry::CmdApp::Config.new("test app", "1.2.3")
|
175
|
+
@format = config.format_option
|
115
176
|
end
|
116
177
|
|
117
|
-
spec "[!
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
178
|
+
spec "[!muhem] returns option part of help message." do
|
179
|
+
x = @builder.__send__(:render_option_help, @schema, @format)
|
180
|
+
ok {x} == <<"END"
|
181
|
+
-s, --silent : silent mode
|
182
|
+
-f <file> : filename
|
183
|
+
END
|
123
184
|
end
|
124
185
|
|
125
|
-
spec "[!
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
\e[34mOptions:\e[0m
|
132
|
-
\e[1m-f, --file=<file> \e[0m : filename
|
133
|
-
\e[1m\e[2m-l, --lang=<lang>\e[0m \e[0m : language
|
186
|
+
spec "[!4z70n] includes hidden options when `all: true` passed." do
|
187
|
+
x = @builder.__send__(:render_option_help, @schema, @format, all: true)
|
188
|
+
ok {x} == <<"END"
|
189
|
+
-s, --silent : silent mode
|
190
|
+
-f <file> : filename
|
191
|
+
\e[2m --debug : debug mode\e[0m
|
134
192
|
END
|
135
193
|
end
|
136
194
|
|
137
|
-
spec "[!
|
138
|
-
schema
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
195
|
+
spec "[!hxy1f] includes `detail:` kwarg value with indentation." do
|
196
|
+
@schema.add(:mode, "-m <mode>", "output mode", detail: <<END)
|
197
|
+
- v, verbose: print many output
|
198
|
+
- q, quiet: print litte output
|
199
|
+
- c, compact: print summary output
|
200
|
+
END
|
201
|
+
#
|
202
|
+
x = @builder.__send__(:render_option_help, @schema, @format)
|
203
|
+
ok {x} == <<"END"
|
204
|
+
-s, --silent : silent mode
|
205
|
+
-f <file> : filename
|
206
|
+
-m <mode> : output mode
|
207
|
+
- v, verbose: print many output
|
208
|
+
- q, quiet: print litte output
|
209
|
+
- c, compact: print summary output
|
210
|
+
END
|
211
|
+
#
|
212
|
+
x = @builder.__send__(:render_option_help, @schema, " %-15s # %s")
|
213
|
+
ok {x} == <<"END"
|
214
|
+
-s, --silent # silent mode
|
215
|
+
-f <file> # filename
|
216
|
+
-m <mode> # output mode
|
217
|
+
- v, verbose: print many output
|
218
|
+
- q, quiet: print litte output
|
219
|
+
- c, compact: print summary output
|
148
220
|
END
|
149
221
|
end
|
150
222
|
|
151
|
-
spec "[!
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
msg = uncolorize(msg)
|
157
|
-
ok {msg} == <<END
|
158
|
-
testapp halo1 -- greeting
|
223
|
+
spec "[!jcqdf] returns nil if no options." do
|
224
|
+
schema = Benry::CmdApp::ACTION_OPTION_SCHEMA_CLASS.new()
|
225
|
+
x = @builder.__send__(:render_option_help, schema, @format)
|
226
|
+
ok {x} == nil
|
227
|
+
end
|
159
228
|
|
160
|
-
|
161
|
-
$ testapp halo1 [<user>]
|
229
|
+
end
|
162
230
|
|
163
|
-
|
164
|
-
|
231
|
+
|
232
|
+
topic '#decorate_command()' do
|
233
|
+
|
234
|
+
spec "[!zffx5] decorates command string." do
|
235
|
+
x = @builder.__send__(:decorate_command, "cmdname")
|
236
|
+
ok {x} == "\e[1mcmdname\e[0m"
|
237
|
+
end
|
238
|
+
|
239
|
+
end
|
240
|
+
|
241
|
+
|
242
|
+
topic '#decorate_header()' do
|
243
|
+
|
244
|
+
spec "[!4ufhw] decorates header string." do
|
245
|
+
x = @builder.__send__(:decorate_header, "Header:")
|
246
|
+
ok {x} == "\e[1;34mHeader:\e[0m"
|
247
|
+
end
|
248
|
+
|
249
|
+
end
|
250
|
+
|
251
|
+
|
252
|
+
topic '#decorate_extra()' do
|
253
|
+
|
254
|
+
spec "[!9nch4] decorates extra string." do
|
255
|
+
x = @builder.__send__(:decorate_extra, "(default: 'git')")
|
256
|
+
ok {x} == "\e[2m(default: 'git')\e[0m"
|
165
257
|
end
|
166
258
|
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
259
|
+
end
|
260
|
+
|
261
|
+
|
262
|
+
topic '#decorate_str()' do
|
263
|
+
|
264
|
+
spec "[!9qesd] decorates string if `hidden` is true." do
|
265
|
+
b = @builder
|
266
|
+
ok {b.__send__(:decorate_str, "FOOBAR", true, nil)} == "\e[2mFOOBAR\e[0m"
|
267
|
+
ok {b.__send__(:decorate_str, "FOOBAR", false, nil)} == "FOOBAR"
|
268
|
+
ok {b.__send__(:decorate_str, "FOOBAR", nil, nil)} == "FOOBAR"
|
173
269
|
end
|
174
270
|
|
175
|
-
spec "[!
|
176
|
-
|
177
|
-
|
178
|
-
msg = metadata.help_message("testapp")
|
179
|
-
msg = uncolorize(msg)
|
180
|
-
ok {msg} =~ /^ \$ testapp args1 <aa> <bb>$/
|
271
|
+
spec "[!uql2d] decorates string if `important` is true." do
|
272
|
+
b = @builder
|
273
|
+
ok {b.__send__(:decorate_str, "FOOBAR", nil, true)} == "\e[1mFOOBAR\e[0m"
|
181
274
|
end
|
182
275
|
|
183
|
-
spec "[!
|
184
|
-
|
185
|
-
|
186
|
-
msg = without_tty { metadata.help_message("testapp") }
|
187
|
-
msg = uncolorize(msg)
|
188
|
-
ok {msg} =~ /^ \$ testapp args2 <aa> \[<bb> \[<cc>\]\]$/
|
276
|
+
spec "[!mdhhr] decorates string if `important` is false." do
|
277
|
+
b = @builder
|
278
|
+
ok {b.__send__(:decorate_str, "FOOBAR", nil, false)} == "\e[2mFOOBAR\e[0m"
|
189
279
|
end
|
190
280
|
|
191
|
-
spec "[!
|
192
|
-
|
193
|
-
|
194
|
-
msg = metadata.help_message("testapp")
|
195
|
-
msg = uncolorize(msg)
|
196
|
-
ok {msg} =~ /^ \$ testapp args3 <aa> \[<bb> \[<cc> \[<dd>...\]\]\]$/
|
281
|
+
spec "[!6uzbi] not decorates string if `hidden` is falthy and `important` is nil." do
|
282
|
+
b = @builder
|
283
|
+
ok {b.__send__(:decorate_str, "FOOBAR", nil, nil)} == "FOOBAR"
|
197
284
|
end
|
198
285
|
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
286
|
+
end
|
287
|
+
|
288
|
+
|
289
|
+
topic '#header()' do
|
290
|
+
|
291
|
+
spec "[!ep064] returns constant value defined in the class." do
|
292
|
+
b = Benry::CmdApp::BaseHelpBuilder.new(nil)
|
293
|
+
ok {b.__send__(:header, :HEADER_ACTIONS)} == "Actions:"
|
205
294
|
end
|
206
295
|
|
207
|
-
spec "[!
|
208
|
-
|
209
|
-
|
210
|
-
msg = metadata.help_message("testapp")
|
211
|
-
msg = uncolorize(msg)
|
212
|
-
ok {msg} =~ /^ \$ testapp args5 <_xx-yy-zz>$/
|
296
|
+
spec "[!viwtn] constant value defined in child class is prior to one defined in parent class." do
|
297
|
+
b = HelpTestBuilder.new(nil)
|
298
|
+
ok {b.__send__(:header, :HEADER_ACTIONS)} == "<ACTIONS>"
|
213
299
|
end
|
214
300
|
|
215
301
|
end
|
@@ -218,534 +304,949 @@ END
|
|
218
304
|
end
|
219
305
|
|
220
306
|
|
221
|
-
topic Benry::CmdApp::
|
222
|
-
include CommonTestingHelper
|
307
|
+
topic Benry::CmdApp::ApplicationHelpBuilder do
|
223
308
|
|
224
309
|
before do
|
225
|
-
@config = Benry::CmdApp::Config.new("test app", "1.
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
@schema = Benry::CmdApp::AppOptionSchema.new(@config)
|
233
|
-
@builder = Benry::CmdApp::AppHelpBuilder.new(@config, @schema)
|
310
|
+
@config = Benry::CmdApp::Config.new("test app", "1.2.3",
|
311
|
+
app_name: "TestApp", app_command: "testapp",
|
312
|
+
help_description: "This is a description of application.",
|
313
|
+
option_verbose: true, option_quiet: true,
|
314
|
+
option_color: true, #option_debug: true,
|
315
|
+
option_trace: true)
|
316
|
+
@builder = new_builder()
|
234
317
|
end
|
235
318
|
|
319
|
+
def new_builder(config=nil)
|
320
|
+
return Benry::CmdApp::ApplicationHelpBuilder.new(config || @config)
|
321
|
+
end
|
322
|
+
|
323
|
+
|
236
324
|
topic '#build_help_message()' do
|
237
325
|
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
326
|
+
spec "[!ezcs4] returns help message string of application." do
|
327
|
+
gschema = Benry::CmdApp::GLOBAL_OPTION_SCHEMA_CLASS.new(@config)
|
328
|
+
actual = @builder.build_help_message(gschema)
|
329
|
+
expected = <<"END"
|
330
|
+
\e[1mTestApp\e[0m \e[2m(1.2.3)\e[0m --- test app
|
331
|
+
|
332
|
+
\e[1;34mUsage:\e[0m
|
333
|
+
$ \e[1mtestapp\e[0m [<options>] <action> [<arguments>...]
|
334
|
+
|
335
|
+
\e[1;34mDescription:\e[0m
|
336
|
+
This is a description of application.
|
337
|
+
|
338
|
+
\e[1;34mOptions:\e[0m
|
339
|
+
-h, --help : print help message (of action if specified)
|
340
|
+
-V, --version : print version
|
341
|
+
-l, --list : list actions and aliases
|
342
|
+
-a, --all : list hidden actions/options, too
|
343
|
+
-v, --verbose : verbose mode
|
344
|
+
-q, --quiet : quiet mode
|
345
|
+
--color[=<on|off>] : color mode
|
346
|
+
-T, --trace : trace mode
|
347
|
+
|
348
|
+
\e[1;34mActions:\e[0m
|
349
|
+
END
|
350
|
+
ok {actual}.start_with?(expected)
|
351
|
+
ok {actual} !~ /^ *--debug/
|
251
352
|
end
|
252
353
|
|
253
|
-
|
354
|
+
spec "[!ntj2y] includes hidden actions and options if `all: true` passed." do
|
355
|
+
@config.option_debug = true
|
356
|
+
gschema = Benry::CmdApp::GLOBAL_OPTION_SCHEMA_CLASS.new(@config)
|
357
|
+
actual = @builder.build_help_message(gschema)
|
358
|
+
expected = <<"END"
|
359
|
+
\e[1mTestApp\e[0m \e[2m(1.2.3)\e[0m --- test app
|
254
360
|
|
255
|
-
|
256
|
-
|
361
|
+
\e[1;34mUsage:\e[0m
|
362
|
+
$ \e[1mtestapp\e[0m [<options>] <action> [<arguments>...]
|
363
|
+
|
364
|
+
\e[1;34mDescription:\e[0m
|
365
|
+
This is a description of application.
|
366
|
+
|
367
|
+
\e[1;34mOptions:\e[0m
|
368
|
+
-h, --help : print help message (of action if specified)
|
369
|
+
-V, --version : print version
|
370
|
+
-l, --list : list actions and aliases
|
371
|
+
-a, --all : list hidden actions/options, too
|
372
|
+
-v, --verbose : verbose mode
|
373
|
+
-q, --quiet : quiet mode
|
374
|
+
--color[=<on|off>] : color mode
|
375
|
+
--debug : debug mode
|
376
|
+
-T, --trace : trace mode
|
377
|
+
|
378
|
+
\e[1;34mActions:\e[0m
|
379
|
+
END
|
380
|
+
ok {actual}.start_with?(expected)
|
381
|
+
ok {actual} =~ /^ +--debug +: debug mode$/
|
257
382
|
end
|
258
383
|
|
259
|
-
|
260
|
-
|
384
|
+
end
|
385
|
+
|
386
|
+
|
387
|
+
topic '#section_preamble()' do
|
388
|
+
|
389
|
+
spec "[!51v42] returns preamble part of application help message." do
|
390
|
+
x = @builder.__send__(:section_preamble)
|
391
|
+
ok {x} == "\e[1mTestApp\e[0m \e[2m(1.2.3)\e[0m --- test app\n"
|
261
392
|
end
|
262
393
|
|
263
|
-
|
264
|
-
|
394
|
+
spec "[!bmh17] includes `config.app_name` or `config.app_command` into preamble." do
|
395
|
+
@config.app_name = "TestApp"
|
396
|
+
@config.app_command = "testapp"
|
397
|
+
x = @builder.__send__(:section_preamble)
|
398
|
+
ok {x} == "\e[1mTestApp\e[0m \e[2m(1.2.3)\e[0m --- test app\n"
|
399
|
+
#
|
400
|
+
@config.app_name = nil
|
401
|
+
x = @builder.__send__(:section_preamble)
|
402
|
+
ok {x} == "\e[1mtestapp\e[0m \e[2m(1.2.3)\e[0m --- test app\n"
|
403
|
+
end
|
265
404
|
|
266
|
-
|
267
|
-
|
405
|
+
spec "[!opii8] includes `config.app_versoin` into preamble if it is set." do
|
406
|
+
@config.app_version = "3.4.5"
|
407
|
+
x = @builder.__send__(:section_preamble)
|
408
|
+
ok {x} == "\e[1mTestApp\e[0m \e[2m(3.4.5)\e[0m --- test app\n"
|
409
|
+
#
|
410
|
+
@config.app_version = nil
|
411
|
+
x = @builder.__send__(:section_preamble)
|
412
|
+
ok {x} == "\e[1mTestApp\e[0m --- test app\n"
|
413
|
+
end
|
268
414
|
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
415
|
+
spec "[!3h380] includes `config.app_detail` into preamble if it is set." do
|
416
|
+
@config.app_detail = "https://www.example.com/"
|
417
|
+
x = @builder.__send__(:section_preamble)
|
418
|
+
ok {x} == <<"END"
|
419
|
+
\e[1mTestApp\e[0m \e[2m(1.2.3)\e[0m --- test app
|
274
420
|
|
275
|
-
|
276
|
-
\e[1mya:ya \e[0m : greeting #2
|
277
|
-
\e[1myes \e[0m : alias of 'yo-yo' action
|
278
|
-
\e[1myo-yo \e[0m : greeting #1
|
421
|
+
https://www.example.com/
|
279
422
|
END
|
423
|
+
end
|
280
424
|
|
281
|
-
|
282
|
-
TestApp (1.0.0) -- test app
|
425
|
+
end
|
283
426
|
|
284
|
-
Usage:
|
285
|
-
$ testapp [<options>] [<action> [<arguments>...]]
|
286
427
|
|
287
|
-
|
288
|
-
-h, --help : print help message
|
289
|
-
-V, --version : print version
|
290
|
-
-a, --all : list all actions including private (hidden) ones
|
291
|
-
-D, --debug : debug mode (set $DEBUG_MODE to true)
|
428
|
+
topic '#section_postamble()' do
|
292
429
|
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
430
|
+
spec "[!64hj1] returns postamble of application help message." do
|
431
|
+
@config.help_postamble = [
|
432
|
+
{"Examples:" => " $ echo yes\n yes\n"},
|
433
|
+
"(Tips: blablabla)",
|
434
|
+
]
|
435
|
+
x = @builder.__send__(:section_postamble)
|
436
|
+
ok {x} == <<"END"
|
437
|
+
\e[1;34mExamples:\e[0m
|
438
|
+
$ echo yes
|
439
|
+
yes
|
440
|
+
|
441
|
+
(Tips: blablabla)
|
297
442
|
END
|
443
|
+
end
|
298
444
|
|
299
|
-
spec "[!
|
300
|
-
|
301
|
-
|
302
|
-
msg_mono = uncolorize(msg)
|
303
|
-
ok {msg_mono} == expected_mono
|
304
|
-
ok {msg_color} == expected_color
|
445
|
+
spec "[!z5k2w] returns nil if postamble not set." do
|
446
|
+
x = @builder.__send__(:section_postamble)
|
447
|
+
ok {x} == nil
|
305
448
|
end
|
306
449
|
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
450
|
+
end
|
451
|
+
|
452
|
+
|
453
|
+
topic '#section_usage()' do
|
454
|
+
|
455
|
+
spec "[!h98me] returns 'Usage:' section of application help message." do
|
456
|
+
x = @builder.__send__(:section_usage)
|
457
|
+
ok {x} == <<"END"
|
458
|
+
\e[1;34mUsage:\e[0m
|
459
|
+
$ \e[1mtestapp\e[0m [<options>] <action> [<arguments>...]
|
460
|
+
END
|
313
461
|
end
|
314
462
|
|
315
|
-
spec "[!
|
316
|
-
@config.
|
317
|
-
|
318
|
-
|
319
|
-
|
463
|
+
spec "[!i9d4r] includes `config.app_usage` into help message if it is set." do
|
464
|
+
@config.app_usage = "<command> [<args>...]"
|
465
|
+
x = @builder.__send__(:section_usage)
|
466
|
+
ok {x} == <<"END"
|
467
|
+
\e[1;34mUsage:\e[0m
|
468
|
+
$ \e[1mtestapp\e[0m [<options>] <command> [<args>...]
|
469
|
+
END
|
320
470
|
end
|
321
471
|
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
472
|
+
end
|
473
|
+
|
474
|
+
|
475
|
+
topic '#section_description()' do
|
476
|
+
|
477
|
+
spec "[!qarrk] returns 'Description:' section if `config.help_description` is set." do
|
478
|
+
@config.help_description = "This is a description of application."
|
479
|
+
str = @builder.__send__(:section_description)
|
480
|
+
ok {str} == <<~"END"
|
481
|
+
\e[1;34mDescription:\e[0m
|
482
|
+
This is a description of application.
|
483
|
+
END
|
327
484
|
end
|
328
485
|
|
329
|
-
spec "[!
|
330
|
-
@config.
|
331
|
-
|
332
|
-
|
333
|
-
ok {msg} =~ /^TestApp \(1\.2\.3\) -- test app$/
|
334
|
-
#
|
335
|
-
@config.app_version = nil
|
336
|
-
msg = @builder.build_help_message()
|
337
|
-
msg = uncolorize(msg)
|
338
|
-
ok {msg} =~ /^TestApp -- test app$/
|
486
|
+
spec "[!ealol] returns nil if `config.help_description` is nil." do
|
487
|
+
@config.help_description = nil
|
488
|
+
str = @builder.__send__(:section_description)
|
489
|
+
ok {str} == nil
|
339
490
|
end
|
340
491
|
|
341
|
-
|
342
|
-
|
343
|
-
msg = @builder.build_help_message()
|
344
|
-
msg = uncolorize(msg)
|
345
|
-
ok {msg}.start_with?(<<END)
|
346
|
-
TestApp (1.0.0) -- test app
|
492
|
+
end
|
493
|
+
|
347
494
|
|
348
|
-
|
495
|
+
topic '#section_options()' do
|
349
496
|
|
350
|
-
|
497
|
+
spec "[!f2n70] returns 'Options:' section of application help message." do
|
498
|
+
gschema = Benry::CmdApp::GLOBAL_OPTION_SCHEMA_CLASS.new(@config)
|
499
|
+
x = @builder.__send__(:section_options, gschema)
|
500
|
+
ok {x} == <<"END"
|
501
|
+
\e[1;34mOptions:\e[0m
|
502
|
+
-h, --help : print help message (of action if specified)
|
503
|
+
-V, --version : print version
|
504
|
+
-l, --list : list actions and aliases
|
505
|
+
-a, --all : list hidden actions/options, too
|
506
|
+
-v, --verbose : verbose mode
|
507
|
+
-q, --quiet : quiet mode
|
508
|
+
--color[=<on|off>] : color mode
|
509
|
+
-T, --trace : trace mode
|
351
510
|
END
|
352
|
-
|
353
|
-
|
354
|
-
msg = @builder.build_help_message()
|
355
|
-
msg = uncolorize(msg)
|
356
|
-
ok {msg}.start_with?(<<END)
|
357
|
-
TestApp (1.0.0) -- test app
|
511
|
+
ok {x} !~ /--debug/
|
512
|
+
end
|
358
513
|
|
359
|
-
|
514
|
+
spec "[!0bboq] includes hidden options into help message if `all: true` passed." do
|
515
|
+
gschema = Benry::CmdApp::GLOBAL_OPTION_SCHEMA_CLASS.new(@config)
|
516
|
+
x = @builder.__send__(:section_options, gschema, all: true)
|
517
|
+
ok {x} == <<"END"
|
518
|
+
\e[1;34mOptions:\e[0m
|
519
|
+
-h, --help : print help message (of action if specified)
|
520
|
+
-V, --version : print version
|
521
|
+
-l, --list : list actions and aliases
|
522
|
+
\e[2m -L <topic> : topic list (actions|aliases|categories|abbrevs)\e[0m
|
523
|
+
-a, --all : list hidden actions/options, too
|
524
|
+
-v, --verbose : verbose mode
|
525
|
+
-q, --quiet : quiet mode
|
526
|
+
--color[=<on|off>] : color mode
|
527
|
+
\e[2m --debug : debug mode\e[0m
|
528
|
+
-T, --trace : trace mode
|
360
529
|
END
|
530
|
+
ok {x} =~ /--debug/
|
361
531
|
end
|
362
532
|
|
363
|
-
spec "[!
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
ok {msg}.start_with?(<<END)
|
369
|
-
See https://...
|
533
|
+
spec "[!fjhow] returns nil if no options." do
|
534
|
+
gschema = Benry::CmdApp::ACTION_OPTION_SCHEMA_CLASS.new
|
535
|
+
x = @builder.__send__(:section_options, gschema)
|
536
|
+
ok {x} == nil
|
537
|
+
end
|
370
538
|
|
371
|
-
|
372
|
-
$ testapp [<options>] [<action> [<arguments>...]]
|
539
|
+
end
|
373
540
|
|
374
|
-
|
541
|
+
|
542
|
+
topic '#section_actions()' do
|
543
|
+
|
544
|
+
spec "[!typ67] returns 'Actions:' section of help message." do
|
545
|
+
x = @builder.__send__(:section_actions)
|
546
|
+
ok {x} =~ /\A\e\[1;34mActions:\e\[0m$/
|
375
547
|
end
|
376
548
|
|
377
|
-
spec "[!
|
378
|
-
@
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
549
|
+
spec "[!yn8ea] includes hidden actions into help message if `all: true` passed." do
|
550
|
+
x = @builder.__send__(:section_actions, all: true)
|
551
|
+
ok {x} =~ /debuginfo/
|
552
|
+
ok {x} =~ /^\e\[2m debuginfo : hidden action\e\[0m$/
|
553
|
+
#
|
554
|
+
x = @builder.__send__(:section_actions)
|
555
|
+
ok {x} !~ /debuginfo/
|
556
|
+
end
|
557
|
+
|
558
|
+
spec "[!10qp0] includes aliases if the 1st argument is true." do
|
559
|
+
x = @builder.__send__(:section_actions, true, all: true)
|
560
|
+
ok {x} =~ /\(alias: /
|
561
|
+
#
|
562
|
+
x = @builder.__send__(:section_actions, false, all: true)
|
563
|
+
ok {x} !~ /\(alias: /
|
564
|
+
end
|
385
565
|
|
566
|
+
spec "[!24by5] returns nil if no actions defined." do
|
567
|
+
debuginfo_md = Benry::CmdApp::REGISTRY.metadata_get("debuginfo")
|
568
|
+
hello_md = Benry::CmdApp::REGISTRY.metadata_get("hello")
|
569
|
+
registry = Benry::CmdApp::Registry.new()
|
570
|
+
with_dummy_registry(registry) do
|
571
|
+
builder = new_builder()
|
572
|
+
#
|
573
|
+
x = builder.__send__(:section_actions)
|
574
|
+
ok {x} == nil
|
575
|
+
#
|
576
|
+
registry.metadata_add(debuginfo_md)
|
577
|
+
x = builder.__send__(:section_actions)
|
578
|
+
ok {x} == nil
|
579
|
+
x = builder.__send__(:section_actions, all: true)
|
580
|
+
ok {x} == <<"END"
|
581
|
+
\e[1;34mActions:\e[0m
|
582
|
+
\e[2m debuginfo : hidden action\e[0m
|
386
583
|
END
|
584
|
+
#
|
585
|
+
registry.metadata_add(hello_md)
|
586
|
+
x = builder.__send__(:section_actions)
|
587
|
+
ok {x} == <<"END"
|
588
|
+
\e[1;34mActions:\e[0m
|
589
|
+
hello : greeting message
|
590
|
+
END
|
591
|
+
x = builder.__send__(:section_actions, all: true)
|
592
|
+
ok {x} == <<"END"
|
593
|
+
\e[1;34mActions:\e[0m
|
594
|
+
\e[2m debuginfo : hidden action\e[0m
|
595
|
+
hello : greeting message
|
596
|
+
END
|
597
|
+
end
|
598
|
+
end
|
599
|
+
|
600
|
+
spec "[!8qz6a] adds default action name after header if it is set." do
|
601
|
+
@config.default_action = "help"
|
602
|
+
x = @builder.__send__(:section_actions)
|
603
|
+
ok {x} =~ /\A\e\[1;34mActions:\e\[0m \e\[2m\(default: help\)\e\[0m$/
|
604
|
+
#
|
605
|
+
@config.default_action = "hello"
|
606
|
+
x = @builder.__send__(:section_actions)
|
607
|
+
ok {x} =~ /\A\e\[1;34mActions:\e\[0m \e\[2m\(default: hello\)\e\[0m$/
|
608
|
+
end
|
609
|
+
|
610
|
+
end
|
611
|
+
|
612
|
+
|
613
|
+
topic '#_render_metadata_list()' do
|
614
|
+
|
615
|
+
spec "[!iokkp] builds list of actions or aliases." do
|
616
|
+
format = "%s : %s"
|
617
|
+
output = @builder.__send__(:_render_metadata_list, format) { true }
|
618
|
+
ok {output} =~ /^hello : greeting message$/
|
619
|
+
end
|
620
|
+
|
621
|
+
spec "[!grwkj] filters by block." do
|
622
|
+
format = "%s : %s"
|
623
|
+
output = @builder.__send__(:_render_metadata_list, format) {|md| md.alias? }
|
624
|
+
ok {output} !~ /^hello : greeting message$/
|
625
|
+
ok {output} =~ /alias for/
|
626
|
+
output = @builder.__send__(:_render_metadata_list, format) {|md| ! md.alias? }
|
627
|
+
ok {output} =~ /^hello : greeting message$/
|
628
|
+
ok {output} !~ /alias for/
|
387
629
|
end
|
388
630
|
|
389
|
-
spec "[!
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
631
|
+
spec "[!hv7or] if action has any aliases, print them below of the action." do
|
632
|
+
format = " %-18s : %s"
|
633
|
+
include_aliases = true
|
634
|
+
output = @builder.instance_eval{
|
635
|
+
_render_metadata_list(format, include_aliases) {|md| ! md.alias? }
|
636
|
+
}
|
637
|
+
ok {output} =~ /^\e\[2m +\(alias: .*\)\e\[0m$/
|
638
|
+
end
|
639
|
+
|
640
|
+
end
|
641
|
+
|
642
|
+
|
643
|
+
topic '#section_availables()' do
|
644
|
+
|
645
|
+
spec "[!pz0cu] includes 'Actions:' and 'Aliases:' sections." do
|
646
|
+
output = @builder.section_availables()
|
647
|
+
ok {output} =~ /\A\e\[1;34mActions:\e\[0m\n/
|
648
|
+
ok {output} =~ /\n\n\e\[1;34mAliases:\e\[0m\n/
|
649
|
+
end
|
650
|
+
|
651
|
+
end
|
396
652
|
|
397
|
-
Usage:
|
398
|
-
$ greatcmd [<options>] [<action> [<arguments>...]]
|
399
653
|
|
400
|
-
|
654
|
+
topic '#section_candidates()' do
|
655
|
+
|
656
|
+
spec "[!3c3f1] returns list of actions which name starts with prefix specified." do
|
657
|
+
x = @builder.section_candidates("git:")
|
658
|
+
ok {x} == <<"END"
|
659
|
+
\e[1;34mActions:\e[0m
|
660
|
+
git:stage : same as `git add -p`
|
661
|
+
git:staged : same as `git diff --cached`
|
662
|
+
git:unstage : same as `git reset HEAD`
|
401
663
|
END
|
402
664
|
end
|
403
665
|
|
404
|
-
spec "[!
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
-a, --all : list all actions including private (hidden) ones
|
415
|
-
-D, --debug : debug mode (set $DEBUG_MODE to true)
|
666
|
+
spec "[!idm2h] includes hidden actions when `all: true` passed." do
|
667
|
+
x = @builder.section_candidates("git:", all: true)
|
668
|
+
ok {x} == <<"END"
|
669
|
+
\e[1;34mActions:\e[0m
|
670
|
+
\e[2m git:correct : same as `git commit --amend`\e[0m
|
671
|
+
git:stage : same as `git add -p`
|
672
|
+
git:staged : same as `git diff --cached`
|
673
|
+
git:unstage : same as `git reset HEAD`
|
674
|
+
END
|
675
|
+
end
|
416
676
|
|
417
|
-
|
677
|
+
spec "[!duhyd] includes actions which name is same as prefix." do
|
678
|
+
HelpTestAction.class_eval do
|
679
|
+
category "p8572:", action: "aaa" do
|
680
|
+
@action.("AAA")
|
681
|
+
def aaa()
|
682
|
+
end
|
683
|
+
@action.("BBB")
|
684
|
+
def bbb()
|
685
|
+
end
|
686
|
+
end
|
687
|
+
@action.("sample")
|
688
|
+
def p8572x()
|
689
|
+
end
|
690
|
+
end
|
691
|
+
x = @builder.section_candidates("p8572:")
|
692
|
+
ok {x} == <<"END"
|
693
|
+
\e[1;34mActions:\e[0m
|
694
|
+
p8572 : AAA
|
695
|
+
p8572:bbb : BBB
|
418
696
|
END
|
419
|
-
|
420
|
-
@config.app_version = nil
|
421
|
-
@config.option_debug = false
|
422
|
-
app = Benry::CmdApp::Application.new(@config)
|
423
|
-
msg = without_tty { app.help_message() }
|
424
|
-
msg = uncolorize(msg)
|
425
|
-
ok {msg}.include?(<<END)
|
426
|
-
Options:
|
427
|
-
-h, --help : print help message
|
428
|
-
-a, --all : list all actions including private (hidden) ones
|
697
|
+
end
|
429
698
|
|
430
|
-
|
699
|
+
spec "[!nwwrd] if prefix is 'xxx:' and alias name is 'xxx' and action name of alias matches to 'xxx:', skip it because it will be shown in 'Aliases:' section." do
|
700
|
+
Benry::CmdApp.define_alias("git", "git:stage")
|
701
|
+
at_end { Benry::CmdApp.undef_alias("git") }
|
702
|
+
x = @builder.section_candidates("git:")
|
703
|
+
ok {x} == <<"END"
|
704
|
+
\e[1;34mActions:\e[0m
|
705
|
+
git:stage : same as `git add -p`
|
706
|
+
\e[2m (alias: git)\e[0m
|
707
|
+
git:staged : same as `git diff --cached`
|
708
|
+
git:unstage : same as `git reset HEAD`
|
709
|
+
|
710
|
+
\e[1;34mAliases:\e[0m
|
711
|
+
git : alias for 'git:stage'
|
431
712
|
END
|
432
713
|
end
|
433
714
|
|
434
|
-
spec "[!
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
715
|
+
spec "[!otvbt] includes name of alias which corresponds to action starting with prefix." do
|
716
|
+
Benry::CmdApp.define_alias("add", "git:stage")
|
717
|
+
at_end { Benry::CmdApp.undef_alias("add") }
|
718
|
+
x = @builder.section_candidates("git:")
|
719
|
+
ok {x} == <<"END"
|
720
|
+
\e[1;34mActions:\e[0m
|
721
|
+
git:stage : same as `git add -p`
|
722
|
+
\e[2m (alias: add)\e[0m
|
723
|
+
git:staged : same as `git diff --cached`
|
724
|
+
git:unstage : same as `git reset HEAD`
|
725
|
+
|
726
|
+
\e[1;34mAliases:\e[0m
|
727
|
+
add : alias for 'git:stage'
|
728
|
+
END
|
729
|
+
end
|
447
730
|
|
448
|
-
|
731
|
+
spec "[!h5ek7] includes hidden aliases when `all: true` passed." do
|
732
|
+
Benry::CmdApp.define_alias("add", "git:stage", hidden: true)
|
733
|
+
at_end { Benry::CmdApp.undef_alias("add") }
|
734
|
+
x = @builder.section_candidates("git:", all: true)
|
735
|
+
ok {x} == <<"END"
|
736
|
+
\e[1;34mActions:\e[0m
|
737
|
+
\e[2m git:correct : same as `git commit --amend`\e[0m
|
738
|
+
git:stage : same as `git add -p`
|
739
|
+
\e[2m (alias: add)\e[0m
|
740
|
+
git:staged : same as `git diff --cached`
|
741
|
+
git:unstage : same as `git reset HEAD`
|
742
|
+
|
743
|
+
\e[1;34mAliases:\e[0m
|
744
|
+
\e[2m add : alias for 'git:stage'\e[0m
|
745
|
+
END
|
746
|
+
#
|
747
|
+
x = @builder.section_candidates("git:")
|
748
|
+
ok {x} == <<"END"
|
749
|
+
\e[1;34mActions:\e[0m
|
750
|
+
git:stage : same as `git add -p`
|
751
|
+
\e[2m (alias: add)\e[0m
|
752
|
+
git:staged : same as `git diff --cached`
|
753
|
+
git:unstage : same as `git reset HEAD`
|
449
754
|
END
|
450
755
|
end
|
451
756
|
|
452
|
-
spec "[!
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
757
|
+
spec "[!9lnn2] alias names in candidate list are sorted by action name." do
|
758
|
+
HelpTestAction.class_eval do
|
759
|
+
category "c7784:" do
|
760
|
+
@action.("#5")
|
761
|
+
def a7784_5(); end
|
762
|
+
@action.("#3")
|
763
|
+
def a7784_3(); end
|
764
|
+
@action.("#1")
|
765
|
+
def a7784_1(); end
|
766
|
+
@action.("#2")
|
767
|
+
def a7784_2(); end
|
768
|
+
@action.("#4")
|
769
|
+
def a7784_4(); end
|
770
|
+
end
|
771
|
+
define_alias("a7784e", "c7784:a7784-5")
|
772
|
+
define_alias("a7784d", "c7784:a7784-3")
|
773
|
+
define_alias("a7784c", "c7784:a7784-1")
|
774
|
+
define_alias("a7784b", "c7784:a7784-2")
|
775
|
+
define_alias("a7784a", "c7784:a7784-4")
|
776
|
+
define_alias("a7784y", "c7784:a7784-4")
|
777
|
+
define_alias("a7784x", "c7784:a7784-4")
|
778
|
+
end
|
779
|
+
#
|
780
|
+
output = @builder.section_candidates("c7784:")
|
781
|
+
alias_section = output.split(/(?=\e\[1;34mAliases:\e\[0m\n)/, 2)[1]
|
782
|
+
ok {alias_section} == <<~"END"
|
783
|
+
\e[1;34mAliases:\e[0m
|
784
|
+
a7784c : alias for 'c7784:a7784-1'
|
785
|
+
a7784b : alias for 'c7784:a7784-2'
|
786
|
+
a7784d : alias for 'c7784:a7784-3'
|
787
|
+
a7784a : alias for 'c7784:a7784-4'
|
788
|
+
a7784x : alias for 'c7784:a7784-4'
|
789
|
+
a7784y : alias for 'c7784:a7784-4'
|
790
|
+
a7784e : alias for 'c7784:a7784-5'
|
791
|
+
END
|
792
|
+
end
|
466
793
|
|
467
|
-
|
794
|
+
spec "[!80t51] alias names are displayed in separated section from actions." do
|
795
|
+
Benry::CmdApp.define_alias("add", "git:stage")
|
796
|
+
at_end { Benry::CmdApp.undef_alias("add") }
|
797
|
+
x = @builder.section_candidates("git:")
|
798
|
+
ok {x} =~ /^\e\[1;34mAliases:\e\[0m$/
|
799
|
+
end
|
800
|
+
|
801
|
+
spec "[!rqx7w] returns header string if both no actions nor aliases found with names starting with prefix." do
|
802
|
+
x = @builder.section_candidates("blabla:")
|
803
|
+
ok {x} == "\e[1;34mActions:\e[0m\n\n"
|
804
|
+
end
|
805
|
+
|
806
|
+
end
|
807
|
+
|
808
|
+
|
809
|
+
topic '#section_aliases()' do
|
810
|
+
|
811
|
+
spec "[!496qq] renders alias list." do
|
812
|
+
Benry::CmdApp.define_alias("a9208", "hello")
|
813
|
+
x = @builder.section_aliases()
|
814
|
+
ok {x} =~ /\A\e\[1;34mAliases:\e\[0m\n/
|
815
|
+
ok {x} =~ /^ a9208 +: alias for 'hello'$/
|
816
|
+
end
|
817
|
+
|
818
|
+
spec "[!fj1c7] returns nil if no aliases found." do
|
819
|
+
registry = Benry::CmdApp::Registry.new()
|
820
|
+
@builder.instance_variable_set(:@_registry, registry)
|
821
|
+
x = @builder.section_aliases()
|
822
|
+
ok {x} == nil
|
823
|
+
registry.metadata_add(Benry::CmdApp::REGISTRY.metadata_get("hello"))
|
824
|
+
registry.metadata_add(Benry::CmdApp::AliasMetadata.new("h1", "hello", []))
|
825
|
+
x = @builder.section_aliases()
|
826
|
+
ok {x} != nil
|
827
|
+
ok {x} == <<"END"
|
828
|
+
\e[1;34mAliases:\e[0m
|
829
|
+
h1 : alias for 'hello'
|
468
830
|
END
|
469
831
|
end
|
470
832
|
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
833
|
+
spec "[!d7vee] ignores hidden aliases in default." do
|
834
|
+
Benry::CmdApp.define_alias("a4904", "hello", hidden: true)
|
835
|
+
x = @builder.section_aliases()
|
836
|
+
ok {x} =~ /\A\e\[1;34mAliases:\e\[0m\n/
|
837
|
+
ok {x} !~ /a4904/
|
476
838
|
end
|
477
839
|
|
478
|
-
spec "[!
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
ok {
|
483
|
-
|
484
|
-
\e[1m-h, --help \e[0m : print help message
|
485
|
-
\e[1m\e[2m-L\e[0m \e[0m : private option
|
840
|
+
spec "[!4vvrs] include hidden aliases if `all: true` specifieid." do
|
841
|
+
Benry::CmdApp.define_alias("a4612", "hello", hidden: true)
|
842
|
+
x = @builder.section_aliases(all: true)
|
843
|
+
ok {x} =~ /\A\e\[1;34mAliases:\e\[0m\n/
|
844
|
+
ok {x} =~ /^\e\[2m a4612 +: alias for 'hello'\e\[0m$/
|
845
|
+
end
|
486
846
|
|
847
|
+
spec "[!v211d] sorts aliases by action names." do
|
848
|
+
old_registry = Benry::CmdApp::REGISTRY
|
849
|
+
names = ["hello", "debuginfo", "testerr1", "git:stage", "git:staged", "git:unstage"]
|
850
|
+
output = nil
|
851
|
+
with_dummy_registry do |new_registry|
|
852
|
+
names.each {|name| new_registry.metadata_add(old_registry.metadata_get(name)) }
|
853
|
+
Benry::CmdApp.define_alias("a1", "git:unstage")
|
854
|
+
Benry::CmdApp.define_alias("a2", "git:stage")
|
855
|
+
Benry::CmdApp.define_alias("a3", "git:staged")
|
856
|
+
Benry::CmdApp.define_alias("a6", "git:staged")
|
857
|
+
Benry::CmdApp.define_alias("a5", "git:staged")
|
858
|
+
Benry::CmdApp.define_alias("a4", "git:staged")
|
859
|
+
Benry::CmdApp.define_alias("a7", "testerr1")
|
860
|
+
Benry::CmdApp.define_alias("a8", "debuginfo")
|
861
|
+
Benry::CmdApp.define_alias("a9", "hello")
|
862
|
+
builder = new_builder()
|
863
|
+
output = builder.section_aliases()
|
864
|
+
end
|
865
|
+
ok {output} == <<"END"
|
866
|
+
\e[1;34mAliases:\e[0m
|
867
|
+
a8 : alias for 'debuginfo'
|
868
|
+
a2 : alias for 'git:stage'
|
869
|
+
a3 : alias for 'git:staged'
|
870
|
+
a4 : alias for 'git:staged'
|
871
|
+
a5 : alias for 'git:staged'
|
872
|
+
a6 : alias for 'git:staged'
|
873
|
+
a1 : alias for 'git:unstage'
|
874
|
+
a9 : alias for 'hello'
|
875
|
+
a7 : alias for 'testerr1'
|
487
876
|
END
|
488
877
|
end
|
489
878
|
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
END
|
537
|
-
end
|
538
|
-
|
539
|
-
spec "[!yigf3] shows private (hidden) action names if 'all' flag is true." do
|
540
|
-
msg = @builder.build_help_message(true)
|
541
|
-
msg = uncolorize(msg)
|
542
|
-
ok {msg} =~ /^ _aha /
|
543
|
-
ok {msg} =~ /^ ya:_mada /
|
544
|
-
ok {msg}.end_with?(<<END)
|
545
|
-
Actions:
|
546
|
-
_aha : greeting #3
|
547
|
-
ya:_mada : greeting #4
|
548
|
-
ya:ya : greeting #2
|
549
|
-
yes : alias of 'yo-yo' action
|
550
|
-
yo-yo : greeting #1
|
551
|
-
END
|
552
|
-
end
|
553
|
-
|
554
|
-
spec "[!5d9mc] shows hidden action in weak format." do
|
555
|
-
HelpMessageTest.class_eval { private :yo_yo }
|
879
|
+
end
|
880
|
+
|
881
|
+
|
882
|
+
topic '#section_abbrevs()' do
|
883
|
+
|
884
|
+
spec "[!00ice] returns abbrev list string." do
|
885
|
+
Benry::CmdApp.define_abbrev("g25:", "git:")
|
886
|
+
x = @builder.section_abbrevs()
|
887
|
+
ok {x} =~ /\A\e\[1;34mAbbreviations:\e\[0m\n/
|
888
|
+
ok {x} =~ /^ g25: +=> +git:\n/
|
889
|
+
end
|
890
|
+
|
891
|
+
spec "[!dnt12] returns nil if no abbrevs found." do
|
892
|
+
registry = Benry::CmdApp::Registry.new()
|
893
|
+
@builder.instance_variable_set(:@_registry, registry)
|
894
|
+
ok {@builder.section_abbrevs()} == nil
|
895
|
+
registry.abbrev_add("g26:", "git:")
|
896
|
+
ok {@builder.section_abbrevs()} == <<END
|
897
|
+
\e[1;34mAbbreviations:\e[0m
|
898
|
+
g26: => git:
|
899
|
+
END
|
900
|
+
end
|
901
|
+
|
902
|
+
end
|
903
|
+
|
904
|
+
|
905
|
+
topic '#section_categories()' do
|
906
|
+
|
907
|
+
spec "[!crbav] returns top prefix list." do
|
908
|
+
x = @builder.section_categories(1)
|
909
|
+
ok {x} =~ /\A\e\[1;34mCategories:\e\[0m \e\[2m\(depth=\d+\)\e\[0m\n/
|
910
|
+
ok {x} =~ /^ git: \(\d+\)\n/
|
911
|
+
end
|
912
|
+
|
913
|
+
spec "[!alteh] includes prefix of hidden actions if `all: true` passed." do
|
914
|
+
x = @builder.section_categories(1, all: true)
|
915
|
+
ok {x} =~ /^ secret:/
|
916
|
+
x = @builder.section_categories(1)
|
917
|
+
ok {x} !~ /^ secret:/
|
918
|
+
end
|
919
|
+
|
920
|
+
spec "[!p4j1o] returns nil if no prefix found." do
|
921
|
+
registry = Benry::CmdApp::Registry.new
|
922
|
+
["hello", "secret:crypt"].each do |action|
|
923
|
+
registry.metadata_add(Benry::CmdApp::REGISTRY.metadata_get(action))
|
924
|
+
end
|
556
925
|
#
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
\e[1mya:ya \e[0m : greeting #2
|
564
|
-
\e[1m\e[2myes\e[0m \e[0m : alias of 'yo-yo' action
|
565
|
-
\e[1m\e[2myo-yo\e[0m \e[0m : greeting #1
|
566
|
-
END
|
567
|
-
ensure
|
568
|
-
HelpMessageTest.class_eval { public :yo_yo }
|
926
|
+
with_dummy_registry(registry) do
|
927
|
+
builder = new_builder()
|
928
|
+
x = builder.section_categories()
|
929
|
+
ok {x} == nil
|
930
|
+
x = builder.section_categories(all: true)
|
931
|
+
ok {x} != nil
|
569
932
|
end
|
570
933
|
end
|
571
934
|
|
572
|
-
spec "[!
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
935
|
+
spec "[!30l2j] includes number of actions per prefix." do
|
936
|
+
x = @builder.section_categories(all: true)
|
937
|
+
ok {x} =~ /^ git: \(\d+\)\n/
|
938
|
+
ok {x} =~ /^ secret: \(\d+\)\n/
|
939
|
+
end
|
940
|
+
|
941
|
+
spec "[!qxoja] includes category description if registered." do
|
942
|
+
x = @builder.section_categories(all: true)
|
943
|
+
ok {x} =~ /^ descdemo: \(2\) : category description demo$/
|
944
|
+
end
|
945
|
+
|
946
|
+
spec "[!k3y6q] uses `config.format_category` or `config.format_action`." do
|
947
|
+
@config.format_category = " %-15s # %s"
|
948
|
+
x = @builder.section_categories(all: true)
|
949
|
+
ok {x} =~ /^ descdemo: \(2\) # category description demo\n/
|
950
|
+
#
|
951
|
+
@config.format_category = nil
|
952
|
+
@config.format_category = " %-15s -- %s"
|
953
|
+
x = @builder.section_categories(all: true)
|
954
|
+
ok {x} =~ /^ descdemo: \(2\) -- category description demo$/
|
955
|
+
end
|
956
|
+
|
957
|
+
end
|
958
|
+
|
959
|
+
|
960
|
+
end
|
961
|
+
|
962
|
+
|
963
|
+
topic Benry::CmdApp::ActionHelpBuilder do
|
964
|
+
|
965
|
+
before do
|
966
|
+
@config = Benry::CmdApp::Config.new("test app", "1.2.3",
|
967
|
+
app_name: "TestApp", app_command: "testapp",
|
968
|
+
option_verbose: true, option_quiet: true,
|
969
|
+
option_color: true, #option_debug: true,
|
970
|
+
option_trace: true)
|
971
|
+
@builder = Benry::CmdApp::ActionHelpBuilder.new(@config)
|
972
|
+
@registry = Benry::CmdApp::REGISTRY
|
973
|
+
end
|
974
|
+
|
975
|
+
topic '#build_help_message()' do
|
976
|
+
|
977
|
+
spec "[!f3436] returns help message of an action." do
|
978
|
+
metadata = @registry.metadata_get("hello")
|
979
|
+
bkup = nil
|
980
|
+
metadata.instance_eval {
|
981
|
+
bkup = @description; @description = "Example of description."
|
982
|
+
}
|
983
|
+
at_end { metadata.instance_eval { @description = bkup } }
|
984
|
+
#
|
985
|
+
x = @builder.build_help_message(metadata)
|
986
|
+
ok {x}.start_with?(<<"END")
|
987
|
+
\e[1mtestapp hello\e[0m --- greeting message
|
988
|
+
|
989
|
+
\e[1;34mUsage:\e[0m
|
990
|
+
$ \e[1mtestapp hello\e[0m [<options>] [<name>]
|
991
|
+
|
992
|
+
\e[1;34mDescription:\e[0m
|
993
|
+
Example of description.
|
994
|
+
|
995
|
+
\e[1;34mOptions:\e[0m
|
996
|
+
-l, --lang=<lang> : language name (en/fr/it)
|
580
997
|
END
|
581
|
-
end
|
582
998
|
end
|
583
999
|
|
584
|
-
spec "[!
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
\e[
|
589
|
-
|
590
|
-
|
591
|
-
\e[
|
1000
|
+
spec "[!8acs1] includes hidden options if `all: true` passed." do
|
1001
|
+
metadata = @registry.metadata_get("debuginfo")
|
1002
|
+
x = @builder.build_help_message(metadata, all: true)
|
1003
|
+
ok {x} == <<"END"
|
1004
|
+
\e[1mtestapp debuginfo\e[0m --- hidden action
|
1005
|
+
|
1006
|
+
\e[1;34mUsage:\e[0m
|
1007
|
+
$ \e[1mtestapp debuginfo\e[0m [<options>]
|
1008
|
+
|
1009
|
+
\e[1;34mOptions:\e[0m
|
1010
|
+
\e[2m -h, --help : print help message\e[0m
|
1011
|
+
\e[2m --val=<val> : something value\e[0m
|
592
1012
|
END
|
593
|
-
end
|
594
1013
|
end
|
595
1014
|
|
596
|
-
spec "[!
|
597
|
-
|
598
|
-
|
599
|
-
ok {
|
600
|
-
|
601
|
-
|
1015
|
+
spec "[!mtvw8] includes 'Aliases:' section if action has any aliases." do
|
1016
|
+
metadata = @registry.metadata_get("alitest1")
|
1017
|
+
output = @builder.build_help_message(metadata, all: true)
|
1018
|
+
ok {output} == <<"END"
|
1019
|
+
\e[1mtestapp alitest1\e[0m --- sample action
|
1020
|
+
|
1021
|
+
\e[1;34mUsage:\e[0m
|
1022
|
+
$ \e[1mtestapp alitest1\e[0m [<options>] <xx> [<yy> [<zz>...]]
|
1023
|
+
|
1024
|
+
\e[1;34mOptions:\e[0m
|
1025
|
+
\e[2m -h, --help : print help message\e[0m
|
1026
|
+
-a, --aa : option A
|
1027
|
+
--bb : option B
|
1028
|
+
|
1029
|
+
\e[1;34mAliases:\e[0m
|
1030
|
+
alitest1x : alias for 'alitest1'
|
1031
|
+
alitest1y : alias for 'alitest1 --aa'
|
1032
|
+
alitest1z : alias for 'alitest1 --aa foobar'
|
602
1033
|
END
|
603
1034
|
end
|
604
1035
|
|
605
|
-
spec "[!
|
606
|
-
|
607
|
-
|
608
|
-
ok {
|
1036
|
+
spec "[!vcg9w] not include 'Options:' section if action has no options." do
|
1037
|
+
metadata = @registry.metadata_get("noopt")
|
1038
|
+
x = @builder.build_help_message(metadata, all: true)
|
1039
|
+
ok {x} == <<"END"
|
1040
|
+
\e[1mtestapp noopt\e[0m --- no options
|
1041
|
+
|
1042
|
+
\e[1;34mUsage:\e[0m
|
1043
|
+
$ \e[1mtestapp noopt\e[0m [<options>] <aa> [<bb>]
|
1044
|
+
|
1045
|
+
\e[1;34mOptions:\e[0m
|
1046
|
+
\e[2m -h, --help : print help message\e[0m
|
1047
|
+
END
|
609
1048
|
end
|
610
1049
|
|
611
|
-
spec "[!
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
msg = Benry::CmdApp::Util.del_escape_seq(msg)
|
617
|
-
ok {msg}.end_with?(<<'END')
|
618
|
-
Actions:
|
619
|
-
ya:ya : greeting #2
|
620
|
-
yo-yo : greeting #1
|
1050
|
+
spec "[!1auu5] not include '[<options>]' in 'Usage:'section if action has no options." do
|
1051
|
+
metadata = @registry.metadata_get("debuginfo")
|
1052
|
+
x = @builder.build_help_message(metadata)
|
1053
|
+
ok {x} == <<"END"
|
1054
|
+
\e[1mtestapp debuginfo\e[0m --- hidden action
|
621
1055
|
|
622
|
-
|
623
|
-
|
1056
|
+
\e[1;34mUsage:\e[0m
|
1057
|
+
$ \e[1mtestapp debuginfo\e[0m
|
624
1058
|
END
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
|
1059
|
+
end
|
1060
|
+
|
1061
|
+
end
|
1062
|
+
|
1063
|
+
|
1064
|
+
topic '#section_preamble()' do
|
1065
|
+
|
1066
|
+
spec "[!a6nk4] returns preamble of action help message." do
|
1067
|
+
metadata = @registry.metadata_get("hello")
|
1068
|
+
x = @builder.__send__(:section_preamble, metadata)
|
1069
|
+
ok {x} == <<"END"
|
1070
|
+
\e[1mtestapp hello\e[0m --- greeting message
|
634
1071
|
END
|
635
1072
|
end
|
636
1073
|
|
637
|
-
spec "[!
|
638
|
-
@config.
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
|
643
|
-
|
644
|
-
|
1074
|
+
spec "[!imxdq] includes `config.app_command`, not `config.app_name`, into preamble." do
|
1075
|
+
@config.app_name = "TestApp1"
|
1076
|
+
@config.app_command = "testapp1"
|
1077
|
+
metadata = @registry.metadata_get("hello")
|
1078
|
+
x = @builder.__send__(:section_preamble, metadata)
|
1079
|
+
ok {x} == <<"END"
|
1080
|
+
\e[1mtestapp1 hello\e[0m --- greeting message
|
1081
|
+
END
|
1082
|
+
end
|
645
1083
|
|
646
|
-
|
647
|
-
|
1084
|
+
spec "[!7uy4f] includes `detail:` kwarg value of `@action.()` if specified." do
|
1085
|
+
@config.app_command = "testapp1"
|
1086
|
+
metadata = @registry.metadata_get("prepostamble")
|
1087
|
+
x = @builder.__send__(:section_preamble, metadata)
|
1088
|
+
ok {x} == <<"END"
|
1089
|
+
\e[1mtestapp1 prepostamble\e[0m --- preamble and postamble
|
648
1090
|
|
649
|
-
|
650
|
-
* foobar
|
1091
|
+
See https://....
|
651
1092
|
END
|
652
1093
|
end
|
653
1094
|
|
654
1095
|
end
|
655
1096
|
|
656
1097
|
|
657
|
-
topic '#
|
1098
|
+
topic '#section_usage()' do
|
658
1099
|
|
659
|
-
|
660
|
-
|
661
|
-
@
|
662
|
-
|
663
|
-
|
664
|
-
|
665
|
-
|
666
|
-
|
667
|
-
|
668
|
-
|
1100
|
+
spec "[!jca5d] not add '[<options>]' if action has no options." do
|
1101
|
+
metadata = @registry.metadata_get("noopt")
|
1102
|
+
x = @builder.__send__(:section_usage, metadata)
|
1103
|
+
ok {x}.NOT.include?("[<options>]")
|
1104
|
+
ok {x} == <<"END"
|
1105
|
+
\e[1;34mUsage:\e[0m
|
1106
|
+
$ \e[1mtestapp noopt\e[0m <aa> [<bb>]
|
1107
|
+
END
|
1108
|
+
#
|
1109
|
+
metadata = @registry.metadata_get("debuginfo") # has a hidden option
|
1110
|
+
x = @builder.__send__(:section_usage, metadata)
|
1111
|
+
ok {x}.NOT.include?("[<options>]")
|
1112
|
+
ok {x} == <<"END"
|
1113
|
+
\e[1;34mUsage:\e[0m
|
1114
|
+
$ \e[1mtestapp debuginfo\e[0m
|
1115
|
+
END
|
669
1116
|
end
|
670
1117
|
|
671
|
-
|
672
|
-
|
673
|
-
|
674
|
-
|
675
|
-
|
676
|
-
|
1118
|
+
spec "[!h5bp4] if `usage:` kwarg specified in `@action.()`, use it as usage string." do
|
1119
|
+
metadata = @registry.metadata_get("usagesample1")
|
1120
|
+
x = @builder.__send__(:section_usage, metadata)
|
1121
|
+
ok {x} == <<"END"
|
1122
|
+
\e[1;34mUsage:\e[0m
|
1123
|
+
$ \e[1mtestapp usagesample1\e[0m input.txt > output.txt
|
1124
|
+
END
|
677
1125
|
end
|
678
1126
|
|
679
|
-
|
680
|
-
|
1127
|
+
spec "[!nfuxz] `usage:` kwarg can be a string or an array of string." do
|
1128
|
+
metadata = @registry.metadata_get("usagesample2")
|
1129
|
+
x = @builder.__send__(:section_usage, metadata)
|
1130
|
+
ok {x} == <<"END"
|
1131
|
+
\e[1;34mUsage:\e[0m
|
1132
|
+
$ \e[1mtestapp usagesample2\e[0m [<options>] input.txt | less
|
1133
|
+
$ \e[1mtestapp usagesample2\e[0m [<options>] input.txt > output.txt
|
1134
|
+
END
|
681
1135
|
end
|
682
1136
|
|
683
|
-
|
684
|
-
|
685
|
-
|
686
|
-
|
687
|
-
return builder
|
1137
|
+
spec "[!z3lh9] if `usage:` kwarg not specified in `@action.()`, generates usage string from method parameters." do
|
1138
|
+
metadata = @registry.metadata_get("argsample")
|
1139
|
+
x = @builder.__send__(:section_usage, metadata)
|
1140
|
+
ok {x}.include?("[<options>] <aa> <bb> [<cc> [<dd> [<rest>...]]]")
|
688
1141
|
end
|
689
1142
|
|
690
|
-
spec "[!
|
691
|
-
|
692
|
-
|
693
|
-
ok {
|
694
|
-
\e[
|
695
|
-
\e[
|
696
|
-
\e[1mh25t1 \e[0m : alias of 'help25:test1' action
|
1143
|
+
spec "[!iuctx] returns 'Usage:' section of action help message." do
|
1144
|
+
metadata = @registry.metadata_get("argsample")
|
1145
|
+
x = @builder.__send__(:section_usage, metadata)
|
1146
|
+
ok {x} == <<"END"
|
1147
|
+
\e[1;34mUsage:\e[0m
|
1148
|
+
$ \e[1mtestapp argsample\e[0m [<options>] <aa> <bb> [<cc> [<dd> [<rest>...]]]
|
697
1149
|
END
|
698
1150
|
end
|
699
1151
|
|
700
|
-
|
701
|
-
|
702
|
-
|
703
|
-
|
1152
|
+
end
|
1153
|
+
|
1154
|
+
|
1155
|
+
topic '#section_descriptin()' do
|
1156
|
+
|
1157
|
+
spec "[!zeujz] returns 'Description:' section if action description is set." do
|
1158
|
+
metadata = @registry.metadata_get("hello")
|
1159
|
+
bkup = nil
|
1160
|
+
metadata.instance_eval {
|
1161
|
+
bkup = @description; @description = "Example of description."
|
1162
|
+
}
|
1163
|
+
at_end { metadata.instance_eval { @description = bkup } }
|
1164
|
+
str = @builder.__send__(:section_description, metadata)
|
1165
|
+
ok {str} == <<~"END"
|
1166
|
+
\e[1;34mDescription:\e[0m
|
1167
|
+
Example of description.
|
1168
|
+
END
|
704
1169
|
end
|
705
1170
|
|
706
|
-
spec "[!
|
707
|
-
|
708
|
-
|
709
|
-
|
710
|
-
ok {
|
711
|
-
|
712
|
-
|
713
|
-
|
714
|
-
|
1171
|
+
spec "[!0zffw] returns nil if action description is nil." do
|
1172
|
+
metadata = @registry.metadata_get("hello")
|
1173
|
+
metadata.instance_eval { @description = nil }
|
1174
|
+
str = @builder.__send__(:section_description, metadata)
|
1175
|
+
ok {str} == nil
|
1176
|
+
end
|
1177
|
+
|
1178
|
+
end
|
1179
|
+
|
1180
|
+
|
1181
|
+
topic '#section_options()' do
|
1182
|
+
|
1183
|
+
spec "[!pafgs] returns 'Options:' section of help message." do
|
1184
|
+
metadata = @registry.metadata_get("hello")
|
1185
|
+
x = @builder.__send__(:section_options, metadata)
|
1186
|
+
ok {x} == <<"END"
|
1187
|
+
\e[1;34mOptions:\e[0m
|
1188
|
+
-l, --lang=<lang> : language name (en/fr/it)
|
715
1189
|
END
|
716
1190
|
end
|
717
1191
|
|
718
|
-
spec "[!
|
719
|
-
|
720
|
-
|
721
|
-
|
722
|
-
|
723
|
-
|
724
|
-
|
725
|
-
|
726
|
-
|
1192
|
+
spec "[!85wus] returns nil if action has no options." do
|
1193
|
+
metadata = @registry.metadata_get("noopt")
|
1194
|
+
x = @builder.__send__(:section_options, metadata)
|
1195
|
+
ok {x} == nil
|
1196
|
+
end
|
1197
|
+
|
1198
|
+
end
|
1199
|
+
|
1200
|
+
|
1201
|
+
topic '#section_aliases()' do
|
1202
|
+
|
1203
|
+
spec "[!kjpt9] returns 'Aliases:' section of help message." do
|
1204
|
+
action = "alitest1"
|
1205
|
+
x = @registry.metadata_each.any? {|md| md.alias? && md.action == action }
|
1206
|
+
ok {x} == true
|
1207
|
+
#
|
1208
|
+
metadata = @registry.metadata_get("alitest1")
|
1209
|
+
output = @builder.__send__(:section_aliases, metadata)
|
1210
|
+
ok {output} == <<"END"
|
1211
|
+
\e[1;34mAliases:\e[0m
|
1212
|
+
alitest1x : alias for 'alitest1'
|
1213
|
+
alitest1y : alias for 'alitest1 --aa'
|
1214
|
+
alitest1z : alias for 'alitest1 --aa foobar'
|
727
1215
|
END
|
728
|
-
end
|
729
1216
|
end
|
730
1217
|
|
731
|
-
spec "[!
|
732
|
-
|
733
|
-
|
734
|
-
|
735
|
-
|
1218
|
+
spec "[!cjr0q] returns nil if action has no options." do
|
1219
|
+
action = "argsample"
|
1220
|
+
x = @registry.metadata_each.any? {|md| md.alias? && md.action == action }
|
1221
|
+
ok {x} == false
|
1222
|
+
#
|
1223
|
+
metadata = @registry.metadata_get(action)
|
1224
|
+
output = @builder.__send__(:section_aliases, metadata)
|
1225
|
+
ok {output} == nil
|
736
1226
|
end
|
737
1227
|
|
738
|
-
|
739
|
-
|
740
|
-
|
741
|
-
|
742
|
-
|
743
|
-
|
744
|
-
|
745
|
-
|
1228
|
+
end
|
1229
|
+
|
1230
|
+
|
1231
|
+
topic '#section_postamble()' do
|
1232
|
+
|
1233
|
+
spec "[!q1jee] returns postamble of help message if `postamble:` kwarg specified in `@action.()`." do
|
1234
|
+
metadata = @registry.metadata_get("prepostamble")
|
1235
|
+
x = @builder.__send__(:section_postamble, metadata)
|
1236
|
+
ok {x} == <<"END"
|
1237
|
+
\e[1;34mExamples:\e[0m
|
1238
|
+
$ echo
|
1239
|
+
|
1240
|
+
(Tips: blabla)
|
746
1241
|
END
|
747
1242
|
end
|
748
1243
|
|
1244
|
+
spec "[!jajse] returns nil if postamble is not set." do
|
1245
|
+
metadata = @registry.metadata_get("hello")
|
1246
|
+
x = @builder.__send__(:section_postamble, metadata)
|
1247
|
+
ok {x} == nil
|
1248
|
+
end
|
1249
|
+
|
749
1250
|
end
|
750
1251
|
|
751
1252
|
|