toys-core 0.3.4 → 0.3.5
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/.yardopts +1 -0
- data/CHANGELOG.md +7 -0
- data/README.md +8 -7
- data/docs/getting-started.md +8 -0
- data/lib/toys/cli.rb +2 -1
- data/lib/toys/config_dsl.rb +282 -74
- data/lib/toys/core_version.rb +1 -1
- data/lib/toys/helpers/exec.rb +47 -365
- data/lib/toys/loader.rb +1 -1
- data/lib/toys/middleware/add_verbosity_flags.rb +2 -2
- data/lib/toys/middleware/set_default_descriptions.rb +16 -16
- data/lib/toys/middleware/show_help.rb +35 -11
- data/lib/toys/middleware/show_version.rb +1 -1
- data/lib/toys/template.rb +1 -1
- data/lib/toys/templates/clean.rb +1 -1
- data/lib/toys/templates/gem_build.rb +1 -1
- data/lib/toys/templates/minitest.rb +1 -1
- data/lib/toys/templates/rubocop.rb +1 -1
- data/lib/toys/templates/yardoc.rb +1 -1
- data/lib/toys/tool.rb +110 -235
- data/lib/toys/utils/exec.rb +505 -0
- data/lib/toys/utils/help_text.rb +11 -11
- metadata +7 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 88644d1a61c31baed3ea200a6a936f79d5f81227b42c79ceeb949dd7be06d3ad
|
4
|
+
data.tar.gz: 85a9544bd4950250ab0797d1fa0a110d949cf677b6739596a90c75b8d1cf8185
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3f09f94ffd7f77b58981bcd291a46bd354c02b11800d550ee9419b76ea74049efe9aa4833bf8ee4e4d41199f84e926b03577315d61d8512c8808878420453542
|
7
|
+
data.tar.gz: 46e24892810dcb54266bad9647b9d2bbb0dde2c283b7e869183103dad84da238ada3dd37581f4a891c84c95af2fa45e33bb72c25e728281ede6027847bd9e984
|
data/.yardopts
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,12 @@
|
|
1
1
|
# Release History
|
2
2
|
|
3
|
+
### 0.3.5 / 2018-05-15
|
4
|
+
|
5
|
+
* CHANGED: Exec logic now lives in a utils class.
|
6
|
+
* CHANGED: Moved flag and arg blocks from Tool into the DSL.
|
7
|
+
* CHANGED: Renamed `execute do` to `script do`, and Tool#executor to Tool#script.
|
8
|
+
* IMPROVED: Help display can use `less` if available.
|
9
|
+
|
3
10
|
### 0.3.4 / 2018-05-14
|
4
11
|
|
5
12
|
* CHANGED: Renamed switch to flag
|
data/README.md
CHANGED
@@ -1,15 +1,16 @@
|
|
1
1
|
# Toys
|
2
2
|
|
3
|
-
Toys is a command line binary that lets you build your own suite of
|
4
|
-
line tools
|
5
|
-
|
3
|
+
Toys is a command line binary that lets you build your own personal suite of
|
4
|
+
command line tools using a Ruby DSL. Toys handles argument parsing, error
|
5
|
+
reporting, logging, help text, and many other details for you. Toys is designed
|
6
|
+
for software developers, IT specialists, and other power users who want to
|
7
|
+
write and organize scripts to automate their workflows.
|
6
8
|
|
7
9
|
Toys-Core is the command line tool framework underlying Toys. It can be used
|
8
|
-
to create command line binaries using the Toys
|
10
|
+
to create command line binaries using the internal Toys APIs.
|
9
11
|
|
10
|
-
|
11
|
-
|
12
|
-
(TODO)
|
12
|
+
To get started using toys-core for your own command line binary, see the
|
13
|
+
{file:docs/getting-started.md Getting Started Guide}.
|
13
14
|
|
14
15
|
## Contributing
|
15
16
|
|
data/lib/toys/cli.rb
CHANGED
@@ -292,7 +292,8 @@ module Toys
|
|
292
292
|
# description fields
|
293
293
|
# * {Toys::Middleware::ShowHelp} adding the `--help` flag
|
294
294
|
# * {Toys::Middleware::HandleUsageErrors}
|
295
|
-
# * {Toys::Middleware::ShowHelp} providing default behavior for
|
295
|
+
# * {Toys::Middleware::ShowHelp} providing default behavior for
|
296
|
+
# namespaces
|
296
297
|
# * {Toys::Middleware::AddVerbosityFlags} adding the `--verbose` and
|
297
298
|
# `--quiet` flags for managing the logger level
|
298
299
|
#
|
data/lib/toys/config_dsl.rb
CHANGED
@@ -49,7 +49,7 @@ module Toys
|
|
49
49
|
#
|
50
50
|
# optional_arg :recipient, default: "world"
|
51
51
|
#
|
52
|
-
#
|
52
|
+
# script do
|
53
53
|
# puts "Hello, #{self[:recipient]}!"
|
54
54
|
# end
|
55
55
|
# end
|
@@ -87,9 +87,8 @@ module Toys
|
|
87
87
|
##
|
88
88
|
# Create a subtool. You must provide a block defining the subtool.
|
89
89
|
#
|
90
|
-
# If the subtool is already defined (either as a tool or a
|
91
|
-
# definition is discarded and replaced with the new definition.
|
92
|
-
# tool was a group, all its descendants are also discarded, recursively.
|
90
|
+
# If the subtool is already defined (either as a tool or a namespace), the
|
91
|
+
# old definition is discarded and replaced with the new definition.
|
93
92
|
#
|
94
93
|
# @param [String] word The name of the subtool
|
95
94
|
#
|
@@ -103,7 +102,7 @@ module Toys
|
|
103
102
|
alias name tool
|
104
103
|
|
105
104
|
##
|
106
|
-
# Create an alias in the current
|
105
|
+
# Create an alias in the current namespace.
|
107
106
|
#
|
108
107
|
# @param [String] word The name of the alias
|
109
108
|
# @param [String] target The target of the alias
|
@@ -165,9 +164,27 @@ module Toys
|
|
165
164
|
# displayed with the tool in a subtool list. You may also use the
|
166
165
|
# equivalent method `short_desc`.
|
167
166
|
#
|
168
|
-
# The description
|
169
|
-
#
|
170
|
-
#
|
167
|
+
# The description is a {Toys::Utils::WrappableString}, which may be word-
|
168
|
+
# wrapped when displayed in a help screen. You may pass a
|
169
|
+
# {Toys::Utils::WrappableString} directly to this method, or you may pass
|
170
|
+
# any input that can be used to construct a wrappable string:
|
171
|
+
#
|
172
|
+
# * If you pass a String, its whitespace will be compacted (i.e. tabs,
|
173
|
+
# newlines, and multiple consecutive whitespace will be turned into a
|
174
|
+
# single space), and it will be word-wrapped on whitespace.
|
175
|
+
# * If you pass an Array of Strings, each string will be considered a
|
176
|
+
# literal word that cannot be broken, and wrapping will be done across
|
177
|
+
# the strings in the array. In this case, whitespace is not compacted.
|
178
|
+
#
|
179
|
+
# For example, if you pass in a sentence as a simple string, it may be
|
180
|
+
# word wrapped when displayed:
|
181
|
+
#
|
182
|
+
# desc "This sentence may be wrapped."
|
183
|
+
#
|
184
|
+
# To specify a sentence that should never be word-wrapped, pass it as the
|
185
|
+
# sole element of a string array:
|
186
|
+
#
|
187
|
+
# desc ["This sentence will not be wrapped."]
|
171
188
|
#
|
172
189
|
# @param [Toys::Utils::WrappableString,String,Array<String>] str
|
173
190
|
#
|
@@ -183,9 +200,18 @@ module Toys
|
|
183
200
|
# Set the long description for the current tool. The long description is
|
184
201
|
# displayed in the usage documentation for the tool itself.
|
185
202
|
#
|
186
|
-
#
|
187
|
-
#
|
188
|
-
#
|
203
|
+
# A long description is a series of descriptions, which are generally
|
204
|
+
# displayed in a series of lines/paragraphs. Each individual description
|
205
|
+
# uses the form described in the {Toys::ConfigDSL#desc} documentation, and
|
206
|
+
# may be word-wrapped when displayed. To insert a blank line, include an
|
207
|
+
# empty string as one of the descriptions.
|
208
|
+
#
|
209
|
+
# Example:
|
210
|
+
#
|
211
|
+
# long_desc "This is an initial paragraph that might be word wrapped.",
|
212
|
+
# "This next paragraph is followed by a blank line.",
|
213
|
+
# "",
|
214
|
+
# ["This line will not be wrapped."]
|
189
215
|
#
|
190
216
|
# @param [Toys::Utils::WrappableString,String,Array<String>...] strs
|
191
217
|
#
|
@@ -198,9 +224,12 @@ module Toys
|
|
198
224
|
|
199
225
|
##
|
200
226
|
# Add a flag to the current tool. Each flag must specify a key which
|
201
|
-
# the
|
227
|
+
# the script may use to obtain the flag value from the context.
|
202
228
|
# You may then provide the flags themselves in `OptionParser` form.
|
203
229
|
#
|
230
|
+
# Attributes of the flag may be passed in as arguments to this method, or
|
231
|
+
# set in a block passed to this method.
|
232
|
+
#
|
204
233
|
# @param [Symbol] key The key to use to retrieve the value from the
|
205
234
|
# execution context.
|
206
235
|
# @param [String...] flags The flags in OptionParser format.
|
@@ -208,40 +237,41 @@ module Toys
|
|
208
237
|
# @param [Object] default The default value. This is the value that will
|
209
238
|
# be set in the context if this flag is not provided on the command
|
210
239
|
# line. Defaults to `nil`.
|
211
|
-
# @param [String,Toys::Utils::WrappableString,
|
212
|
-
# Array<String,Toys::Utils::WrappableString>] desc Short description
|
213
|
-
# for the flag. Defaults to empty array.
|
214
|
-
# @param [String,Toys::Utils::WrappableString,
|
215
|
-
# Array<String,Toys::Utils::WrappableString>] long_desc Long
|
216
|
-
# description for the flag. Defaults to empty array.
|
217
|
-
# @param [Boolean] only_unique If true, any flags that are already
|
218
|
-
# defined in this tool are removed from this flag. For example, if
|
219
|
-
# an earlier flag uses `-a`, and this flag wants to use both
|
220
|
-
# `-a` and `-b`, then only `-b` will be assigned to this flag.
|
221
|
-
# Defaults to false.
|
222
240
|
# @param [Proc,nil] handler An optional handler for setting/updating the
|
223
241
|
# value. If given, it should take two arguments, the new given value
|
224
242
|
# and the previous value, and it should return the new value that
|
225
243
|
# should be set. The default handler simply replaces the previous
|
226
244
|
# value. i.e. the default is effectively `-> (val, _prev) { val }`.
|
245
|
+
# @param [String,Array<String>,Toys::Utils::WrappableString] desc Short
|
246
|
+
# description for the flag. See {Toys::ConfigDSL#desc} for a description
|
247
|
+
# of the allowed formats. Defaults to the empty string.
|
248
|
+
# @param [Array<String,Array<String>,Toys::Utils::WrappableString>] long_desc
|
249
|
+
# Long description for the flag. See {Toys::ConfigDSL#long_desc} for a
|
250
|
+
# description of the allowed formats. (But note that this param takes
|
251
|
+
# an Array of description lines, rather than a series of arguments.)
|
252
|
+
# Defaults to the empty array.
|
253
|
+
# @param [Boolean] only_unique If true, any flags that are already
|
254
|
+
# defined in this tool are removed from this flag. For example, if
|
255
|
+
# an earlier flag uses `-a`, and this flag wants to use both
|
256
|
+
# `-a` and `-b`, then only `-b` will be assigned to this flag.
|
257
|
+
# Defaults to false.
|
258
|
+
# @yieldparam flag_dsl [Toys::ConfigDSL::FlagDSL] An object that lets you
|
259
|
+
# configure this flag in a block.
|
227
260
|
#
|
228
261
|
def flag(key, *flags,
|
229
|
-
accept: nil, default: nil, desc: nil, long_desc: nil,
|
230
|
-
only_unique: false
|
231
|
-
&block)
|
262
|
+
accept: nil, default: nil, handler: nil, desc: nil, long_desc: nil,
|
263
|
+
only_unique: false)
|
232
264
|
return self if _cur_tool.nil?
|
265
|
+
flag_dsl = FlagDSL.new(flags, accept, default, handler, desc, long_desc)
|
266
|
+
yield flag_dsl if block_given?
|
233
267
|
_cur_tool.lock_definition_path(@path)
|
234
|
-
|
235
|
-
accept: accept, default: default,
|
236
|
-
desc: desc, long_desc: long_desc,
|
237
|
-
only_unique: only_unique, handler: handler,
|
238
|
-
&block)
|
268
|
+
flag_dsl._add_to(_cur_tool, key, only_unique)
|
239
269
|
self
|
240
270
|
end
|
241
271
|
|
242
272
|
##
|
243
273
|
# Add a required positional argument to the current tool. You must specify
|
244
|
-
# a key which the
|
274
|
+
# a key which the script may use to obtain the argument value from the
|
245
275
|
# context.
|
246
276
|
#
|
247
277
|
# @param [Symbol] key The key to use to retrieve the value from the
|
@@ -249,27 +279,30 @@ module Toys
|
|
249
279
|
# @param [Object,nil] accept An OptionParser acceptor. Optional.
|
250
280
|
# @param [String] display_name A name to use for display (in help text and
|
251
281
|
# error reports). Defaults to the key in upper case.
|
252
|
-
# @param [String,Toys::Utils::WrappableString
|
253
|
-
#
|
254
|
-
#
|
255
|
-
# @param [String,Toys::Utils::WrappableString
|
256
|
-
#
|
257
|
-
# description
|
258
|
-
#
|
259
|
-
|
282
|
+
# @param [String,Array<String>,Toys::Utils::WrappableString] desc Short
|
283
|
+
# description for the flag. See {Toys::ConfigDSL#desc} for a description
|
284
|
+
# of the allowed formats. Defaults to the empty string.
|
285
|
+
# @param [Array<String,Array<String>,Toys::Utils::WrappableString>] long_desc
|
286
|
+
# Long description for the flag. See {Toys::ConfigDSL#long_desc} for a
|
287
|
+
# description of the allowed formats. (But note that this param takes
|
288
|
+
# an Array of description lines, rather than a series of arguments.)
|
289
|
+
# Defaults to the empty array.
|
290
|
+
# @yieldparam arg_dsl [Toys::ConfigDSL::ArgDSL] An object that lets you
|
291
|
+
# configure this argument in a block.
|
292
|
+
#
|
293
|
+
def required_arg(key, accept: nil, display_name: nil, desc: nil, long_desc: nil)
|
260
294
|
return self if _cur_tool.nil?
|
295
|
+
arg_dsl = ArgDSL.new(accept, nil, display_name, desc, long_desc)
|
296
|
+
yield arg_dsl if block_given?
|
261
297
|
_cur_tool.lock_definition_path(@path)
|
262
|
-
|
263
|
-
accept: accept, display_name: display_name,
|
264
|
-
desc: desc, long_desc: long_desc,
|
265
|
-
&block)
|
298
|
+
arg_dsl._add_required_to(_cur_tool, key)
|
266
299
|
self
|
267
300
|
end
|
268
301
|
alias required required_arg
|
269
302
|
|
270
303
|
##
|
271
304
|
# Add an optional positional argument to the current tool. You must specify
|
272
|
-
# a key which the
|
305
|
+
# a key which the script may use to obtain the argument value from the
|
273
306
|
# context. If an optional argument is not given on the command line, the
|
274
307
|
# value is set to the given default.
|
275
308
|
#
|
@@ -281,29 +314,32 @@ module Toys
|
|
281
314
|
# @param [Object,nil] accept An OptionParser acceptor. Optional.
|
282
315
|
# @param [String] display_name A name to use for display (in help text and
|
283
316
|
# error reports). Defaults to the key in upper case.
|
284
|
-
# @param [String,Toys::Utils::WrappableString
|
285
|
-
#
|
286
|
-
#
|
287
|
-
# @param [String,Toys::Utils::WrappableString
|
288
|
-
#
|
289
|
-
# description
|
317
|
+
# @param [String,Array<String>,Toys::Utils::WrappableString] desc Short
|
318
|
+
# description for the flag. See {Toys::ConfigDSL#desc} for a description
|
319
|
+
# of the allowed formats. Defaults to the empty string.
|
320
|
+
# @param [Array<String,Array<String>,Toys::Utils::WrappableString>] long_desc
|
321
|
+
# Long description for the flag. See {Toys::ConfigDSL#long_desc} for a
|
322
|
+
# description of the allowed formats. (But note that this param takes
|
323
|
+
# an Array of description lines, rather than a series of arguments.)
|
324
|
+
# Defaults to the empty array.
|
325
|
+
# @yieldparam arg_dsl [Toys::ConfigDSL::ArgDSL] An object that lets you
|
326
|
+
# configure this argument in a block.
|
290
327
|
#
|
291
328
|
def optional_arg(key, default: nil, accept: nil, display_name: nil,
|
292
|
-
desc: nil, long_desc: nil
|
329
|
+
desc: nil, long_desc: nil)
|
293
330
|
return self if _cur_tool.nil?
|
331
|
+
arg_dsl = ArgDSL.new(accept, default, display_name, desc, long_desc)
|
332
|
+
yield arg_dsl if block_given?
|
294
333
|
_cur_tool.lock_definition_path(@path)
|
295
|
-
|
296
|
-
accept: accept, default: default, display_name: display_name,
|
297
|
-
desc: desc, long_desc: long_desc,
|
298
|
-
&block)
|
334
|
+
arg_dsl._add_optional_to(_cur_tool, key)
|
299
335
|
self
|
300
336
|
end
|
301
337
|
alias optional optional_arg
|
302
338
|
|
303
339
|
##
|
304
340
|
# Specify what should be done with unmatched positional arguments. You must
|
305
|
-
# specify a key which the
|
306
|
-
#
|
341
|
+
# specify a key which the script may use to obtain the remaining args from
|
342
|
+
# the context.
|
307
343
|
#
|
308
344
|
# @param [Symbol] key The key to use to retrieve the value from the
|
309
345
|
# execution context.
|
@@ -313,38 +349,41 @@ module Toys
|
|
313
349
|
# @param [Object,nil] accept An OptionParser acceptor. Optional.
|
314
350
|
# @param [String] display_name A name to use for display (in help text and
|
315
351
|
# error reports). Defaults to the key in upper case.
|
316
|
-
# @param [String,Toys::Utils::WrappableString
|
317
|
-
#
|
318
|
-
#
|
319
|
-
# @param [String,Toys::Utils::WrappableString
|
320
|
-
#
|
321
|
-
# description
|
352
|
+
# @param [String,Array<String>,Toys::Utils::WrappableString] desc Short
|
353
|
+
# description for the flag. See {Toys::ConfigDSL#desc} for a description
|
354
|
+
# of the allowed formats. Defaults to the empty string.
|
355
|
+
# @param [Array<String,Array<String>,Toys::Utils::WrappableString>] long_desc
|
356
|
+
# Long description for the flag. See {Toys::ConfigDSL#long_desc} for a
|
357
|
+
# description of the allowed formats. (But note that this param takes
|
358
|
+
# an Array of description lines, rather than a series of arguments.)
|
359
|
+
# Defaults to the empty array.
|
360
|
+
# @yieldparam arg_dsl [Toys::ConfigDSL::ArgDSL] An object that lets you
|
361
|
+
# configure this argument in a block.
|
322
362
|
#
|
323
363
|
def remaining_args(key, default: [], accept: nil, display_name: nil,
|
324
|
-
desc: nil, long_desc: nil
|
364
|
+
desc: nil, long_desc: nil)
|
325
365
|
return self if _cur_tool.nil?
|
366
|
+
arg_dsl = ArgDSL.new(accept, default, display_name, desc, long_desc)
|
367
|
+
yield arg_dsl if block_given?
|
326
368
|
_cur_tool.lock_definition_path(@path)
|
327
|
-
|
328
|
-
accept: accept, default: default, display_name: display_name,
|
329
|
-
desc: desc, long_desc: long_desc,
|
330
|
-
&block)
|
369
|
+
arg_dsl._set_remaining_on(_cur_tool, key)
|
331
370
|
self
|
332
371
|
end
|
333
372
|
alias remaining remaining_args
|
334
373
|
|
335
374
|
##
|
336
|
-
# Specify the
|
375
|
+
# Specify the script for this tool. This is a block that will be called,
|
337
376
|
# with `self` set to a {Toys::Context}.
|
338
377
|
#
|
339
|
-
def
|
378
|
+
def script(&block)
|
340
379
|
return self if _cur_tool.nil?
|
341
380
|
_cur_tool.lock_definition_path(@path)
|
342
|
-
_cur_tool.
|
381
|
+
_cur_tool.script = block
|
343
382
|
self
|
344
383
|
end
|
345
384
|
|
346
385
|
##
|
347
|
-
# Define a helper method that may be called from this tool's
|
386
|
+
# Define a helper method that may be called from this tool's script.
|
348
387
|
# You must provide a name for the method, and a block for the method
|
349
388
|
# definition.
|
350
389
|
#
|
@@ -359,7 +398,7 @@ module Toys
|
|
359
398
|
end
|
360
399
|
|
361
400
|
##
|
362
|
-
# Specify that the given module should be mixed in to this tool's
|
401
|
+
# Specify that the given module should be mixed in to this tool's script.
|
363
402
|
# Effectively, the module is added to the {Toys::Context} object.
|
364
403
|
# You may either provide a module directly, or specify the name of a
|
365
404
|
# well-known module.
|
@@ -373,6 +412,175 @@ module Toys
|
|
373
412
|
self
|
374
413
|
end
|
375
414
|
|
415
|
+
##
|
416
|
+
# DSL for a flag definition block. Lets you set flag attributes in a block
|
417
|
+
# instead of a long series of keyword arguments.
|
418
|
+
#
|
419
|
+
class FlagDSL
|
420
|
+
## @private
|
421
|
+
def initialize(flags, accept, default, handler, desc, long_desc)
|
422
|
+
@flags = flags
|
423
|
+
@accept = accept
|
424
|
+
@default = default
|
425
|
+
@handler = handler
|
426
|
+
@desc = desc
|
427
|
+
@long_desc = long_desc
|
428
|
+
end
|
429
|
+
|
430
|
+
##
|
431
|
+
# Add flags in OptionParser format. This may be called multiple times,
|
432
|
+
# and the results are cumulative.
|
433
|
+
# @param [String...] flags
|
434
|
+
#
|
435
|
+
def flags(*flags)
|
436
|
+
@flags += flags
|
437
|
+
self
|
438
|
+
end
|
439
|
+
|
440
|
+
##
|
441
|
+
# Set the OptionParser acceptor.
|
442
|
+
# @param [Object] accept
|
443
|
+
#
|
444
|
+
def accept(accept)
|
445
|
+
@accept = accept
|
446
|
+
self
|
447
|
+
end
|
448
|
+
|
449
|
+
##
|
450
|
+
# Set the default value.
|
451
|
+
# @param [Object] default
|
452
|
+
#
|
453
|
+
def default(default)
|
454
|
+
@default = default
|
455
|
+
self
|
456
|
+
end
|
457
|
+
|
458
|
+
##
|
459
|
+
# Set the optional handler for setting/updating the value when a flag is
|
460
|
+
# parsed. It should be a Proc taking two arguments, the new given value
|
461
|
+
# and the previous value, and it should return the new value that should
|
462
|
+
# be set.
|
463
|
+
# @param [Proc] handler
|
464
|
+
#
|
465
|
+
def handler(handler)
|
466
|
+
@handler = handler
|
467
|
+
self
|
468
|
+
end
|
469
|
+
|
470
|
+
##
|
471
|
+
# Set the short description. See {Toys::ConfigDSL#desc} for the allowed
|
472
|
+
# formats.
|
473
|
+
# @param [String,Array<String>,Toys::Utils::WrappableString] desc
|
474
|
+
#
|
475
|
+
def desc(desc)
|
476
|
+
@desc = desc
|
477
|
+
self
|
478
|
+
end
|
479
|
+
|
480
|
+
##
|
481
|
+
# Adds to the long description. This may be called multiple times, and
|
482
|
+
# the results are cumulative. See {Toys::ConfigDSL#long_desc} for the
|
483
|
+
# allowed formats.
|
484
|
+
# @param [String,Array<String>,Toys::Utils::WrappableString...] long_desc
|
485
|
+
#
|
486
|
+
def long_desc(*long_desc)
|
487
|
+
@long_desc += long_desc
|
488
|
+
self
|
489
|
+
end
|
490
|
+
|
491
|
+
## @private
|
492
|
+
def _add_to(tool, key, only_unique)
|
493
|
+
tool.add_flag(key, @flags,
|
494
|
+
accept: @accept, default: @default, handler: @handler,
|
495
|
+
desc: @desc, long_desc: @long_desc,
|
496
|
+
only_unique: only_unique)
|
497
|
+
end
|
498
|
+
end
|
499
|
+
|
500
|
+
##
|
501
|
+
# DSL for an arg definition block. Lets you set arg attributes in a block
|
502
|
+
# instead of a long series of keyword arguments.
|
503
|
+
#
|
504
|
+
class ArgDSL
|
505
|
+
## @private
|
506
|
+
def initialize(accept, default, display_name, desc, long_desc)
|
507
|
+
@accept = accept
|
508
|
+
@default = default
|
509
|
+
@display_name = display_name
|
510
|
+
@desc = desc
|
511
|
+
@long_desc = long_desc
|
512
|
+
end
|
513
|
+
|
514
|
+
##
|
515
|
+
# Set the OptionParser acceptor.
|
516
|
+
# @param [Object] accept
|
517
|
+
#
|
518
|
+
def accept(accept)
|
519
|
+
@accept = accept
|
520
|
+
self
|
521
|
+
end
|
522
|
+
|
523
|
+
##
|
524
|
+
# Set the default value.
|
525
|
+
# @param [Object] default
|
526
|
+
#
|
527
|
+
def default(default)
|
528
|
+
@default = default
|
529
|
+
self
|
530
|
+
end
|
531
|
+
|
532
|
+
##
|
533
|
+
# Set the name of this arg as it appears in help screens.
|
534
|
+
# @param [String] display_name
|
535
|
+
#
|
536
|
+
def display_name(display_name)
|
537
|
+
@handler = display_name
|
538
|
+
self
|
539
|
+
end
|
540
|
+
|
541
|
+
##
|
542
|
+
# Set the short description. See {Toys::ConfigDSL#desc} for the allowed
|
543
|
+
# formats.
|
544
|
+
# @param [String,Array<String>,Toys::Utils::WrappableString] desc
|
545
|
+
#
|
546
|
+
def desc(desc)
|
547
|
+
@desc = desc
|
548
|
+
self
|
549
|
+
end
|
550
|
+
|
551
|
+
##
|
552
|
+
# Adds to the long description. This may be called multiple times, and
|
553
|
+
# the results are cumulative. See {Toys::ConfigDSL#long_desc} for the
|
554
|
+
# allowed formats.
|
555
|
+
# @param [String,Array<String>,Toys::Utils::WrappableString...] long_desc
|
556
|
+
#
|
557
|
+
def long_desc(*long_desc)
|
558
|
+
@long_desc += long_desc
|
559
|
+
self
|
560
|
+
end
|
561
|
+
|
562
|
+
## @private
|
563
|
+
def _add_required_to(tool, key)
|
564
|
+
tool.add_required_arg(key,
|
565
|
+
accept: @accept, display_name: @display_name,
|
566
|
+
desc: @desc, long_desc: @long_desc)
|
567
|
+
end
|
568
|
+
|
569
|
+
## @private
|
570
|
+
def _add_optional_to(tool, key)
|
571
|
+
tool.add_optional_arg(key,
|
572
|
+
accept: @accept, default: @default, display_name: @display_name,
|
573
|
+
desc: @desc, long_desc: @long_desc)
|
574
|
+
end
|
575
|
+
|
576
|
+
## @private
|
577
|
+
def _set_remaining_on(tool, key)
|
578
|
+
tool.set_remaining_args(key,
|
579
|
+
accept: @accept, default: @default, display_name: @display_name,
|
580
|
+
desc: @desc, long_desc: @long_desc)
|
581
|
+
end
|
582
|
+
end
|
583
|
+
|
376
584
|
## @private
|
377
585
|
def _binding
|
378
586
|
binding
|