toys 0.17.1 → 0.18.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.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +8 -0
  3. data/README.md +3 -3
  4. data/core-docs/toys/acceptor.rb +474 -0
  5. data/core-docs/toys/arg_parser.rb +397 -0
  6. data/core-docs/toys/cli.rb +466 -0
  7. data/core-docs/toys/compat.rb +2 -0
  8. data/core-docs/toys/completion.rb +340 -0
  9. data/core-docs/toys/context.rb +386 -0
  10. data/core-docs/toys/core.rb +14 -0
  11. data/core-docs/toys/dsl/base.rb +56 -0
  12. data/core-docs/toys/dsl/flag.rb +287 -0
  13. data/core-docs/toys/dsl/flag_group.rb +270 -0
  14. data/core-docs/toys/dsl/internal.rb +4 -0
  15. data/core-docs/toys/dsl/positional_arg.rb +155 -0
  16. data/core-docs/toys/dsl/tool.rb +1665 -0
  17. data/core-docs/toys/errors.rb +126 -0
  18. data/core-docs/toys/flag.rb +563 -0
  19. data/core-docs/toys/flag_group.rb +186 -0
  20. data/core-docs/toys/input_file.rb +17 -0
  21. data/core-docs/toys/loader.rb +411 -0
  22. data/core-docs/toys/middleware.rb +336 -0
  23. data/core-docs/toys/mixin.rb +142 -0
  24. data/core-docs/toys/module_lookup.rb +75 -0
  25. data/core-docs/toys/positional_arg.rb +145 -0
  26. data/core-docs/toys/settings.rb +524 -0
  27. data/core-docs/toys/source_info.rb +321 -0
  28. data/core-docs/toys/standard_middleware/add_verbosity_flags.rb +49 -0
  29. data/core-docs/toys/standard_middleware/apply_config.rb +24 -0
  30. data/core-docs/toys/standard_middleware/handle_usage_errors.rb +33 -0
  31. data/core-docs/toys/standard_middleware/set_default_descriptions.rb +222 -0
  32. data/core-docs/toys/standard_middleware/show_help.rb +190 -0
  33. data/core-docs/toys/standard_middleware/show_root_version.rb +45 -0
  34. data/core-docs/toys/standard_mixins/bundler.rb +98 -0
  35. data/core-docs/toys/standard_mixins/exec.rb +711 -0
  36. data/core-docs/toys/standard_mixins/fileutils.rb +18 -0
  37. data/core-docs/toys/standard_mixins/gems.rb +74 -0
  38. data/core-docs/toys/standard_mixins/git_cache.rb +41 -0
  39. data/core-docs/toys/standard_mixins/highline.rb +133 -0
  40. data/core-docs/toys/standard_mixins/pager.rb +50 -0
  41. data/core-docs/toys/standard_mixins/terminal.rb +135 -0
  42. data/core-docs/toys/standard_mixins/xdg.rb +49 -0
  43. data/core-docs/toys/template.rb +112 -0
  44. data/core-docs/toys/tool_definition.rb +1080 -0
  45. data/core-docs/toys/utils/completion_engine.rb +49 -0
  46. data/core-docs/toys/utils/exec.rb +776 -0
  47. data/core-docs/toys/utils/gems.rb +185 -0
  48. data/core-docs/toys/utils/git_cache.rb +368 -0
  49. data/core-docs/toys/utils/help_text.rb +134 -0
  50. data/core-docs/toys/utils/pager.rb +118 -0
  51. data/core-docs/toys/utils/standard_ui.rb +184 -0
  52. data/core-docs/toys/utils/terminal.rb +310 -0
  53. data/core-docs/toys/utils/xdg.rb +253 -0
  54. data/core-docs/toys/wrappable_string.rb +132 -0
  55. data/core-docs/toys-core.rb +111 -0
  56. data/lib/toys/version.rb +1 -1
  57. metadata +57 -5
@@ -0,0 +1,1665 @@
1
+ module Toys
2
+ module DSL
3
+ ##
4
+ # **_Defined in the toys-core gem_**
5
+ #
6
+ # This module defines the DSL for a Toys configuration file.
7
+ #
8
+ # A Toys configuration defines one or more named tools. It provides syntax
9
+ # for setting the description, defining flags and arguments, specifying
10
+ # how to execute the tool, and requesting mixin modules and other services.
11
+ # It also lets you define subtools, nested arbitrarily deep, using blocks.
12
+ #
13
+ # ### Simple example
14
+ #
15
+ # Create a file called `.toys.rb` in the current directory, with the
16
+ # following contents:
17
+ #
18
+ # tool "greet" do
19
+ # desc "Prints a simple greeting"
20
+ #
21
+ # optional_arg :recipient, default: "world"
22
+ #
23
+ # def run
24
+ # puts "Hello, #{recipient}!"
25
+ # end
26
+ # end
27
+ #
28
+ # The DSL directives `tool`, `desc`, `optional_arg`, and others are defined
29
+ # in this module.
30
+ #
31
+ # Now you can execute it using:
32
+ #
33
+ # toys greet
34
+ #
35
+ # or try:
36
+ #
37
+ # toys greet rubyists
38
+ #
39
+ module Tool
40
+ ##
41
+ # Create a named acceptor that can be referenced by name from any flag or
42
+ # positional argument in this tool or its subtools.
43
+ #
44
+ # An acceptor validates the string parameter passed to a flag or
45
+ # positional argument. It also optionally converts the string to a
46
+ # different object before storing it in your tool's data.
47
+ #
48
+ # Acceptors can be defined in one of four ways.
49
+ #
50
+ # * You can provide a **regular expression**. This acceptor validates
51
+ # only if the regex matches the *entire string parameter*.
52
+ #
53
+ # You can also provide an optional conversion function as a block. If
54
+ # provided, function must take a variable number of arguments, the
55
+ # first being the matched string and the remainder being the captures
56
+ # from the regular expression. It should return the converted object
57
+ # that will be stored in the context data. If you do not provide a
58
+ # block, the original string will be used.
59
+ #
60
+ # * You can provide an **array** of possible values. The acceptor
61
+ # validates if the string parameter matches the *string form* of one
62
+ # of the array elements (i.e. the results of calling `to_s` on the
63
+ # array elements.)
64
+ #
65
+ # An array acceptor automatically converts the string parameter to
66
+ # the actual array element that it matched. For example, if the
67
+ # symbol `:foo` is in the array, it will match the string `"foo"`,
68
+ # and then store the symbol `:foo` in the tool data.
69
+ #
70
+ # * You can provide a **range** of possible values, along with a
71
+ # conversion function that converts a string parameter to a type
72
+ # comparable by the range. (See the "function" spec below for a
73
+ # detailed description of conversion functions.) If the range has
74
+ # numeric endpoints, the conversion function is optional because a
75
+ # default will be provided.
76
+ #
77
+ # * You can provide a **function** by passing it as a proc or a block.
78
+ # This function performs *both* validation and conversion. It should
79
+ # take the string parameter as its argument, and it must either
80
+ # return the object that should be stored in the tool data, or raise
81
+ # an exception (descended from `StandardError`) to indicate that the
82
+ # string parameter is invalid.
83
+ #
84
+ # ### Example
85
+ #
86
+ # The following example creates an acceptor named "hex" that is defined
87
+ # via a regular expression. It uses the acceptor to validate values
88
+ # passed to a flag.
89
+ #
90
+ # tool "example" do
91
+ # acceptor "hex", /[0-9a-fA-F]+/, type_desc: "hex numbers"
92
+ # flag :number, accept: "hex"
93
+ # def run
94
+ # puts "number was #{number}"
95
+ # end
96
+ # end
97
+ #
98
+ # @param name [String] The acceptor name.
99
+ # @param spec [Object] See the description for recognized values.
100
+ # @param type_desc [String] Type description string, shown in help.
101
+ # Defaults to the acceptor name.
102
+ # @param block [Proc] See the description for recognized forms.
103
+ # @return [self]
104
+ #
105
+ def acceptor(name, spec = nil, type_desc: nil, &block)
106
+ # Source available in the toys-core gem
107
+ end
108
+
109
+ ##
110
+ # Create a named mixin module that can be included by name from this tool
111
+ # or its subtools.
112
+ #
113
+ # A mixin is a module that defines methods that can be called from a
114
+ # tool. It is commonly used to provide "utility" methods, implementing
115
+ # common functionality and allowing tools to share code.
116
+ #
117
+ # Normally you provide a block and define the mixin's methods in that
118
+ # block. Alternatively, you can create a module separately and pass it
119
+ # directly to this directive.
120
+ #
121
+ # ### Example
122
+ #
123
+ # The following example creates a named mixin and uses it in a tool.
124
+ #
125
+ # mixin "error-reporter" do
126
+ # def error message
127
+ # logger.error "An error occurred: #{message}"
128
+ # exit 1
129
+ # end
130
+ # end
131
+ #
132
+ # tool "build" do
133
+ # include "error-reporter"
134
+ # def run
135
+ # puts "Building..."
136
+ # error "Build failed!"
137
+ # end
138
+ # end
139
+ #
140
+ # @param name [String] Name of the mixin
141
+ # @param mixin_module [Module] Module to use as the mixin. Optional.
142
+ # Either pass a module here, *or* provide a block and define the
143
+ # mixin within the block.
144
+ # @param block [Proc] Defines the mixin module.
145
+ # @return [self]
146
+ #
147
+ def mixin(name, mixin_module = nil, &block)
148
+ # Source available in the toys-core gem
149
+ end
150
+
151
+ ##
152
+ # Create a named template that can be expanded by name from this tool
153
+ # or its subtools.
154
+ #
155
+ # A template is an object that generates DSL directives. You can use it
156
+ # to build "prefabricated" tools, and then instantiate them in your Toys
157
+ # files.
158
+ #
159
+ # A template is an object that defines an `expansion` procedure. This
160
+ # procedure generates the DSL directives implemented by the template. The
161
+ # template object typically also includes attributes that are used to
162
+ # configure the expansion.
163
+ #
164
+ # The simplest way to define a template is to pass a block to the
165
+ # {#template} directive. In the block, define an `initialize` method that
166
+ # accepts any arguments that may be passed to the template when it is
167
+ # instantiated and are used to configure the template. Define
168
+ # `attr_reader`s or other methods to make this configuration accessible
169
+ # from the object. Then define an `on_expand` block that implements the
170
+ # template's expansion. The template object is passed as an object to the
171
+ # `on_expand` block.
172
+ #
173
+ # Alternately, you can create a template class separately and pass it
174
+ # directly. See {Toys::Template} for details on creating a template
175
+ # class.
176
+ #
177
+ # ### Example
178
+ #
179
+ # The following example creates and uses a simple template. The template
180
+ # defines a tool, with a configurable name, that simply prints out a
181
+ # configurable message.
182
+ #
183
+ # template "hello-generator" do
184
+ # def initialize(name, message)
185
+ # @name = name
186
+ # @message = message
187
+ # end
188
+ # attr_reader :name, :message
189
+ # on_expand do |template|
190
+ # tool template.name do
191
+ # to_run do
192
+ # puts template.message
193
+ # end
194
+ # end
195
+ # end
196
+ # end
197
+ #
198
+ # expand "hello-generator", "mytool", "mytool is running!"
199
+ #
200
+ # @param name [String] Name of the template
201
+ # @param template_class [Class] Module to use as the mixin. Optional.
202
+ # Either pass a module here, *or* provide a block and define the
203
+ # mixin within the block.
204
+ # @param block [Proc] Defines the template class.
205
+ # @return [self]
206
+ #
207
+ def template(name, template_class = nil, &block)
208
+ # Source available in the toys-core gem
209
+ end
210
+
211
+ ##
212
+ # Create a named completion procedure that may be used by name by any
213
+ # flag or positional arg in this tool or any subtool.
214
+ #
215
+ # A completion controls tab completion for the value of a flag or
216
+ # positional argument. In general, it is a Ruby `Proc` that takes a
217
+ # context object (of type {Toys::Completion::Context}) and returns an
218
+ # array of completion candidate strings.
219
+ #
220
+ # Completions can be specified in one of three ways.
221
+ #
222
+ # * A Proc object itself, either passed directly to this directive or
223
+ # provided as a block.
224
+ # * A static array of strings, indicating the completion candidates
225
+ # independent of context.
226
+ # * The symbol `:file_system` which indicates that paths in the file
227
+ # system should serve as completion candidates.
228
+ #
229
+ # ### Example
230
+ #
231
+ # The following example defines a completion that uses only the immediate
232
+ # files in the current directory as candidates. (This is different from
233
+ # the `:file_system` completion which will descend into subdirectories
234
+ # similar to how bash completes most of its file system commands.)
235
+ #
236
+ # completion "local-files" do |_context|
237
+ # `/bin/ls`.split("\n")
238
+ # end
239
+ # tool "example" do
240
+ # flag :file, complete_values: "local-files"
241
+ # def run
242
+ # puts "selected file #{file}"
243
+ # end
244
+ # end
245
+ #
246
+ # @param name [String] Name of the completion
247
+ # @param spec [Object] See the description for recognized values.
248
+ # @param options [Hash] Additional options to pass to the completion.
249
+ # @param block [Proc] See the description for recognized forms.
250
+ # @return [self]
251
+ #
252
+ def completion(name, spec = nil, **options, &block)
253
+ # Source available in the toys-core gem
254
+ end
255
+
256
+ ##
257
+ # Create a subtool. You must provide a block defining the subtool.
258
+ #
259
+ # ### Example
260
+ #
261
+ # The following example defines a tool and two subtools within it.
262
+ #
263
+ # tool "build" do
264
+ # tool "staging" do
265
+ # def run
266
+ # puts "Building staging"
267
+ # end
268
+ # end
269
+ # tool "production" do
270
+ # def run
271
+ # puts "Building production"
272
+ # end
273
+ # end
274
+ # end
275
+ #
276
+ # The following example uses `delegate_to` to define a tool that runs one
277
+ # of its subtools.
278
+ #
279
+ # tool "test", delegate_to: ["test", "unit"] do
280
+ # tool "unit" do
281
+ # def run
282
+ # puts "Running unit tests"
283
+ # end
284
+ # end
285
+ # end
286
+ #
287
+ # @param words [String,Array<String>] The name of the subtool
288
+ # @param if_defined [:combine,:reset,:ignore] What to do if a definition
289
+ # already exists for this tool. Possible values are `:combine` (the
290
+ # default) indicating the definition should be combined with the
291
+ # existing definition, `:reset` indicating the earlier definition
292
+ # should be reset and the new definition applied instead, or
293
+ # `:ignore` indicating the new definition should be ignored.
294
+ # @param delegate_to [String,Array<String>] Optional. This tool should
295
+ # delegate to another tool, specified by the full path. This path may
296
+ # be given as an array of strings, or a single string possibly
297
+ # delimited by path separators.
298
+ # @param delegate_relative [String,Array<String>] Optional. Similar to
299
+ # delegate_to, but takes a delegate name relative to the context in
300
+ # which this tool is being defined.
301
+ # @param block [Proc] Defines the subtool.
302
+ # @return [self]
303
+ #
304
+ def tool(words, if_defined: :combine, delegate_to: nil, delegate_relative: nil, &block)
305
+ # Source available in the toys-core gem
306
+ end
307
+
308
+ ##
309
+ # Create an alias, representing an "alternate name" for a tool.
310
+ #
311
+ # Note: This is functionally equivalent to creating a tool with the
312
+ # `:delegate_relative` option. As such, `alias_tool` is considered
313
+ # deprecated.
314
+ #
315
+ # ### Example
316
+ #
317
+ # This example defines a tool and an alias pointing to it. Both the tool
318
+ # name `test` and the alias `t` will then refer to the same tool.
319
+ #
320
+ # tool "test" do
321
+ # def run
322
+ # puts "Running tests..."
323
+ # end
324
+ # end
325
+ # alias_tool "t", "test"
326
+ # # Note: the following is preferred over alias_tool:
327
+ # # tool "t", delegate_relative: "test"
328
+ #
329
+ # @param word [String] The name of the alias
330
+ # @param target [String,Array<String>] Relative path to the target of the
331
+ # alias. This path may be given as an array of strings, or a single
332
+ # string possibly delimited by path separators.
333
+ # @return [self]
334
+ # @deprecated Use {#tool} and pass `:delegate_relative` instead
335
+ #
336
+ def alias_tool(word, target)
337
+ # Source available in the toys-core gem
338
+ end
339
+
340
+ ##
341
+ # Causes the current tool to delegate to another tool, specified by the
342
+ # full tool name. When run, it simply invokes the target tool with the
343
+ # same arguments.
344
+ #
345
+ # ### Example
346
+ #
347
+ # This example defines a tool that runs one of its subtools. Running the
348
+ # `test` tool will have the same effect (and recognize the same args) as
349
+ # the subtool `test unit`.
350
+ #
351
+ # tool "test" do
352
+ # tool "unit" do
353
+ # flag :faster
354
+ # def run
355
+ # puts "running tests..."
356
+ # end
357
+ # end
358
+ # delegate_to "test:unit"
359
+ # end
360
+ #
361
+ # @param target [String,Array<String>] The full path to the delegate
362
+ # tool. This path may be given as an array of strings, or a single
363
+ # string possibly delimited by path separators.
364
+ # @return [self]
365
+ #
366
+ def delegate_to(target)
367
+ # Source available in the toys-core gem
368
+ end
369
+
370
+ ##
371
+ # Load another config file or directory, as if its contents were inserted
372
+ # at the current location.
373
+ #
374
+ # @param path [String] The file or directory to load.
375
+ # @param as [String] Load into the given tool/namespace. If omitted,
376
+ # configuration will be loaded into the current namespace.
377
+ #
378
+ # @return [self]
379
+ #
380
+ def load(path, as: nil)
381
+ # Source available in the toys-core gem
382
+ end
383
+
384
+ ##
385
+ # Load configuration from a public git repository, as if its contents
386
+ # were inserted at the current location.
387
+ #
388
+ # @param remote [String] The URL of the git repository. Defaults to the
389
+ # current repository if already loading from git.
390
+ # @param path [String] The path within the repo to the file or directory
391
+ # to load. Defaults to the root of the repo.
392
+ # @param commit [String] The commit branch, tag, or sha. Defaults to the
393
+ # current commit if already loading from git, or to `HEAD`.
394
+ # @param as [String] Load into the given tool/namespace. If omitted,
395
+ # configuration will be loaded into the current namespace.
396
+ # @param update [Boolean,Integer] Whether and when to force-fetch from
397
+ # the remote (unless the commit is a SHA). Force-fetching will ensure
398
+ # that symbolic commits, such as branch names or HEAD, are up to date.
399
+ # You can pass `true` or `false` to specify whether to update, or an
400
+ # integer to update if the last update was done at least that many
401
+ # seconds ago. Default is false.
402
+ #
403
+ # @return [self]
404
+ #
405
+ def load_git(remote: nil, path: nil, commit: nil, as: nil, update: false)
406
+ # Source available in the toys-core gem
407
+ end
408
+
409
+ ##
410
+ # Load configuration from a gem, as if its contents were inserted at the
411
+ # current location.
412
+ #
413
+ # @param name [String] Name of the gem
414
+ # @param versions [Array<String>] Version requirements for the gem.
415
+ # @param version [String,Array<String>] An alternate way to specify
416
+ # version requirements for the gem.
417
+ # @param path [String] Optional path within the gem to the file or
418
+ # directory to load. Defaults to the root of the gem's toys directory.
419
+ # @param toys_dir [String] Optional override for the gem's toys
420
+ # directory name. If not specified, the default specified by the gem
421
+ # will be used.
422
+ # @param as [String] Load into the given tool/namespace. If omitted,
423
+ # configuration will be loaded into the current namespace.
424
+ #
425
+ def load_gem(name, *versions, version: nil, path: nil, toys_dir: nil, as: nil)
426
+ # Source available in the toys-core gem
427
+ end
428
+
429
+ ##
430
+ # Expand the given template in the current location.
431
+ #
432
+ # The template may be specified as a class or a well-known template name.
433
+ # You may also provide arguments to pass to the template.
434
+ #
435
+ # ### Example
436
+ #
437
+ # The following example creates and uses a simple template.
438
+ #
439
+ # template "hello-generator" do
440
+ # def initialize(name, message)
441
+ # @name = name
442
+ # @message = message
443
+ # end
444
+ # attr_reader :name, :message
445
+ # expansion do |template|
446
+ # tool template.name do
447
+ # to_run do
448
+ # puts template.message
449
+ # end
450
+ # end
451
+ # end
452
+ # end
453
+ #
454
+ # expand "hello-generator", "mytool", "mytool is running!"
455
+ #
456
+ # @param template_class [Class,String,Symbol] The template, either as a
457
+ # class or a well-known name.
458
+ # @param args [Object...] Template arguments
459
+ # @return [self]
460
+ #
461
+ def expand(template_class, *args, **kwargs)
462
+ # Source available in the toys-core gem
463
+ end
464
+
465
+ ##
466
+ # Set the short description for the current tool. The short description
467
+ # is displayed with the tool in a subtool list. You may also use the
468
+ # equivalent method `short_desc`.
469
+ #
470
+ # The description is a {Toys::WrappableString}, which may be word-wrapped
471
+ # when displayed in a help screen. You may pass a {Toys::WrappableString}
472
+ # directly to this method, or you may pass any input that can be used to
473
+ # construct a wrappable string:
474
+ #
475
+ # * If you pass a String, its whitespace will be compacted (i.e. tabs,
476
+ # newlines, and multiple consecutive whitespace will be turned into a
477
+ # single space), and it will be word-wrapped on whitespace.
478
+ # * If you pass an Array of Strings, each string will be considered a
479
+ # literal word that cannot be broken, and wrapping will be done
480
+ # across the strings in the array. In this case, whitespace is not
481
+ # compacted.
482
+ #
483
+ # ### Examples
484
+ #
485
+ # If you pass in a sentence as a simple string, it may be word wrapped
486
+ # when displayed:
487
+ #
488
+ # desc "This sentence may be wrapped."
489
+ #
490
+ # To specify a sentence that should never be word-wrapped, pass it as the
491
+ # sole element of a string array:
492
+ #
493
+ # desc ["This sentence will not be wrapped."]
494
+ #
495
+ # @param str [Toys::WrappableString,String,Array<String>]
496
+ # @return [self]
497
+ #
498
+ def desc(str)
499
+ # Source available in the toys-core gem
500
+ end
501
+ alias short_desc desc
502
+
503
+ ##
504
+ # Add to the long description for the current tool. The long description
505
+ # is displayed in the usage documentation for the tool itself. This
506
+ # directive may be given multiple times, and the results are cumulative.
507
+ #
508
+ # A long description is a series of descriptions, which are generally
509
+ # displayed in a series of lines/paragraphs. Each individual description
510
+ # uses the form described in the {#desc} documentation, and may be
511
+ # word-wrapped when displayed. To insert a blank line, include an empty
512
+ # string as one of the descriptions.
513
+ #
514
+ # ### Example
515
+ #
516
+ # long_desc "This initial paragraph might get word wrapped.",
517
+ # "This next paragraph is followed by a blank line.",
518
+ # "",
519
+ # ["This line will not be wrapped."],
520
+ # [" This indent is preserved."]
521
+ # long_desc "This line is appended to the description."
522
+ #
523
+ # @param strs [Toys::WrappableString,String,Array<String>...]
524
+ # @param file [String] Optional. Read the description from the given file
525
+ # provided relative to the current toys file. The file must be a
526
+ # plain text file whose suffix is `.txt`.
527
+ # @param data [String] Optional. Read the description from the given data
528
+ # file. The file must be a plain text file whose suffix is `.txt`.
529
+ # @return [self]
530
+ #
531
+ def long_desc(*strs, file: nil, data: nil)
532
+ # Source available in the toys-core gem
533
+ end
534
+
535
+ ##
536
+ # Create a flag group. If a block is given, flags defined in the block
537
+ # belong to the group. The flags in the group are listed together in
538
+ # help screens.
539
+ #
540
+ # ### Example
541
+ #
542
+ # The following example creates a flag group in which all flags are
543
+ # optional.
544
+ #
545
+ # tool "execute" do
546
+ # flag_group desc: "Debug Flags" do
547
+ # flag :debug, "-D", desc: "Enable debugger"
548
+ # flag :warnings, "-W[VAL]", desc: "Enable warnings"
549
+ # end
550
+ # # ...
551
+ # end
552
+ #
553
+ # @param type [Symbol] The type of group. Allowed values: `:required`,
554
+ # `:optional`, `:exactly_one`, `:at_most_one`, `:at_least_one`.
555
+ # Default is `:optional`.
556
+ # @param desc [String,Array<String>,Toys::WrappableString] Short
557
+ # description for the group. See {Toys::DSL::Tool#desc} for a
558
+ # description of allowed formats. Defaults to `"Flags"`.
559
+ # @param long_desc [Array<String,Array<String>,Toys::WrappableString>]
560
+ # Long description for the flag group. See
561
+ # {Toys::DSL::Tool#long_desc} for a description of allowed formats.
562
+ # Defaults to the empty array.
563
+ # @param name [String,Symbol,nil] The name of the group, or nil for no
564
+ # name.
565
+ # @param report_collisions [Boolean] If `true`, raise an exception if a
566
+ # the given name is already taken. If `false`, ignore. Default is
567
+ # `true`.
568
+ # @param prepend [Boolean] If `true`, prepend rather than append the
569
+ # group to the list. Default is `false`.
570
+ # @param block [Proc] Adds flags to the group. See {Toys::DSL::FlagGroup}
571
+ # for the directives that can be called in this block.
572
+ # @return [self]
573
+ #
574
+ def flag_group(type: :optional, desc: nil, long_desc: nil, name: nil,
575
+ report_collisions: true, prepend: false, &block)
576
+ # Source available in the toys-core gem
577
+ end
578
+
579
+ ##
580
+ # Create a flag group of type `:required`. If a block is given, flags
581
+ # defined in the block belong to the group. All flags in this group are
582
+ # required.
583
+ #
584
+ # ### Example
585
+ #
586
+ # The following example creates a group of required flags.
587
+ #
588
+ # tool "login" do
589
+ # all_required do
590
+ # flag :username, "--username=VAL", desc: "Set username (required)"
591
+ # flag :password, "--password=VAL", desc: "Set password (required)"
592
+ # end
593
+ # # ...
594
+ # end
595
+ #
596
+ # @param desc [String,Array<String>,Toys::WrappableString] Short
597
+ # description for the group. See {Toys::DSL::Tool#desc} for a
598
+ # description of allowed formats. Defaults to `"Flags"`.
599
+ # @param long_desc [Array<String,Array<String>,Toys::WrappableString>]
600
+ # Long description for the flag group. See
601
+ # {Toys::DSL::Tool#long_desc} for a description of allowed formats.
602
+ # Defaults to the empty array.
603
+ # @param name [String,Symbol,nil] The name of the group, or nil for no
604
+ # name.
605
+ # @param report_collisions [Boolean] If `true`, raise an exception if a
606
+ # the given name is already taken. If `false`, ignore. Default is
607
+ # `true`.
608
+ # @param prepend [Boolean] If `true`, prepend rather than append the
609
+ # group to the list. Default is `false`.
610
+ # @param block [Proc] Adds flags to the group. See {Toys::DSL::FlagGroup}
611
+ # for the directives that can be called in this block.
612
+ # @return [self]
613
+ #
614
+ def all_required(desc: nil, long_desc: nil, name: nil, report_collisions: true,
615
+ prepend: false, &block)
616
+ # Source available in the toys-core gem
617
+ end
618
+
619
+ ##
620
+ # Create a flag group of type `:at_most_one`. If a block is given, flags
621
+ # defined in the block belong to the group. At most one flag in this
622
+ # group must be provided on the command line.
623
+ #
624
+ # ### Example
625
+ #
626
+ # The following example creates a group of flags in which either one or
627
+ # none may be set, but not more than one.
628
+ #
629
+ # tool "provision-server" do
630
+ # at_most_one do
631
+ # flag :restore_from_backup, "--restore-from-backup=VAL"
632
+ # flag :restore_from_image, "--restore-from-image=VAL"
633
+ # flag :clone_existing, "--clone-existing=VAL"
634
+ # end
635
+ # # ...
636
+ # end
637
+ #
638
+ # @param desc [String,Array<String>,Toys::WrappableString] Short
639
+ # description for the group. See {Toys::DSL::Tool#desc} for a
640
+ # description of allowed formats. Defaults to `"Flags"`.
641
+ # @param long_desc [Array<String,Array<String>,Toys::WrappableString>]
642
+ # Long description for the flag group. See
643
+ # {Toys::DSL::Tool#long_desc} for a description of allowed formats.
644
+ # Defaults to the empty array.
645
+ # @param name [String,Symbol,nil] The name of the group, or nil for no
646
+ # name.
647
+ # @param report_collisions [Boolean] If `true`, raise an exception if a
648
+ # the given name is already taken. If `false`, ignore. Default is
649
+ # `true`.
650
+ # @param prepend [Boolean] If `true`, prepend rather than append the
651
+ # group to the list. Default is `false`.
652
+ # @param block [Proc] Adds flags to the group. See {Toys::DSL::FlagGroup}
653
+ # for the directives that can be called in this block.
654
+ # @return [self]
655
+ #
656
+ def at_most_one(desc: nil, long_desc: nil, name: nil, report_collisions: true,
657
+ prepend: false, &block)
658
+ # Source available in the toys-core gem
659
+ end
660
+ alias at_most_one_required at_most_one
661
+
662
+ ##
663
+ # Create a flag group of type `:at_least_one`. If a block is given, flags
664
+ # defined in the block belong to the group. At least one flag in this
665
+ # group must be provided on the command line.
666
+ #
667
+ # ### Example
668
+ #
669
+ # The following example creates a group of flags in which one or more
670
+ # may be set.
671
+ #
672
+ # tool "run-tests" do
673
+ # at_least_one do
674
+ # flag :unit, desc: "Run unit tests"
675
+ # flag :integration, desc: "Run integration tests"
676
+ # flag :performance, desc: "Run performance tests"
677
+ # end
678
+ # # ...
679
+ # end
680
+ #
681
+ # @param desc [String,Array<String>,Toys::WrappableString] Short
682
+ # description for the group. See {Toys::DSL::Tool#desc} for a
683
+ # description of allowed formats. Defaults to `"Flags"`.
684
+ # @param long_desc [Array<String,Array<String>,Toys::WrappableString>]
685
+ # Long description for the flag group. See
686
+ # {Toys::DSL::Tool#long_desc} for a description of allowed formats.
687
+ # Defaults to the empty array.
688
+ # @param name [String,Symbol,nil] The name of the group, or nil for no
689
+ # name.
690
+ # @param report_collisions [Boolean] If `true`, raise an exception if a
691
+ # the given name is already taken. If `false`, ignore. Default is
692
+ # `true`.
693
+ # @param prepend [Boolean] If `true`, prepend rather than append the
694
+ # group to the list. Default is `false`.
695
+ # @param block [Proc] Adds flags to the group. See {Toys::DSL::FlagGroup}
696
+ # for the directives that can be called in this block.
697
+ # @return [self]
698
+ #
699
+ def at_least_one(desc: nil, long_desc: nil, name: nil, report_collisions: true,
700
+ prepend: false, &block)
701
+ # Source available in the toys-core gem
702
+ end
703
+ alias at_least_one_required at_least_one
704
+
705
+ ##
706
+ # Create a flag group of type `:exactly_one`. If a block is given, flags
707
+ # defined in the block belong to the group. Exactly one flag in this
708
+ # group must be provided on the command line.
709
+ #
710
+ # ### Example
711
+ #
712
+ # The following example creates a group of flags in which exactly one
713
+ # must be set.
714
+ #
715
+ # tool "deploy" do
716
+ # exactly_one do
717
+ # flag :server, "--server=IP_ADDR", desc: "Deploy to server"
718
+ # flag :vm, "--vm=ID", desc: "Deploy to a VM"
719
+ # flag :container, "--container=ID", desc: "Deploy to a container"
720
+ # end
721
+ # # ...
722
+ # end
723
+ #
724
+ # @param desc [String,Array<String>,Toys::WrappableString] Short
725
+ # description for the group. See {Toys::DSL::Tool#desc} for a
726
+ # description of allowed formats. Defaults to `"Flags"`.
727
+ # @param long_desc [Array<String,Array<String>,Toys::WrappableString>]
728
+ # Long description for the flag group. See
729
+ # {Toys::DSL::Tool#long_desc} for a description of allowed formats.
730
+ # Defaults to the empty array.
731
+ # @param name [String,Symbol,nil] The name of the group, or nil for no
732
+ # name.
733
+ # @param report_collisions [Boolean] If `true`, raise an exception if a
734
+ # the given name is already taken. If `false`, ignore. Default is
735
+ # `true`.
736
+ # @param prepend [Boolean] If `true`, prepend rather than append the
737
+ # group to the list. Default is `false`.
738
+ # @param block [Proc] Adds flags to the group. See {Toys::DSL::FlagGroup}
739
+ # for the directives that can be called in this block.
740
+ # @return [self]
741
+ #
742
+ def exactly_one(desc: nil, long_desc: nil, name: nil, report_collisions: true,
743
+ prepend: false, &block)
744
+ # Source available in the toys-core gem
745
+ end
746
+ alias exactly_one_required exactly_one
747
+
748
+ ##
749
+ # Add a flag to the current tool. Each flag must specify a key which
750
+ # the script may use to obtain the flag value from the context.
751
+ # You may then provide the flags themselves in OptionParser form.
752
+ #
753
+ # If the given key is a symbol representing a valid method name, then a
754
+ # helper method is automatically added to retrieve the value. Otherwise,
755
+ # if the key is a string or does not represent a valid method name, the
756
+ # tool can retrieve the value by calling {Toys::Context#get}.
757
+ #
758
+ # Attributes of the flag may be passed in as arguments to this method, or
759
+ # set in a block passed to this method. If you provide a block, you can
760
+ # use directives in {Toys::DSL::Flag} within the block.
761
+ #
762
+ # ### Flag syntax
763
+ #
764
+ # The flags themselves should be provided in OptionParser form. Following
765
+ # are examples of valid syntax.
766
+ #
767
+ # * `-a` : A short boolean switch. When this appears as an argument,
768
+ # the value is set to `true`.
769
+ # * `--abc` : A long boolean switch. When this appears as an argument,
770
+ # the value is set to `true`.
771
+ # * `-aVAL` or `-a VAL` : A short flag that takes a required value.
772
+ # These two forms are treated identically. If this argument appears
773
+ # with a value attached (e.g. `-afoo`), the attached string (e.g.
774
+ # `"foo"`) is taken as the value. Otherwise, the following argument
775
+ # is taken as the value (e.g. for `-a foo`, the value is set to
776
+ # `"foo"`.) The following argument is treated as the value even if it
777
+ # looks like a flag (e.g. `-a -a` causes the string `"-a"` to be
778
+ # taken as the value.)
779
+ # * `-a[VAL]` : A short flag that takes an optional value. If this
780
+ # argument appears with a value attached (e.g. `-afoo`), the attached
781
+ # string (e.g. `"foo"`) is taken as the value. Otherwise, the value
782
+ # is set to `true`. The following argument is never interpreted as
783
+ # the value. (Compare with `-a [VAL]`.)
784
+ # * `-a [VAL]` : A short flag that takes an optional value. If this
785
+ # argument appears with a value attached (e.g. `-afoo`), the attached
786
+ # string (e.g. `"foo"`) is taken as the value. Otherwise, if the
787
+ # following argument does not look like a flag (i.e. it does not
788
+ # begin with a hyphen), it is taken as the value. (e.g. `-a foo`
789
+ # causes the string `"foo"` to be taken as the value.). If there is
790
+ # no following argument, or the following argument looks like a flag,
791
+ # the value is set to `true`. (Compare with `-a[VAL]`.)
792
+ # * `--abc=VAL` or `--abc VAL` : A long flag that takes a required
793
+ # value. These two forms are treated identically. If this argument
794
+ # appears with a value attached (e.g. `--abc=foo`), the attached
795
+ # string (e.g. `"foo"`) is taken as the value. Otherwise, the
796
+ # following argument is taken as the value (e.g. for `--abc foo`, the
797
+ # value is set to `"foo"`.) The following argument is treated as the
798
+ # value even if it looks like a flag (e.g. `--abc --def` causes the
799
+ # string `"--def"` to be taken as the value.)
800
+ # * `--abc[=VAL]` : A long flag that takes an optional value. If this
801
+ # argument appears with a value attached (e.g. `--abc=foo`), the
802
+ # attached string (e.g. `"foo"`) is taken as the value. Otherwise,
803
+ # the value is set to `true`. The following argument is never
804
+ # interpreted as the value. (Compare with `--abc [VAL]`.)
805
+ # * `--abc [VAL]` : A long flag that takes an optional value. If this
806
+ # argument appears with a value attached (e.g. `--abc=foo`), the
807
+ # attached string (e.g. `"foo"`) is taken as the value. Otherwise, if
808
+ # the following argument does not look like a flag (i.e. it does not
809
+ # begin with a hyphen), it is taken as the value. (e.g. `--abc foo`
810
+ # causes the string `"foo"` to be taken as the value.). If there is
811
+ # no following argument, or the following argument looks like a flag,
812
+ # the value is set to `true`. (Compare with `--abc=[VAL]`.)
813
+ # * `--[no-]abc` : A long boolean switch that can be turned either on
814
+ # or off. This effectively creates two flags, `--abc` which sets the
815
+ # value to `true`, and `--no-abc` which sets the falue to `false`.
816
+ #
817
+ # ### Default flag syntax
818
+ #
819
+ # If no flag syntax strings are provided, a default syntax will be
820
+ # inferred based on the key and other options.
821
+ #
822
+ # Specifically, if the key has one character, then that character will be
823
+ # chosen as a short flag. If the key has multiple characters, a long flag
824
+ # will be generated.
825
+ #
826
+ # Furthermore, if a custom completion, a non-boolean acceptor, or a
827
+ # non-boolean default value is provided in the options, then the flag
828
+ # will be considered to take a value. Otherwise, it will be considered to
829
+ # be a boolean switch.
830
+ #
831
+ # For example, the following pairs of flags are identical:
832
+ #
833
+ # flag :a
834
+ # flag :a, "-a"
835
+ #
836
+ # flag :abc_def
837
+ # flag :abc_def, "--abc-def"
838
+ #
839
+ # flag :number, accept: Integer
840
+ # flag :number, "--number=VAL", accept: Integer
841
+ #
842
+ # ### More examples
843
+ #
844
+ # A flag that sets its value to the number of times it appears on the
845
+ # command line:
846
+ #
847
+ # flag :verbose, "-v", "--verbose",
848
+ # default: 0, handler: ->(_val, count) { count + 1 }
849
+ #
850
+ # An example using block form:
851
+ #
852
+ # flag :shout do
853
+ # flags "-s", "--shout"
854
+ # default false
855
+ # desc "Say it louder"
856
+ # long_desc "This flag says it lowder.",
857
+ # "You might use this when people can't hear you.",
858
+ # "",
859
+ # "Example:",
860
+ # [" toys say --shout hello"]
861
+ # end
862
+ #
863
+ # @param key [String,Symbol] The key to use to retrieve the value from
864
+ # the execution context.
865
+ # @param flags [String...] The flags in OptionParser format.
866
+ # @param accept [Object] An acceptor that validates and/or converts the
867
+ # value. You may provide either the name of an acceptor you have
868
+ # defined, one of the default acceptors provided by OptionParser, or
869
+ # any other specification recognized by {Toys::Acceptor.create}.
870
+ # Optional. If not specified, accepts any value as a string.
871
+ # @param default [Object] The default value. This is the value that will
872
+ # be set in the context if this flag is not provided on the command
873
+ # line. Defaults to `nil`.
874
+ # @param handler [Proc,nil,:set,:push] An optional handler that
875
+ # customizes how a value is set or updated when the flag is parsed.
876
+ # A handler is a proc that takes up to three arguments: the given
877
+ # value, the previous value, and a hash containing all the data
878
+ # collected so far during argument parsing. The proc must return the
879
+ # new value for the flag.
880
+ # You may also specify a predefined named handler. The `:set` handler
881
+ # (the default) replaces the previous value (effectively
882
+ # `-> (val) { val }`). The `:push` handler expects the previous value
883
+ # to be an array and pushes the given value onto it; it should be
884
+ # combined with setting the default value to `[]` and is intended for
885
+ # "multi-valued" flags.
886
+ # @param complete_flags [Object] A specifier for shell tab completion
887
+ # for flag names associated with this flag. By default, a
888
+ # {Toys::Flag::DefaultCompletion} is used, which provides the flag's
889
+ # names as completion candidates. To customize completion, set this
890
+ # to the name of a previously defined completion, a hash of options
891
+ # to pass to the constructor for {Toys::Flag::DefaultCompletion}, or
892
+ # any other spec recognized by {Toys::Completion.create}.
893
+ # @param complete_values [Object] A specifier for shell tab completion
894
+ # for flag values associated with this flag. This is the empty
895
+ # completion by default. To customize completion, set this to the
896
+ # name of a previously defined completion, or any spec recognized by
897
+ # {Toys::Completion.create}.
898
+ # @param report_collisions [Boolean] Raise an exception if a flag is
899
+ # requested that is already in use or marked as unusable. Default is
900
+ # true.
901
+ # @param group [Toys::FlagGroup,String,Symbol,nil] Group for this flag.
902
+ # You may provide a group name, a FlagGroup object, or `nil` which
903
+ # denotes the default group.
904
+ # @param desc [String,Array<String>,Toys::WrappableString] Short
905
+ # description for the flag. See {Toys::DSL::Tool#desc} for a
906
+ # description of the allowed formats. Defaults to the empty string.
907
+ # @param long_desc [Array<String,Array<String>,Toys::WrappableString>]
908
+ # Long description for the flag. See {Toys::DSL::Tool#long_desc} for
909
+ # a description of the allowed formats. (But note that this param
910
+ # takes an Array of description lines, rather than a series of
911
+ # arguments.) Defaults to the empty array.
912
+ # @param display_name [String] A display name for this flag, used in help
913
+ # text and error messages.
914
+ # @param add_method [true,false,nil] Whether to add a method for this
915
+ # flag. If omitted or set to nil, uses the default behavior, which
916
+ # adds the method if the key is a symbol representing a legal method
917
+ # name that starts with a letter and does not override any public
918
+ # method in the Ruby Object class or collide with any method directly
919
+ # defined in the tool class.
920
+ # @param block [Proc] Configures the flag. See {Toys::DSL::Flag} for the
921
+ # directives that can be called in this block.
922
+ # @return [self]
923
+ #
924
+ def flag(key, *flags,
925
+ accept: nil, default: nil, handler: nil,
926
+ complete_flags: nil, complete_values: nil,
927
+ report_collisions: true, group: nil,
928
+ desc: nil, long_desc: nil, display_name: nil, add_method: nil,
929
+ &block)
930
+ # Source available in the toys-core gem
931
+ end
932
+
933
+ ##
934
+ # Add a required positional argument to the current tool. You must
935
+ # specify a key which the script may use to obtain the argument value
936
+ # from the context.
937
+ #
938
+ # If the given key is a symbol representing a valid method name, then a
939
+ # helper method is automatically added to retrieve the value. Otherwise,
940
+ # if the key is a string or does not represent a valid method name, the
941
+ # tool can retrieve the value by calling {Toys::Context#get}.
942
+ #
943
+ # Attributes of the arg may be passed in as arguments to this method, or
944
+ # set in a block passed to this method. If you provide a block, you can
945
+ # use directives in {Toys::DSL::PositionalArg} within the block.
946
+ #
947
+ # ### Example
948
+ #
949
+ # This tool "moves" something from a source to destination, and takes two
950
+ # required arguments:
951
+ #
952
+ # tool "mv" do
953
+ # required_arg :source
954
+ # required_arg :dest
955
+ # def run
956
+ # puts "moving from #{source} to #{dest}..."
957
+ # end
958
+ # end
959
+ #
960
+ # @param key [String,Symbol] The key to use to retrieve the value from
961
+ # the execution context.
962
+ # @param accept [Object] An acceptor that validates and/or converts the
963
+ # value. You may provide either the name of an acceptor you have
964
+ # defined, one of the default acceptors provided by OptionParser, or
965
+ # any other specification recognized by {Toys::Acceptor.create}.
966
+ # Optional. If not specified, accepts any value as a string.
967
+ # @param complete [Object] A specifier for shell tab completion for
968
+ # values of this arg. This is the empty completion by default. To
969
+ # customize completion, set this to the name of a previously defined
970
+ # completion, or any spec recognized by {Toys::Completion.create}.
971
+ # @param display_name [String] A name to use for display (in help text
972
+ # and error reports). Defaults to the key in upper case.
973
+ # @param desc [String,Array<String>,Toys::WrappableString] Short
974
+ # description for the flag. See {Toys::DSL::Tool#desc} for a
975
+ # description of the allowed formats. Defaults to the empty string.
976
+ # @param long_desc [Array<String,Array<String>,Toys::WrappableString>]
977
+ # Long description for the flag. See {Toys::DSL::Tool#long_desc} for
978
+ # a description of the allowed formats. (But note that this param
979
+ # takes an Array of description lines, rather than a series of
980
+ # arguments.) Defaults to the empty array.
981
+ # @param add_method [true,false,nil] Whether to add a method for this
982
+ # argument. If omitted or set to nil, uses the default behavior,
983
+ # which adds the method if the key is a symbol representing a legal
984
+ # method name that starts with a letter and does not override any
985
+ # public method in the Ruby Object class or collide with any method
986
+ # directly defined in the tool class.
987
+ # @param block [Proc] Configures the positional argument. See
988
+ # {Toys::DSL::PositionalArg} for the directives that can be called in
989
+ # this block.
990
+ # @return [self]
991
+ #
992
+ def required_arg(key,
993
+ accept: nil, complete: nil, display_name: nil,
994
+ desc: nil, long_desc: nil, add_method: nil,
995
+ &block)
996
+ # Source available in the toys-core gem
997
+ end
998
+ alias required required_arg
999
+
1000
+ ##
1001
+ # Add an optional positional argument to the current tool. You must
1002
+ # specify a key which the script may use to obtain the argument value
1003
+ # from the context. If an optional argument is not given on the command
1004
+ # line, the value is set to the given default.
1005
+ #
1006
+ # If the given key is a symbol representing a valid method name, then a
1007
+ # helper method is automatically added to retrieve the value. Otherwise,
1008
+ # if the key is a string or does not represent a valid method name, the
1009
+ # tool can retrieve the value by calling {Toys::Context#get}.
1010
+ #
1011
+ # Attributes of the arg may be passed in as arguments to this method, or
1012
+ # set in a block passed to this method. If you provide a block, you can
1013
+ # use directives in {Toys::DSL::PositionalArg} within the block.
1014
+ #
1015
+ # ### Example
1016
+ #
1017
+ # This tool creates a "link" to a given target. The link location is
1018
+ # optional; if it is not given, it is inferred from the target.
1019
+ #
1020
+ # tool "ln" do
1021
+ # required_arg :target
1022
+ # optional_arg :location
1023
+ # def run
1024
+ # loc = location || File.basename(target)
1025
+ # puts "linking to #{target} from #{loc}..."
1026
+ # end
1027
+ # end
1028
+ #
1029
+ # @param key [String,Symbol] The key to use to retrieve the value from
1030
+ # the execution context.
1031
+ # @param default [Object] The default value. This is the value that will
1032
+ # be set in the context if this argument is not provided on the
1033
+ # command line. Defaults to `nil`.
1034
+ # @param accept [Object] An acceptor that validates and/or converts the
1035
+ # value. You may provide either the name of an acceptor you have
1036
+ # defined, one of the default acceptors provided by OptionParser, or
1037
+ # any other specification recognized by {Toys::Acceptor.create}.
1038
+ # Optional. If not specified, accepts any value as a string.
1039
+ # @param complete [Object] A specifier for shell tab completion for
1040
+ # values of this arg. This is the empty completion by default. To
1041
+ # customize completion, set this to the name of a previously defined
1042
+ # completion, or any spec recognized by {Toys::Completion.create}.
1043
+ # @param display_name [String] A name to use for display (in help text
1044
+ # and error reports). Defaults to the key in upper case.
1045
+ # @param desc [String,Array<String>,Toys::WrappableString] Short
1046
+ # description for the flag. See {Toys::DSL::Tool#desc} for a
1047
+ # description of the allowed formats. Defaults to the empty string.
1048
+ # @param long_desc [Array<String,Array<String>,Toys::WrappableString>]
1049
+ # Long description for the flag. See {Toys::DSL::Tool#long_desc} for
1050
+ # a description of the allowed formats. (But note that this param
1051
+ # takes an Array of description lines, rather than a series of
1052
+ # arguments.) Defaults to the empty array.
1053
+ # @param add_method [true,false,nil] Whether to add a method for this
1054
+ # argument. If omitted or set to nil, uses the default behavior,
1055
+ # which adds the method if the key is a symbol representing a legal
1056
+ # method name that starts with a letter and does not override any
1057
+ # public method in the Ruby Object class or collide with any method
1058
+ # directly defined in the tool class.
1059
+ # @param block [Proc] Configures the positional argument. See
1060
+ # {Toys::DSL::PositionalArg} for the directives that can be called in
1061
+ # this block.
1062
+ # @return [self]
1063
+ #
1064
+ def optional_arg(key,
1065
+ default: nil, accept: nil, complete: nil, display_name: nil,
1066
+ desc: nil, long_desc: nil, add_method: nil,
1067
+ &block)
1068
+ # Source available in the toys-core gem
1069
+ end
1070
+ alias optional optional_arg
1071
+
1072
+ ##
1073
+ # Specify what should be done with unmatched positional arguments. You
1074
+ # must specify a key which the script may use to obtain the remaining
1075
+ # args from the context.
1076
+ #
1077
+ # If the given key is a symbol representing a valid method name, then a
1078
+ # helper method is automatically added to retrieve the value. Otherwise,
1079
+ # if the key is a string or does not represent a valid method name, the
1080
+ # tool can retrieve the value by calling {Toys::Context#get}.
1081
+ #
1082
+ # Attributes of the arg may be passed in as arguments to this method, or
1083
+ # set in a block passed to this method. If you provide a block, you can
1084
+ # use directives in {Toys::DSL::PositionalArg} within the block.
1085
+ #
1086
+ # ### Example
1087
+ #
1088
+ # This tool displays a "list" of the given directories. If no directories
1089
+ # ar given, lists the current directory.
1090
+ #
1091
+ # tool "ln" do
1092
+ # remaining_args :directories
1093
+ # def run
1094
+ # dirs = directories.empty? ? [Dir.pwd] : directories
1095
+ # dirs.each do |dir|
1096
+ # puts "Listing directory #{dir}..."
1097
+ # end
1098
+ # end
1099
+ # end
1100
+ #
1101
+ # @param key [String,Symbol] The key to use to retrieve the value from
1102
+ # the execution context.
1103
+ # @param default [Object] The default value. This is the value that will
1104
+ # be set in the context if no unmatched arguments are provided on the
1105
+ # command line. Defaults to the empty array `[]`.
1106
+ # @param accept [Object] An acceptor that validates and/or converts the
1107
+ # value. You may provide either the name of an acceptor you have
1108
+ # defined, one of the default acceptors provided by OptionParser, or
1109
+ # any other specification recognized by {Toys::Acceptor.create}.
1110
+ # Optional. If not specified, accepts any value as a string.
1111
+ # @param complete [Object] A specifier for shell tab completion for
1112
+ # values of this arg. This is the empty completion by default. To
1113
+ # customize completion, set this to the name of a previously defined
1114
+ # completion, or any spec recognized by {Toys::Completion.create}.
1115
+ # @param display_name [String] A name to use for display (in help text
1116
+ # and error reports). Defaults to the key in upper case.
1117
+ # @param desc [String,Array<String>,Toys::WrappableString] Short
1118
+ # description for the flag. See {Toys::DSL::Tool#desc} for a
1119
+ # description of the allowed formats. Defaults to the empty string.
1120
+ # @param long_desc [Array<String,Array<String>,Toys::WrappableString>]
1121
+ # Long description for the flag. See {Toys::DSL::Tool#long_desc} for
1122
+ # a description of the allowed formats. (But note that this param
1123
+ # takes an Array of description lines, rather than a series of
1124
+ # arguments.) Defaults to the empty array.
1125
+ # @param add_method [true,false,nil] Whether to add a method for these
1126
+ # arguments. If omitted or set to nil, uses the default behavior,
1127
+ # which adds the method if the key is a symbol representing a legal
1128
+ # method name that starts with a letter and does not override any
1129
+ # public method in the Ruby Object class or collide with any method
1130
+ # directly defined in the tool class.
1131
+ # @param block [Proc] Configures the positional argument. See
1132
+ # {Toys::DSL::PositionalArg} for the directives that can be called in
1133
+ # this block.
1134
+ # @return [self]
1135
+ #
1136
+ def remaining_args(key,
1137
+ default: [], accept: nil, complete: nil, display_name: nil,
1138
+ desc: nil, long_desc: nil, add_method: nil,
1139
+ &block)
1140
+ # Source available in the toys-core gem
1141
+ end
1142
+ alias remaining remaining_args
1143
+
1144
+ ##
1145
+ # Set option values statically and create helper methods.
1146
+ #
1147
+ # If any given key is a symbol representing a valid method name, then a
1148
+ # helper method is automatically added to retrieve the value. Otherwise,
1149
+ # if the key is a string or does not represent a valid method name, the
1150
+ # tool can retrieve the value by calling {Toys::Context#get}.
1151
+ #
1152
+ # ### Example
1153
+ #
1154
+ # tool "hello" do
1155
+ # static :greeting, "Hi there"
1156
+ # def run
1157
+ # puts "#{greeting}, world!"
1158
+ # end
1159
+ # end
1160
+ #
1161
+ # @overload static(key, value)
1162
+ # Set a single value by key.
1163
+ # @param key [String,Symbol] The key to use to retrieve the value from
1164
+ # the execution context.
1165
+ # @param value [Object] The value to set.
1166
+ # @return [self]
1167
+ #
1168
+ # @overload static(hash)
1169
+ # Set multiple keys and values
1170
+ # @param hash [Hash] The keys and values to set
1171
+ # @return [self]
1172
+ #
1173
+ def static(key, value = nil)
1174
+ # Source available in the toys-core gem
1175
+ end
1176
+
1177
+ ##
1178
+ # Set option values statically without creating helper methods.
1179
+ #
1180
+ # ### Example
1181
+ #
1182
+ # tool "hello" do
1183
+ # set :greeting, "Hi there"
1184
+ # def run
1185
+ # puts "#{get(:greeting)}, world!"
1186
+ # end
1187
+ # end
1188
+ #
1189
+ # @overload set(key, value)
1190
+ # Set a single value by key.
1191
+ # @param key [String,Symbol] The key to use to retrieve the value from
1192
+ # the execution context.
1193
+ # @param value [Object] The value to set.
1194
+ # @return [self]
1195
+ #
1196
+ # @overload set(hash)
1197
+ # Set multiple keys and values
1198
+ # @param hash [Hash] The keys and values to set
1199
+ # @return [self]
1200
+ #
1201
+ def set(key, value = nil)
1202
+ # Source available in the toys-core gem
1203
+ end
1204
+
1205
+ ##
1206
+ # Enforce that all flags must be provided before any positional args.
1207
+ # That is, as soon as the first positional arg appears in the command
1208
+ # line arguments, flag parsing is disabled as if `--` had appeared.
1209
+ #
1210
+ # Issuing this directive by itself turns on enforcement. You may turn it
1211
+ # off by passsing `false` as the parameter.
1212
+ #
1213
+ # @param state [Boolean]
1214
+ # @return [self]
1215
+ #
1216
+ def enforce_flags_before_args(state = true)
1217
+ # Source available in the toys-core gem
1218
+ end
1219
+
1220
+ ##
1221
+ # Require that flags must match exactly. That is, flags must appear in
1222
+ # their entirety on the command line. (If false, substrings of flags are
1223
+ # accepted as long as they are unambiguous.)
1224
+ #
1225
+ # Issuing this directive by itself turns on exact match. You may turn it
1226
+ # off by passsing `false` as the parameter.
1227
+ #
1228
+ # @param state [Boolean]
1229
+ # @return [self]
1230
+ #
1231
+ def require_exact_flag_match(state = true)
1232
+ # Source available in the toys-core gem
1233
+ end
1234
+
1235
+ ##
1236
+ # Disable argument parsing for this tool. Arguments will not be parsed
1237
+ # and the options will not be populated. Instead, tools can retrieve the
1238
+ # full unparsed argument list by calling {Toys::Context#args}.
1239
+ #
1240
+ # This directive is mutually exclusive with any of the directives that
1241
+ # declare arguments or flags.
1242
+ #
1243
+ # ### Example
1244
+ #
1245
+ # tool "mytool" do
1246
+ # disable_argument_parsing
1247
+ # def run
1248
+ # puts "Arguments passed: #{args}"
1249
+ # end
1250
+ # end
1251
+ #
1252
+ # @return [self]
1253
+ #
1254
+ def disable_argument_parsing
1255
+ # Source available in the toys-core gem
1256
+ end
1257
+
1258
+ ##
1259
+ # Mark one or more flags as disabled, preventing their use by any
1260
+ # subsequent flag definition. This can be used to prevent middleware from
1261
+ # defining a particular flag.
1262
+ #
1263
+ # ### Example
1264
+ #
1265
+ # This tool does not support the `-v` and `-q` short forms for the two
1266
+ # verbosity flags (although it still supports the long forms `--verbose`
1267
+ # and `--quiet`.)
1268
+ #
1269
+ # tool "mytool" do
1270
+ # disable_flag "-v", "-q"
1271
+ # def run
1272
+ # # ...
1273
+ # end
1274
+ # end
1275
+ #
1276
+ # @param flags [String...] The flags to disable
1277
+ # @return [self]
1278
+ #
1279
+ def disable_flag(*flags)
1280
+ # Source available in the toys-core gem
1281
+ end
1282
+
1283
+ ##
1284
+ # Set the shell completion strategy for this tool's arguments.
1285
+ # You can pass one of the following:
1286
+ #
1287
+ # * The string name of a completion defined in this tool or any of its
1288
+ # its ancestors.
1289
+ # * A hash of options to pass to the constructor of
1290
+ # {Toys::ToolDefinition::DefaultCompletion}.
1291
+ # * `nil` or `:default` to select the standard completion strategy
1292
+ # (which is {Toys::ToolDefinition::DefaultCompletion} with no extra
1293
+ # options).
1294
+ # * Any other specification recognized by {Toys::Completion.create}.
1295
+ #
1296
+ # ### Example
1297
+ #
1298
+ # The namespace "foo" supports completion only of subtool names. It does
1299
+ # not complete the standard flags (like --help).
1300
+ #
1301
+ # tool "foo" do
1302
+ # complete_tool_args complete_args: false, complete_flags: false,
1303
+ # complete_flag_values: false
1304
+ # tool "bar" do
1305
+ # def run
1306
+ # puts "in foo bar"
1307
+ # end
1308
+ # end
1309
+ # end
1310
+ #
1311
+ # @param spec [Object]
1312
+ # @param options [Hash]
1313
+ # @param block [Proc]
1314
+ # @return [self]
1315
+ #
1316
+ def complete_tool_args(spec = nil, **options, &block)
1317
+ # Source available in the toys-core gem
1318
+ end
1319
+
1320
+ ##
1321
+ # Specify how to run this tool.
1322
+ #
1323
+ # Typically the entrypoint for a tool is a method named `run`. However,
1324
+ # you can change this by passing a different method name, as a symbol, to
1325
+ # {#to_run}.
1326
+ #
1327
+ # You can also alternatively pass a block to {#to_run}. You might do this
1328
+ # if your method needs access to local variables in the lexical scope.
1329
+ # However, it is often more convenient to use {#static} to set those
1330
+ # values in the context.
1331
+ #
1332
+ # ### Examples
1333
+ #
1334
+ # # Set a different method name as the entrypoint:
1335
+ #
1336
+ # tool "foo" do
1337
+ # to_run :foo
1338
+ # def foo
1339
+ # puts "The foo tool ran!"
1340
+ # end
1341
+ # end
1342
+ #
1343
+ # # Use a block to retain access to the enclosing lexical scope from
1344
+ # # the run method:
1345
+ #
1346
+ # tool "foo" do
1347
+ # cur_time = Time.now
1348
+ # to_run do
1349
+ # puts "The time at tool definition was #{cur_time}"
1350
+ # end
1351
+ # end
1352
+ #
1353
+ # # But the following is approximately equivalent:
1354
+ #
1355
+ # tool "foo" do
1356
+ # static :cur_time, Time.now
1357
+ # def run
1358
+ # puts "The time at tool definition was #{cur_time}"
1359
+ # end
1360
+ # end
1361
+ #
1362
+ # @param handler [Proc,Symbol,nil] The run handler as a method name
1363
+ # symbol or a proc, or nil to explicitly set as non-runnable.
1364
+ # @param block [Proc] The run handler as a block.
1365
+ # @return [self]
1366
+ #
1367
+ def to_run(handler = nil, &block)
1368
+ # Source available in the toys-core gem
1369
+ end
1370
+ alias on_run to_run
1371
+
1372
+ ##
1373
+ # Specify how to handle interrupts.
1374
+ #
1375
+ # You can provide either a block to be called, a Proc to be called, or
1376
+ # the name of a method to be called. In each case, the block, Proc, or
1377
+ # method can optionally take one argument, the Interrupt exception that
1378
+ # was raised.
1379
+ #
1380
+ # Note: this is equivalent to `on_signal("SIGINT")`.
1381
+ #
1382
+ # ### Example
1383
+ #
1384
+ # tool "foo" do
1385
+ # def run
1386
+ # sleep 10
1387
+ # end
1388
+ # on_interrupt do
1389
+ # puts "I was interrupted."
1390
+ # end
1391
+ # end
1392
+ #
1393
+ # @param handler [Proc,Symbol,nil] The interrupt callback proc or method
1394
+ # name. Pass nil to disable interrupt handling.
1395
+ # @param block [Proc] The interrupt callback as a block.
1396
+ # @return [self]
1397
+ #
1398
+ def on_interrupt(handler = nil, &block)
1399
+ # Source available in the toys-core gem
1400
+ end
1401
+
1402
+ ##
1403
+ # Specify how to handle the given signal.
1404
+ #
1405
+ # You can provide either a block to be called, a Proc to be called, or
1406
+ # the name of a method to be called. In each case, the block, Proc, or
1407
+ # method can optionally take one argument, the SignalException that was
1408
+ # raised.
1409
+ #
1410
+ # ### Example
1411
+ #
1412
+ # tool "foo" do
1413
+ # def run
1414
+ # sleep 10
1415
+ # end
1416
+ # on_signal("QUIT") do |e|
1417
+ # puts "Signal caught: #{e.signm}."
1418
+ # end
1419
+ # end
1420
+ #
1421
+ # @param signal [Integer,String,Symbol] The signal name or number
1422
+ # @param handler [Proc,Symbol,nil] The signal callback proc or method
1423
+ # name. Pass nil to disable signal handling.
1424
+ # @param block [Proc] The signal callback as a block.
1425
+ # @return [self]
1426
+ #
1427
+ def on_signal(signal, handler = nil, &block)
1428
+ # Source available in the toys-core gem
1429
+ end
1430
+
1431
+ ##
1432
+ # Specify how to handle usage errors.
1433
+ #
1434
+ # You can provide either a block to be called, a Proc to be called, or
1435
+ # the name of a method to be called. In each case, the block, Proc, or
1436
+ # method can optionally take one argument, the array of usage errors
1437
+ # reported.
1438
+ #
1439
+ # ### Example
1440
+ #
1441
+ # This tool runs even if a usage error is encountered, by setting the
1442
+ # `run` method as the usage error handler.
1443
+ #
1444
+ # tool "foo" do
1445
+ # def run
1446
+ # puts "Errors: #{usage_errors.join("\n")}"
1447
+ # end
1448
+ # on_usage_error :run
1449
+ # end
1450
+ #
1451
+ # @param handler [Proc,Symbol,nil] The interrupt callback proc or method
1452
+ # name. Pass nil to disable interrupt handling.
1453
+ # @param block [Proc] The interrupt callback as a block.
1454
+ # @return [self]
1455
+ #
1456
+ def on_usage_error(handler = nil, &block)
1457
+ # Source available in the toys-core gem
1458
+ end
1459
+
1460
+ ##
1461
+ # Specify that the given module should be mixed into this tool, and its
1462
+ # methods made available when running the tool.
1463
+ #
1464
+ # You can provide either a module, the string name of a mixin that you
1465
+ # have defined in this tool or one of its ancestors, or the symbol name
1466
+ # of a well-known mixin.
1467
+ #
1468
+ # ### Example
1469
+ #
1470
+ # Include the well-known mixin `:terminal` and perform some terminal
1471
+ # magic.
1472
+ #
1473
+ # tool "spin" do
1474
+ # include :terminal
1475
+ # def run
1476
+ # # The spinner method is defined by the :terminal mixin.
1477
+ # spinner(leading_text: "Waiting...", final_text: "\n") do
1478
+ # sleep 5
1479
+ # end
1480
+ # end
1481
+ # end
1482
+ #
1483
+ # @param mixin [Module,Symbol,String] Module or module name.
1484
+ # @param args [Object...] Arguments to pass to the initializer
1485
+ # @param kwargs [keywords] Keyword arguments to pass to the initializer
1486
+ # @return [self]
1487
+ #
1488
+ def include(mixin, *args, **kwargs)
1489
+ # Source available in the toys-core gem
1490
+ end
1491
+
1492
+ ##
1493
+ # Determine if the given module/mixin has already been included.
1494
+ #
1495
+ # You can provide either a module, the string name of a mixin that you
1496
+ # have defined in this tool or one of its ancestors, or the symbol name
1497
+ # of a well-known mixin.
1498
+ #
1499
+ # @param mod [Module,Symbol,String] Module or module name.
1500
+ #
1501
+ # @return [Boolean] Whether the mixin is included
1502
+ # @return [nil] if the current tool is not active.
1503
+ #
1504
+ def include?(mod)
1505
+ # Source available in the toys-core gem
1506
+ end
1507
+
1508
+ ##
1509
+ # Return the current source info object.
1510
+ #
1511
+ # @return [Toys::SourceInfo] Source info.
1512
+ #
1513
+ def source_info
1514
+ # Source available in the toys-core gem
1515
+ end
1516
+
1517
+ ##
1518
+ # Find the given data path (file or directory).
1519
+ #
1520
+ # Data directories are a convenient place to put images, archives, keys,
1521
+ # or other such static data needed by your tools. Data files are located
1522
+ # in a directory called `.data` inside a Toys directory. This directive
1523
+ # locates a data file during tool definition.
1524
+ #
1525
+ # ### Example
1526
+ #
1527
+ # This tool reads its description from a text file in the `.data`
1528
+ # directory.
1529
+ #
1530
+ # tool "mytool" do
1531
+ # path = find_data("mytool-desc.txt", type: :file)
1532
+ # desc IO.read(path) if path
1533
+ # def run
1534
+ # # ...
1535
+ # end
1536
+ # end
1537
+ #
1538
+ # @param path [String] The path to find
1539
+ # @param type [nil,:file,:directory] Type of file system object to find.
1540
+ # Default is `nil`, indicating any type.
1541
+ #
1542
+ # @return [String] Absolute path of the data.
1543
+ # @return [nil] if the given data path is not found.
1544
+ #
1545
+ def find_data(path, type: nil)
1546
+ # Source available in the toys-core gem
1547
+ end
1548
+
1549
+ ##
1550
+ # Return the context directory for this tool. Generally, this defaults
1551
+ # to the directory containing the toys config directory structure being
1552
+ # read, but it may be changed by setting a different context directory
1553
+ # for the tool.
1554
+ #
1555
+ # @return [String] Context directory path
1556
+ # @return [nil] if there is no context.
1557
+ #
1558
+ def context_directory
1559
+ # Source available in the toys-core gem
1560
+ end
1561
+
1562
+ ##
1563
+ # Return the current tool config. This object can be queried to determine
1564
+ # such information as the name, but it should not be altered.
1565
+ #
1566
+ # @return [Toys::ToolDefinition]
1567
+ #
1568
+ def current_tool
1569
+ # Source available in the toys-core gem
1570
+ end
1571
+
1572
+ ##
1573
+ # Set a custom context directory for this tool.
1574
+ #
1575
+ # @param dir [String] Context directory
1576
+ # @return [self]
1577
+ #
1578
+ def set_context_directory(dir)
1579
+ # Source available in the toys-core gem
1580
+ end
1581
+
1582
+ ##
1583
+ # Applies the given block to all subtools, recursively. Effectively, the
1584
+ # given block is run at the *end* of every tool block. This can be used,
1585
+ # for example, to provide some shared configuration for all tools.
1586
+ #
1587
+ # The block is applied only to subtools defined *after* the block
1588
+ # appears. Subtools defined before the block appears are not affected.
1589
+ #
1590
+ # ### Example
1591
+ #
1592
+ # It is common for tools to use the `:exec` mixin to invoke external
1593
+ # programs. This example automatically includes the exec mixin in all
1594
+ # subtools, recursively, so you do not have to repeat the `include`
1595
+ # directive in every tool.
1596
+ #
1597
+ # # .toys.rb
1598
+ #
1599
+ # subtool_apply do
1600
+ # # Include the mixin only if the tool hasn't already done so
1601
+ # unless include?(:exec)
1602
+ # include :exec, exit_on_nonzero_status: true
1603
+ # end
1604
+ # end
1605
+ #
1606
+ # tool "foo" do
1607
+ # def run
1608
+ # # This tool has access to methods defined by the :exec mixin
1609
+ # # because the above block is applied to the tool.
1610
+ # sh "echo hello"
1611
+ # end
1612
+ # end
1613
+ #
1614
+ def subtool_apply(&block)
1615
+ # Source available in the toys-core gem
1616
+ end
1617
+
1618
+ ##
1619
+ # Remove lower-priority sources from the load path. This prevents lower-
1620
+ # priority sources (such as Toys files from parent or global directories)
1621
+ # from executing or defining tools.
1622
+ #
1623
+ # This works only if no such sources have already loaded yet.
1624
+ #
1625
+ # @raise [Toys::ToolDefinitionError] if any lower-priority tools have
1626
+ # already been loaded.
1627
+ #
1628
+ def truncate_load_path!
1629
+ # Source available in the toys-core gem
1630
+ end
1631
+
1632
+ ##
1633
+ # Get the settings for this tool.
1634
+ #
1635
+ # @return [Toys::ToolDefinition::Settings] Tool-specific settings.
1636
+ #
1637
+ def settings
1638
+ # Source available in the toys-core gem
1639
+ end
1640
+
1641
+ ##
1642
+ # Determines whether the current Toys version satisfies the given
1643
+ # requirements.
1644
+ #
1645
+ # @return [Boolean] whether or not the requirements are satisfied
1646
+ #
1647
+ def toys_version?(*requirements)
1648
+ # Source available in the toys-core gem
1649
+ end
1650
+
1651
+ ##
1652
+ # Asserts that the current Toys version against the given requirements,
1653
+ # raising an exception if not.
1654
+ #
1655
+ # @return [self]
1656
+ #
1657
+ # @raise [Toys::ToolDefinitionError] if the current Toys version does not
1658
+ # satisfy the requirements.
1659
+ #
1660
+ def toys_version!(*requirements)
1661
+ # Source available in the toys-core gem
1662
+ end
1663
+ end
1664
+ end
1665
+ end