toys 0.17.1 → 0.17.2

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 +4 -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 +1663 -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,1663 @@
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 version [String,Array<String>] Version requirements for the gem.
415
+ # @param path [String] Optional path within the gem to the file or
416
+ # directory to load. Defaults to the root of the gem's toys directory.
417
+ # @param toys_dir [String] Optional override for the gem's toys
418
+ # directory name. If not specified, the default specified by the gem
419
+ # will be used.
420
+ # @param as [String] Load into the given tool/namespace. If omitted,
421
+ # configuration will be loaded into the current namespace.
422
+ #
423
+ def load_gem(name, version: nil, path: nil, toys_dir: nil, as: nil)
424
+ # Source available in the toys-core gem
425
+ end
426
+
427
+ ##
428
+ # Expand the given template in the current location.
429
+ #
430
+ # The template may be specified as a class or a well-known template name.
431
+ # You may also provide arguments to pass to the template.
432
+ #
433
+ # ### Example
434
+ #
435
+ # The following example creates and uses a simple template.
436
+ #
437
+ # template "hello-generator" do
438
+ # def initialize(name, message)
439
+ # @name = name
440
+ # @message = message
441
+ # end
442
+ # attr_reader :name, :message
443
+ # expansion do |template|
444
+ # tool template.name do
445
+ # to_run do
446
+ # puts template.message
447
+ # end
448
+ # end
449
+ # end
450
+ # end
451
+ #
452
+ # expand "hello-generator", "mytool", "mytool is running!"
453
+ #
454
+ # @param template_class [Class,String,Symbol] The template, either as a
455
+ # class or a well-known name.
456
+ # @param args [Object...] Template arguments
457
+ # @return [self]
458
+ #
459
+ def expand(template_class, *args, **kwargs)
460
+ # Source available in the toys-core gem
461
+ end
462
+
463
+ ##
464
+ # Set the short description for the current tool. The short description
465
+ # is displayed with the tool in a subtool list. You may also use the
466
+ # equivalent method `short_desc`.
467
+ #
468
+ # The description is a {Toys::WrappableString}, which may be word-wrapped
469
+ # when displayed in a help screen. You may pass a {Toys::WrappableString}
470
+ # directly to this method, or you may pass any input that can be used to
471
+ # construct a wrappable string:
472
+ #
473
+ # * If you pass a String, its whitespace will be compacted (i.e. tabs,
474
+ # newlines, and multiple consecutive whitespace will be turned into a
475
+ # single space), and it will be word-wrapped on whitespace.
476
+ # * If you pass an Array of Strings, each string will be considered a
477
+ # literal word that cannot be broken, and wrapping will be done
478
+ # across the strings in the array. In this case, whitespace is not
479
+ # compacted.
480
+ #
481
+ # ### Examples
482
+ #
483
+ # If you pass in a sentence as a simple string, it may be word wrapped
484
+ # when displayed:
485
+ #
486
+ # desc "This sentence may be wrapped."
487
+ #
488
+ # To specify a sentence that should never be word-wrapped, pass it as the
489
+ # sole element of a string array:
490
+ #
491
+ # desc ["This sentence will not be wrapped."]
492
+ #
493
+ # @param str [Toys::WrappableString,String,Array<String>]
494
+ # @return [self]
495
+ #
496
+ def desc(str)
497
+ # Source available in the toys-core gem
498
+ end
499
+ alias short_desc desc
500
+
501
+ ##
502
+ # Add to the long description for the current tool. The long description
503
+ # is displayed in the usage documentation for the tool itself. This
504
+ # directive may be given multiple times, and the results are cumulative.
505
+ #
506
+ # A long description is a series of descriptions, which are generally
507
+ # displayed in a series of lines/paragraphs. Each individual description
508
+ # uses the form described in the {#desc} documentation, and may be
509
+ # word-wrapped when displayed. To insert a blank line, include an empty
510
+ # string as one of the descriptions.
511
+ #
512
+ # ### Example
513
+ #
514
+ # long_desc "This initial paragraph might get word wrapped.",
515
+ # "This next paragraph is followed by a blank line.",
516
+ # "",
517
+ # ["This line will not be wrapped."],
518
+ # [" This indent is preserved."]
519
+ # long_desc "This line is appended to the description."
520
+ #
521
+ # @param strs [Toys::WrappableString,String,Array<String>...]
522
+ # @param file [String] Optional. Read the description from the given file
523
+ # provided relative to the current toys file. The file must be a
524
+ # plain text file whose suffix is `.txt`.
525
+ # @param data [String] Optional. Read the description from the given data
526
+ # file. The file must be a plain text file whose suffix is `.txt`.
527
+ # @return [self]
528
+ #
529
+ def long_desc(*strs, file: nil, data: nil)
530
+ # Source available in the toys-core gem
531
+ end
532
+
533
+ ##
534
+ # Create a flag group. If a block is given, flags defined in the block
535
+ # belong to the group. The flags in the group are listed together in
536
+ # help screens.
537
+ #
538
+ # ### Example
539
+ #
540
+ # The following example creates a flag group in which all flags are
541
+ # optional.
542
+ #
543
+ # tool "execute" do
544
+ # flag_group desc: "Debug Flags" do
545
+ # flag :debug, "-D", desc: "Enable debugger"
546
+ # flag :warnings, "-W[VAL]", desc: "Enable warnings"
547
+ # end
548
+ # # ...
549
+ # end
550
+ #
551
+ # @param type [Symbol] The type of group. Allowed values: `:required`,
552
+ # `:optional`, `:exactly_one`, `:at_most_one`, `:at_least_one`.
553
+ # Default is `:optional`.
554
+ # @param desc [String,Array<String>,Toys::WrappableString] Short
555
+ # description for the group. See {Toys::DSL::Tool#desc} for a
556
+ # description of allowed formats. Defaults to `"Flags"`.
557
+ # @param long_desc [Array<String,Array<String>,Toys::WrappableString>]
558
+ # Long description for the flag group. See
559
+ # {Toys::DSL::Tool#long_desc} for a description of allowed formats.
560
+ # Defaults to the empty array.
561
+ # @param name [String,Symbol,nil] The name of the group, or nil for no
562
+ # name.
563
+ # @param report_collisions [Boolean] If `true`, raise an exception if a
564
+ # the given name is already taken. If `false`, ignore. Default is
565
+ # `true`.
566
+ # @param prepend [Boolean] If `true`, prepend rather than append the
567
+ # group to the list. Default is `false`.
568
+ # @param block [Proc] Adds flags to the group. See {Toys::DSL::FlagGroup}
569
+ # for the directives that can be called in this block.
570
+ # @return [self]
571
+ #
572
+ def flag_group(type: :optional, desc: nil, long_desc: nil, name: nil,
573
+ report_collisions: true, prepend: false, &block)
574
+ # Source available in the toys-core gem
575
+ end
576
+
577
+ ##
578
+ # Create a flag group of type `:required`. If a block is given, flags
579
+ # defined in the block belong to the group. All flags in this group are
580
+ # required.
581
+ #
582
+ # ### Example
583
+ #
584
+ # The following example creates a group of required flags.
585
+ #
586
+ # tool "login" do
587
+ # all_required do
588
+ # flag :username, "--username=VAL", desc: "Set username (required)"
589
+ # flag :password, "--password=VAL", desc: "Set password (required)"
590
+ # end
591
+ # # ...
592
+ # end
593
+ #
594
+ # @param desc [String,Array<String>,Toys::WrappableString] Short
595
+ # description for the group. See {Toys::DSL::Tool#desc} for a
596
+ # description of allowed formats. Defaults to `"Flags"`.
597
+ # @param long_desc [Array<String,Array<String>,Toys::WrappableString>]
598
+ # Long description for the flag group. See
599
+ # {Toys::DSL::Tool#long_desc} for a description of allowed formats.
600
+ # Defaults to the empty array.
601
+ # @param name [String,Symbol,nil] The name of the group, or nil for no
602
+ # name.
603
+ # @param report_collisions [Boolean] If `true`, raise an exception if a
604
+ # the given name is already taken. If `false`, ignore. Default is
605
+ # `true`.
606
+ # @param prepend [Boolean] If `true`, prepend rather than append the
607
+ # group to the list. Default is `false`.
608
+ # @param block [Proc] Adds flags to the group. See {Toys::DSL::FlagGroup}
609
+ # for the directives that can be called in this block.
610
+ # @return [self]
611
+ #
612
+ def all_required(desc: nil, long_desc: nil, name: nil, report_collisions: true,
613
+ prepend: false, &block)
614
+ # Source available in the toys-core gem
615
+ end
616
+
617
+ ##
618
+ # Create a flag group of type `:at_most_one`. If a block is given, flags
619
+ # defined in the block belong to the group. At most one flag in this
620
+ # group must be provided on the command line.
621
+ #
622
+ # ### Example
623
+ #
624
+ # The following example creates a group of flags in which either one or
625
+ # none may be set, but not more than one.
626
+ #
627
+ # tool "provision-server" do
628
+ # at_most_one do
629
+ # flag :restore_from_backup, "--restore-from-backup=VAL"
630
+ # flag :restore_from_image, "--restore-from-image=VAL"
631
+ # flag :clone_existing, "--clone-existing=VAL"
632
+ # end
633
+ # # ...
634
+ # end
635
+ #
636
+ # @param desc [String,Array<String>,Toys::WrappableString] Short
637
+ # description for the group. See {Toys::DSL::Tool#desc} for a
638
+ # description of allowed formats. Defaults to `"Flags"`.
639
+ # @param long_desc [Array<String,Array<String>,Toys::WrappableString>]
640
+ # Long description for the flag group. See
641
+ # {Toys::DSL::Tool#long_desc} for a description of allowed formats.
642
+ # Defaults to the empty array.
643
+ # @param name [String,Symbol,nil] The name of the group, or nil for no
644
+ # name.
645
+ # @param report_collisions [Boolean] If `true`, raise an exception if a
646
+ # the given name is already taken. If `false`, ignore. Default is
647
+ # `true`.
648
+ # @param prepend [Boolean] If `true`, prepend rather than append the
649
+ # group to the list. Default is `false`.
650
+ # @param block [Proc] Adds flags to the group. See {Toys::DSL::FlagGroup}
651
+ # for the directives that can be called in this block.
652
+ # @return [self]
653
+ #
654
+ def at_most_one(desc: nil, long_desc: nil, name: nil, report_collisions: true,
655
+ prepend: false, &block)
656
+ # Source available in the toys-core gem
657
+ end
658
+ alias at_most_one_required at_most_one
659
+
660
+ ##
661
+ # Create a flag group of type `:at_least_one`. If a block is given, flags
662
+ # defined in the block belong to the group. At least one flag in this
663
+ # group must be provided on the command line.
664
+ #
665
+ # ### Example
666
+ #
667
+ # The following example creates a group of flags in which one or more
668
+ # may be set.
669
+ #
670
+ # tool "run-tests" do
671
+ # at_least_one do
672
+ # flag :unit, desc: "Run unit tests"
673
+ # flag :integration, desc: "Run integration tests"
674
+ # flag :performance, desc: "Run performance tests"
675
+ # end
676
+ # # ...
677
+ # end
678
+ #
679
+ # @param desc [String,Array<String>,Toys::WrappableString] Short
680
+ # description for the group. See {Toys::DSL::Tool#desc} for a
681
+ # description of allowed formats. Defaults to `"Flags"`.
682
+ # @param long_desc [Array<String,Array<String>,Toys::WrappableString>]
683
+ # Long description for the flag group. See
684
+ # {Toys::DSL::Tool#long_desc} for a description of allowed formats.
685
+ # Defaults to the empty array.
686
+ # @param name [String,Symbol,nil] The name of the group, or nil for no
687
+ # name.
688
+ # @param report_collisions [Boolean] If `true`, raise an exception if a
689
+ # the given name is already taken. If `false`, ignore. Default is
690
+ # `true`.
691
+ # @param prepend [Boolean] If `true`, prepend rather than append the
692
+ # group to the list. Default is `false`.
693
+ # @param block [Proc] Adds flags to the group. See {Toys::DSL::FlagGroup}
694
+ # for the directives that can be called in this block.
695
+ # @return [self]
696
+ #
697
+ def at_least_one(desc: nil, long_desc: nil, name: nil, report_collisions: true,
698
+ prepend: false, &block)
699
+ # Source available in the toys-core gem
700
+ end
701
+ alias at_least_one_required at_least_one
702
+
703
+ ##
704
+ # Create a flag group of type `:exactly_one`. If a block is given, flags
705
+ # defined in the block belong to the group. Exactly one flag in this
706
+ # group must be provided on the command line.
707
+ #
708
+ # ### Example
709
+ #
710
+ # The following example creates a group of flags in which exactly one
711
+ # must be set.
712
+ #
713
+ # tool "deploy" do
714
+ # exactly_one do
715
+ # flag :server, "--server=IP_ADDR", desc: "Deploy to server"
716
+ # flag :vm, "--vm=ID", desc: "Deploy to a VM"
717
+ # flag :container, "--container=ID", desc: "Deploy to a container"
718
+ # end
719
+ # # ...
720
+ # end
721
+ #
722
+ # @param desc [String,Array<String>,Toys::WrappableString] Short
723
+ # description for the group. See {Toys::DSL::Tool#desc} for a
724
+ # description of allowed formats. Defaults to `"Flags"`.
725
+ # @param long_desc [Array<String,Array<String>,Toys::WrappableString>]
726
+ # Long description for the flag group. See
727
+ # {Toys::DSL::Tool#long_desc} for a description of allowed formats.
728
+ # Defaults to the empty array.
729
+ # @param name [String,Symbol,nil] The name of the group, or nil for no
730
+ # name.
731
+ # @param report_collisions [Boolean] If `true`, raise an exception if a
732
+ # the given name is already taken. If `false`, ignore. Default is
733
+ # `true`.
734
+ # @param prepend [Boolean] If `true`, prepend rather than append the
735
+ # group to the list. Default is `false`.
736
+ # @param block [Proc] Adds flags to the group. See {Toys::DSL::FlagGroup}
737
+ # for the directives that can be called in this block.
738
+ # @return [self]
739
+ #
740
+ def exactly_one(desc: nil, long_desc: nil, name: nil, report_collisions: true,
741
+ prepend: false, &block)
742
+ # Source available in the toys-core gem
743
+ end
744
+ alias exactly_one_required exactly_one
745
+
746
+ ##
747
+ # Add a flag to the current tool. Each flag must specify a key which
748
+ # the script may use to obtain the flag value from the context.
749
+ # You may then provide the flags themselves in OptionParser form.
750
+ #
751
+ # If the given key is a symbol representing a valid method name, then a
752
+ # helper method is automatically added to retrieve the value. Otherwise,
753
+ # if the key is a string or does not represent a valid method name, the
754
+ # tool can retrieve the value by calling {Toys::Context#get}.
755
+ #
756
+ # Attributes of the flag may be passed in as arguments to this method, or
757
+ # set in a block passed to this method. If you provide a block, you can
758
+ # use directives in {Toys::DSL::Flag} within the block.
759
+ #
760
+ # ### Flag syntax
761
+ #
762
+ # The flags themselves should be provided in OptionParser form. Following
763
+ # are examples of valid syntax.
764
+ #
765
+ # * `-a` : A short boolean switch. When this appears as an argument,
766
+ # the value is set to `true`.
767
+ # * `--abc` : A long boolean switch. When this appears as an argument,
768
+ # the value is set to `true`.
769
+ # * `-aVAL` or `-a VAL` : A short flag that takes a required value.
770
+ # These two forms are treated identically. If this argument appears
771
+ # with a value attached (e.g. `-afoo`), the attached string (e.g.
772
+ # `"foo"`) is taken as the value. Otherwise, the following argument
773
+ # is taken as the value (e.g. for `-a foo`, the value is set to
774
+ # `"foo"`.) The following argument is treated as the value even if it
775
+ # looks like a flag (e.g. `-a -a` causes the string `"-a"` to be
776
+ # taken as the value.)
777
+ # * `-a[VAL]` : A short flag that takes an optional value. If this
778
+ # argument appears with a value attached (e.g. `-afoo`), the attached
779
+ # string (e.g. `"foo"`) is taken as the value. Otherwise, the value
780
+ # is set to `true`. The following argument is never interpreted as
781
+ # the value. (Compare with `-a [VAL]`.)
782
+ # * `-a [VAL]` : A short flag that takes an optional value. If this
783
+ # argument appears with a value attached (e.g. `-afoo`), the attached
784
+ # string (e.g. `"foo"`) is taken as the value. Otherwise, if the
785
+ # following argument does not look like a flag (i.e. it does not
786
+ # begin with a hyphen), it is taken as the value. (e.g. `-a foo`
787
+ # causes the string `"foo"` to be taken as the value.). If there is
788
+ # no following argument, or the following argument looks like a flag,
789
+ # the value is set to `true`. (Compare with `-a[VAL]`.)
790
+ # * `--abc=VAL` or `--abc VAL` : A long flag that takes a required
791
+ # value. These two forms are treated identically. If this argument
792
+ # appears with a value attached (e.g. `--abc=foo`), the attached
793
+ # string (e.g. `"foo"`) is taken as the value. Otherwise, the
794
+ # following argument is taken as the value (e.g. for `--abc foo`, the
795
+ # value is set to `"foo"`.) The following argument is treated as the
796
+ # value even if it looks like a flag (e.g. `--abc --def` causes the
797
+ # string `"--def"` to be taken as the value.)
798
+ # * `--abc[=VAL]` : A long flag that takes an optional value. If this
799
+ # argument appears with a value attached (e.g. `--abc=foo`), the
800
+ # attached string (e.g. `"foo"`) is taken as the value. Otherwise,
801
+ # the value is set to `true`. The following argument is never
802
+ # interpreted as the value. (Compare with `--abc [VAL]`.)
803
+ # * `--abc [VAL]` : A long flag that takes an optional value. If this
804
+ # argument appears with a value attached (e.g. `--abc=foo`), the
805
+ # attached string (e.g. `"foo"`) is taken as the value. Otherwise, if
806
+ # the following argument does not look like a flag (i.e. it does not
807
+ # begin with a hyphen), it is taken as the value. (e.g. `--abc foo`
808
+ # causes the string `"foo"` to be taken as the value.). If there is
809
+ # no following argument, or the following argument looks like a flag,
810
+ # the value is set to `true`. (Compare with `--abc=[VAL]`.)
811
+ # * `--[no-]abc` : A long boolean switch that can be turned either on
812
+ # or off. This effectively creates two flags, `--abc` which sets the
813
+ # value to `true`, and `--no-abc` which sets the falue to `false`.
814
+ #
815
+ # ### Default flag syntax
816
+ #
817
+ # If no flag syntax strings are provided, a default syntax will be
818
+ # inferred based on the key and other options.
819
+ #
820
+ # Specifically, if the key has one character, then that character will be
821
+ # chosen as a short flag. If the key has multiple characters, a long flag
822
+ # will be generated.
823
+ #
824
+ # Furthermore, if a custom completion, a non-boolean acceptor, or a
825
+ # non-boolean default value is provided in the options, then the flag
826
+ # will be considered to take a value. Otherwise, it will be considered to
827
+ # be a boolean switch.
828
+ #
829
+ # For example, the following pairs of flags are identical:
830
+ #
831
+ # flag :a
832
+ # flag :a, "-a"
833
+ #
834
+ # flag :abc_def
835
+ # flag :abc_def, "--abc-def"
836
+ #
837
+ # flag :number, accept: Integer
838
+ # flag :number, "--number=VAL", accept: Integer
839
+ #
840
+ # ### More examples
841
+ #
842
+ # A flag that sets its value to the number of times it appears on the
843
+ # command line:
844
+ #
845
+ # flag :verbose, "-v", "--verbose",
846
+ # default: 0, handler: ->(_val, count) { count + 1 }
847
+ #
848
+ # An example using block form:
849
+ #
850
+ # flag :shout do
851
+ # flags "-s", "--shout"
852
+ # default false
853
+ # desc "Say it louder"
854
+ # long_desc "This flag says it lowder.",
855
+ # "You might use this when people can't hear you.",
856
+ # "",
857
+ # "Example:",
858
+ # [" toys say --shout hello"]
859
+ # end
860
+ #
861
+ # @param key [String,Symbol] The key to use to retrieve the value from
862
+ # the execution context.
863
+ # @param flags [String...] The flags in OptionParser format.
864
+ # @param accept [Object] An acceptor that validates and/or converts the
865
+ # value. You may provide either the name of an acceptor you have
866
+ # defined, one of the default acceptors provided by OptionParser, or
867
+ # any other specification recognized by {Toys::Acceptor.create}.
868
+ # Optional. If not specified, accepts any value as a string.
869
+ # @param default [Object] The default value. This is the value that will
870
+ # be set in the context if this flag is not provided on the command
871
+ # line. Defaults to `nil`.
872
+ # @param handler [Proc,nil,:set,:push] An optional handler that
873
+ # customizes how a value is set or updated when the flag is parsed.
874
+ # A handler is a proc that takes up to three arguments: the given
875
+ # value, the previous value, and a hash containing all the data
876
+ # collected so far during argument parsing. The proc must return the
877
+ # new value for the flag.
878
+ # You may also specify a predefined named handler. The `:set` handler
879
+ # (the default) replaces the previous value (effectively
880
+ # `-> (val) { val }`). The `:push` handler expects the previous value
881
+ # to be an array and pushes the given value onto it; it should be
882
+ # combined with setting the default value to `[]` and is intended for
883
+ # "multi-valued" flags.
884
+ # @param complete_flags [Object] A specifier for shell tab completion
885
+ # for flag names associated with this flag. By default, a
886
+ # {Toys::Flag::DefaultCompletion} is used, which provides the flag's
887
+ # names as completion candidates. To customize completion, set this
888
+ # to the name of a previously defined completion, a hash of options
889
+ # to pass to the constructor for {Toys::Flag::DefaultCompletion}, or
890
+ # any other spec recognized by {Toys::Completion.create}.
891
+ # @param complete_values [Object] A specifier for shell tab completion
892
+ # for flag values associated with this flag. This is the empty
893
+ # completion by default. To customize completion, set this to the
894
+ # name of a previously defined completion, or any spec recognized by
895
+ # {Toys::Completion.create}.
896
+ # @param report_collisions [Boolean] Raise an exception if a flag is
897
+ # requested that is already in use or marked as unusable. Default is
898
+ # true.
899
+ # @param group [Toys::FlagGroup,String,Symbol,nil] Group for this flag.
900
+ # You may provide a group name, a FlagGroup object, or `nil` which
901
+ # denotes the default group.
902
+ # @param desc [String,Array<String>,Toys::WrappableString] Short
903
+ # description for the flag. See {Toys::DSL::Tool#desc} for a
904
+ # description of the allowed formats. Defaults to the empty string.
905
+ # @param long_desc [Array<String,Array<String>,Toys::WrappableString>]
906
+ # Long description for the flag. See {Toys::DSL::Tool#long_desc} for
907
+ # a description of the allowed formats. (But note that this param
908
+ # takes an Array of description lines, rather than a series of
909
+ # arguments.) Defaults to the empty array.
910
+ # @param display_name [String] A display name for this flag, used in help
911
+ # text and error messages.
912
+ # @param add_method [true,false,nil] Whether to add a method for this
913
+ # flag. If omitted or set to nil, uses the default behavior, which
914
+ # adds the method if the key is a symbol representing a legal method
915
+ # name that starts with a letter and does not override any public
916
+ # method in the Ruby Object class or collide with any method directly
917
+ # defined in the tool class.
918
+ # @param block [Proc] Configures the flag. See {Toys::DSL::Flag} for the
919
+ # directives that can be called in this block.
920
+ # @return [self]
921
+ #
922
+ def flag(key, *flags,
923
+ accept: nil, default: nil, handler: nil,
924
+ complete_flags: nil, complete_values: nil,
925
+ report_collisions: true, group: nil,
926
+ desc: nil, long_desc: nil, display_name: nil, add_method: nil,
927
+ &block)
928
+ # Source available in the toys-core gem
929
+ end
930
+
931
+ ##
932
+ # Add a required positional argument to the current tool. You must
933
+ # specify a key which the script may use to obtain the argument value
934
+ # from the context.
935
+ #
936
+ # If the given key is a symbol representing a valid method name, then a
937
+ # helper method is automatically added to retrieve the value. Otherwise,
938
+ # if the key is a string or does not represent a valid method name, the
939
+ # tool can retrieve the value by calling {Toys::Context#get}.
940
+ #
941
+ # Attributes of the arg may be passed in as arguments to this method, or
942
+ # set in a block passed to this method. If you provide a block, you can
943
+ # use directives in {Toys::DSL::PositionalArg} within the block.
944
+ #
945
+ # ### Example
946
+ #
947
+ # This tool "moves" something from a source to destination, and takes two
948
+ # required arguments:
949
+ #
950
+ # tool "mv" do
951
+ # required_arg :source
952
+ # required_arg :dest
953
+ # def run
954
+ # puts "moving from #{source} to #{dest}..."
955
+ # end
956
+ # end
957
+ #
958
+ # @param key [String,Symbol] The key to use to retrieve the value from
959
+ # the execution context.
960
+ # @param accept [Object] An acceptor that validates and/or converts the
961
+ # value. You may provide either the name of an acceptor you have
962
+ # defined, one of the default acceptors provided by OptionParser, or
963
+ # any other specification recognized by {Toys::Acceptor.create}.
964
+ # Optional. If not specified, accepts any value as a string.
965
+ # @param complete [Object] A specifier for shell tab completion for
966
+ # values of this arg. This is the empty completion by default. To
967
+ # customize completion, set this to the name of a previously defined
968
+ # completion, or any spec recognized by {Toys::Completion.create}.
969
+ # @param display_name [String] A name to use for display (in help text
970
+ # and error reports). Defaults to the key in upper case.
971
+ # @param desc [String,Array<String>,Toys::WrappableString] Short
972
+ # description for the flag. See {Toys::DSL::Tool#desc} for a
973
+ # description of the allowed formats. Defaults to the empty string.
974
+ # @param long_desc [Array<String,Array<String>,Toys::WrappableString>]
975
+ # Long description for the flag. See {Toys::DSL::Tool#long_desc} for
976
+ # a description of the allowed formats. (But note that this param
977
+ # takes an Array of description lines, rather than a series of
978
+ # arguments.) Defaults to the empty array.
979
+ # @param add_method [true,false,nil] Whether to add a method for this
980
+ # argument. If omitted or set to nil, uses the default behavior,
981
+ # which adds the method if the key is a symbol representing a legal
982
+ # method name that starts with a letter and does not override any
983
+ # public method in the Ruby Object class or collide with any method
984
+ # directly defined in the tool class.
985
+ # @param block [Proc] Configures the positional argument. See
986
+ # {Toys::DSL::PositionalArg} for the directives that can be called in
987
+ # this block.
988
+ # @return [self]
989
+ #
990
+ def required_arg(key,
991
+ accept: nil, complete: nil, display_name: nil,
992
+ desc: nil, long_desc: nil, add_method: nil,
993
+ &block)
994
+ # Source available in the toys-core gem
995
+ end
996
+ alias required required_arg
997
+
998
+ ##
999
+ # Add an optional positional argument to the current tool. You must
1000
+ # specify a key which the script may use to obtain the argument value
1001
+ # from the context. If an optional argument is not given on the command
1002
+ # line, the value is set to the given default.
1003
+ #
1004
+ # If the given key is a symbol representing a valid method name, then a
1005
+ # helper method is automatically added to retrieve the value. Otherwise,
1006
+ # if the key is a string or does not represent a valid method name, the
1007
+ # tool can retrieve the value by calling {Toys::Context#get}.
1008
+ #
1009
+ # Attributes of the arg may be passed in as arguments to this method, or
1010
+ # set in a block passed to this method. If you provide a block, you can
1011
+ # use directives in {Toys::DSL::PositionalArg} within the block.
1012
+ #
1013
+ # ### Example
1014
+ #
1015
+ # This tool creates a "link" to a given target. The link location is
1016
+ # optional; if it is not given, it is inferred from the target.
1017
+ #
1018
+ # tool "ln" do
1019
+ # required_arg :target
1020
+ # optional_arg :location
1021
+ # def run
1022
+ # loc = location || File.basename(target)
1023
+ # puts "linking to #{target} from #{loc}..."
1024
+ # end
1025
+ # end
1026
+ #
1027
+ # @param key [String,Symbol] The key to use to retrieve the value from
1028
+ # the execution context.
1029
+ # @param default [Object] The default value. This is the value that will
1030
+ # be set in the context if this argument is not provided on the
1031
+ # command line. Defaults to `nil`.
1032
+ # @param accept [Object] An acceptor that validates and/or converts the
1033
+ # value. You may provide either the name of an acceptor you have
1034
+ # defined, one of the default acceptors provided by OptionParser, or
1035
+ # any other specification recognized by {Toys::Acceptor.create}.
1036
+ # Optional. If not specified, accepts any value as a string.
1037
+ # @param complete [Object] A specifier for shell tab completion for
1038
+ # values of this arg. This is the empty completion by default. To
1039
+ # customize completion, set this to the name of a previously defined
1040
+ # completion, or any spec recognized by {Toys::Completion.create}.
1041
+ # @param display_name [String] A name to use for display (in help text
1042
+ # and error reports). Defaults to the key in upper case.
1043
+ # @param desc [String,Array<String>,Toys::WrappableString] Short
1044
+ # description for the flag. See {Toys::DSL::Tool#desc} for a
1045
+ # description of the allowed formats. Defaults to the empty string.
1046
+ # @param long_desc [Array<String,Array<String>,Toys::WrappableString>]
1047
+ # Long description for the flag. See {Toys::DSL::Tool#long_desc} for
1048
+ # a description of the allowed formats. (But note that this param
1049
+ # takes an Array of description lines, rather than a series of
1050
+ # arguments.) Defaults to the empty array.
1051
+ # @param add_method [true,false,nil] Whether to add a method for this
1052
+ # argument. If omitted or set to nil, uses the default behavior,
1053
+ # which adds the method if the key is a symbol representing a legal
1054
+ # method name that starts with a letter and does not override any
1055
+ # public method in the Ruby Object class or collide with any method
1056
+ # directly defined in the tool class.
1057
+ # @param block [Proc] Configures the positional argument. See
1058
+ # {Toys::DSL::PositionalArg} for the directives that can be called in
1059
+ # this block.
1060
+ # @return [self]
1061
+ #
1062
+ def optional_arg(key,
1063
+ default: nil, accept: nil, complete: nil, display_name: nil,
1064
+ desc: nil, long_desc: nil, add_method: nil,
1065
+ &block)
1066
+ # Source available in the toys-core gem
1067
+ end
1068
+ alias optional optional_arg
1069
+
1070
+ ##
1071
+ # Specify what should be done with unmatched positional arguments. You
1072
+ # must specify a key which the script may use to obtain the remaining
1073
+ # args from the context.
1074
+ #
1075
+ # If the given key is a symbol representing a valid method name, then a
1076
+ # helper method is automatically added to retrieve the value. Otherwise,
1077
+ # if the key is a string or does not represent a valid method name, the
1078
+ # tool can retrieve the value by calling {Toys::Context#get}.
1079
+ #
1080
+ # Attributes of the arg may be passed in as arguments to this method, or
1081
+ # set in a block passed to this method. If you provide a block, you can
1082
+ # use directives in {Toys::DSL::PositionalArg} within the block.
1083
+ #
1084
+ # ### Example
1085
+ #
1086
+ # This tool displays a "list" of the given directories. If no directories
1087
+ # ar given, lists the current directory.
1088
+ #
1089
+ # tool "ln" do
1090
+ # remaining_args :directories
1091
+ # def run
1092
+ # dirs = directories.empty? ? [Dir.pwd] : directories
1093
+ # dirs.each do |dir|
1094
+ # puts "Listing directory #{dir}..."
1095
+ # end
1096
+ # end
1097
+ # end
1098
+ #
1099
+ # @param key [String,Symbol] The key to use to retrieve the value from
1100
+ # the execution context.
1101
+ # @param default [Object] The default value. This is the value that will
1102
+ # be set in the context if no unmatched arguments are provided on the
1103
+ # command line. Defaults to the empty array `[]`.
1104
+ # @param accept [Object] An acceptor that validates and/or converts the
1105
+ # value. You may provide either the name of an acceptor you have
1106
+ # defined, one of the default acceptors provided by OptionParser, or
1107
+ # any other specification recognized by {Toys::Acceptor.create}.
1108
+ # Optional. If not specified, accepts any value as a string.
1109
+ # @param complete [Object] A specifier for shell tab completion for
1110
+ # values of this arg. This is the empty completion by default. To
1111
+ # customize completion, set this to the name of a previously defined
1112
+ # completion, or any spec recognized by {Toys::Completion.create}.
1113
+ # @param display_name [String] A name to use for display (in help text
1114
+ # and error reports). Defaults to the key in upper case.
1115
+ # @param desc [String,Array<String>,Toys::WrappableString] Short
1116
+ # description for the flag. See {Toys::DSL::Tool#desc} for a
1117
+ # description of the allowed formats. Defaults to the empty string.
1118
+ # @param long_desc [Array<String,Array<String>,Toys::WrappableString>]
1119
+ # Long description for the flag. See {Toys::DSL::Tool#long_desc} for
1120
+ # a description of the allowed formats. (But note that this param
1121
+ # takes an Array of description lines, rather than a series of
1122
+ # arguments.) Defaults to the empty array.
1123
+ # @param add_method [true,false,nil] Whether to add a method for these
1124
+ # arguments. If omitted or set to nil, uses the default behavior,
1125
+ # which adds the method if the key is a symbol representing a legal
1126
+ # method name that starts with a letter and does not override any
1127
+ # public method in the Ruby Object class or collide with any method
1128
+ # directly defined in the tool class.
1129
+ # @param block [Proc] Configures the positional argument. See
1130
+ # {Toys::DSL::PositionalArg} for the directives that can be called in
1131
+ # this block.
1132
+ # @return [self]
1133
+ #
1134
+ def remaining_args(key,
1135
+ default: [], accept: nil, complete: nil, display_name: nil,
1136
+ desc: nil, long_desc: nil, add_method: nil,
1137
+ &block)
1138
+ # Source available in the toys-core gem
1139
+ end
1140
+ alias remaining remaining_args
1141
+
1142
+ ##
1143
+ # Set option values statically and create helper methods.
1144
+ #
1145
+ # If any given key is a symbol representing a valid method name, then a
1146
+ # helper method is automatically added to retrieve the value. Otherwise,
1147
+ # if the key is a string or does not represent a valid method name, the
1148
+ # tool can retrieve the value by calling {Toys::Context#get}.
1149
+ #
1150
+ # ### Example
1151
+ #
1152
+ # tool "hello" do
1153
+ # static :greeting, "Hi there"
1154
+ # def run
1155
+ # puts "#{greeting}, world!"
1156
+ # end
1157
+ # end
1158
+ #
1159
+ # @overload static(key, value)
1160
+ # Set a single value by key.
1161
+ # @param key [String,Symbol] The key to use to retrieve the value from
1162
+ # the execution context.
1163
+ # @param value [Object] The value to set.
1164
+ # @return [self]
1165
+ #
1166
+ # @overload static(hash)
1167
+ # Set multiple keys and values
1168
+ # @param hash [Hash] The keys and values to set
1169
+ # @return [self]
1170
+ #
1171
+ def static(key, value = nil)
1172
+ # Source available in the toys-core gem
1173
+ end
1174
+
1175
+ ##
1176
+ # Set option values statically without creating helper methods.
1177
+ #
1178
+ # ### Example
1179
+ #
1180
+ # tool "hello" do
1181
+ # set :greeting, "Hi there"
1182
+ # def run
1183
+ # puts "#{get(:greeting)}, world!"
1184
+ # end
1185
+ # end
1186
+ #
1187
+ # @overload set(key, value)
1188
+ # Set a single value by key.
1189
+ # @param key [String,Symbol] The key to use to retrieve the value from
1190
+ # the execution context.
1191
+ # @param value [Object] The value to set.
1192
+ # @return [self]
1193
+ #
1194
+ # @overload set(hash)
1195
+ # Set multiple keys and values
1196
+ # @param hash [Hash] The keys and values to set
1197
+ # @return [self]
1198
+ #
1199
+ def set(key, value = nil)
1200
+ # Source available in the toys-core gem
1201
+ end
1202
+
1203
+ ##
1204
+ # Enforce that all flags must be provided before any positional args.
1205
+ # That is, as soon as the first positional arg appears in the command
1206
+ # line arguments, flag parsing is disabled as if `--` had appeared.
1207
+ #
1208
+ # Issuing this directive by itself turns on enforcement. You may turn it
1209
+ # off by passsing `false` as the parameter.
1210
+ #
1211
+ # @param state [Boolean]
1212
+ # @return [self]
1213
+ #
1214
+ def enforce_flags_before_args(state = true)
1215
+ # Source available in the toys-core gem
1216
+ end
1217
+
1218
+ ##
1219
+ # Require that flags must match exactly. That is, flags must appear in
1220
+ # their entirety on the command line. (If false, substrings of flags are
1221
+ # accepted as long as they are unambiguous.)
1222
+ #
1223
+ # Issuing this directive by itself turns on exact match. You may turn it
1224
+ # off by passsing `false` as the parameter.
1225
+ #
1226
+ # @param state [Boolean]
1227
+ # @return [self]
1228
+ #
1229
+ def require_exact_flag_match(state = true)
1230
+ # Source available in the toys-core gem
1231
+ end
1232
+
1233
+ ##
1234
+ # Disable argument parsing for this tool. Arguments will not be parsed
1235
+ # and the options will not be populated. Instead, tools can retrieve the
1236
+ # full unparsed argument list by calling {Toys::Context#args}.
1237
+ #
1238
+ # This directive is mutually exclusive with any of the directives that
1239
+ # declare arguments or flags.
1240
+ #
1241
+ # ### Example
1242
+ #
1243
+ # tool "mytool" do
1244
+ # disable_argument_parsing
1245
+ # def run
1246
+ # puts "Arguments passed: #{args}"
1247
+ # end
1248
+ # end
1249
+ #
1250
+ # @return [self]
1251
+ #
1252
+ def disable_argument_parsing
1253
+ # Source available in the toys-core gem
1254
+ end
1255
+
1256
+ ##
1257
+ # Mark one or more flags as disabled, preventing their use by any
1258
+ # subsequent flag definition. This can be used to prevent middleware from
1259
+ # defining a particular flag.
1260
+ #
1261
+ # ### Example
1262
+ #
1263
+ # This tool does not support the `-v` and `-q` short forms for the two
1264
+ # verbosity flags (although it still supports the long forms `--verbose`
1265
+ # and `--quiet`.)
1266
+ #
1267
+ # tool "mytool" do
1268
+ # disable_flag "-v", "-q"
1269
+ # def run
1270
+ # # ...
1271
+ # end
1272
+ # end
1273
+ #
1274
+ # @param flags [String...] The flags to disable
1275
+ # @return [self]
1276
+ #
1277
+ def disable_flag(*flags)
1278
+ # Source available in the toys-core gem
1279
+ end
1280
+
1281
+ ##
1282
+ # Set the shell completion strategy for this tool's arguments.
1283
+ # You can pass one of the following:
1284
+ #
1285
+ # * The string name of a completion defined in this tool or any of its
1286
+ # its ancestors.
1287
+ # * A hash of options to pass to the constructor of
1288
+ # {Toys::ToolDefinition::DefaultCompletion}.
1289
+ # * `nil` or `:default` to select the standard completion strategy
1290
+ # (which is {Toys::ToolDefinition::DefaultCompletion} with no extra
1291
+ # options).
1292
+ # * Any other specification recognized by {Toys::Completion.create}.
1293
+ #
1294
+ # ### Example
1295
+ #
1296
+ # The namespace "foo" supports completion only of subtool names. It does
1297
+ # not complete the standard flags (like --help).
1298
+ #
1299
+ # tool "foo" do
1300
+ # complete_tool_args complete_args: false, complete_flags: false,
1301
+ # complete_flag_values: false
1302
+ # tool "bar" do
1303
+ # def run
1304
+ # puts "in foo bar"
1305
+ # end
1306
+ # end
1307
+ # end
1308
+ #
1309
+ # @param spec [Object]
1310
+ # @param options [Hash]
1311
+ # @param block [Proc]
1312
+ # @return [self]
1313
+ #
1314
+ def complete_tool_args(spec = nil, **options, &block)
1315
+ # Source available in the toys-core gem
1316
+ end
1317
+
1318
+ ##
1319
+ # Specify how to run this tool.
1320
+ #
1321
+ # Typically the entrypoint for a tool is a method named `run`. However,
1322
+ # you can change this by passing a different method name, as a symbol, to
1323
+ # {#to_run}.
1324
+ #
1325
+ # You can also alternatively pass a block to {#to_run}. You might do this
1326
+ # if your method needs access to local variables in the lexical scope.
1327
+ # However, it is often more convenient to use {#static} to set those
1328
+ # values in the context.
1329
+ #
1330
+ # ### Examples
1331
+ #
1332
+ # # Set a different method name as the entrypoint:
1333
+ #
1334
+ # tool "foo" do
1335
+ # to_run :foo
1336
+ # def foo
1337
+ # puts "The foo tool ran!"
1338
+ # end
1339
+ # end
1340
+ #
1341
+ # # Use a block to retain access to the enclosing lexical scope from
1342
+ # # the run method:
1343
+ #
1344
+ # tool "foo" do
1345
+ # cur_time = Time.now
1346
+ # to_run do
1347
+ # puts "The time at tool definition was #{cur_time}"
1348
+ # end
1349
+ # end
1350
+ #
1351
+ # # But the following is approximately equivalent:
1352
+ #
1353
+ # tool "foo" do
1354
+ # static :cur_time, Time.now
1355
+ # def run
1356
+ # puts "The time at tool definition was #{cur_time}"
1357
+ # end
1358
+ # end
1359
+ #
1360
+ # @param handler [Proc,Symbol,nil] The run handler as a method name
1361
+ # symbol or a proc, or nil to explicitly set as non-runnable.
1362
+ # @param block [Proc] The run handler as a block.
1363
+ # @return [self]
1364
+ #
1365
+ def to_run(handler = nil, &block)
1366
+ # Source available in the toys-core gem
1367
+ end
1368
+ alias on_run to_run
1369
+
1370
+ ##
1371
+ # Specify how to handle interrupts.
1372
+ #
1373
+ # You can provide either a block to be called, a Proc to be called, or
1374
+ # the name of a method to be called. In each case, the block, Proc, or
1375
+ # method can optionally take one argument, the Interrupt exception that
1376
+ # was raised.
1377
+ #
1378
+ # Note: this is equivalent to `on_signal("SIGINT")`.
1379
+ #
1380
+ # ### Example
1381
+ #
1382
+ # tool "foo" do
1383
+ # def run
1384
+ # sleep 10
1385
+ # end
1386
+ # on_interrupt do
1387
+ # puts "I was interrupted."
1388
+ # end
1389
+ # end
1390
+ #
1391
+ # @param handler [Proc,Symbol,nil] The interrupt callback proc or method
1392
+ # name. Pass nil to disable interrupt handling.
1393
+ # @param block [Proc] The interrupt callback as a block.
1394
+ # @return [self]
1395
+ #
1396
+ def on_interrupt(handler = nil, &block)
1397
+ # Source available in the toys-core gem
1398
+ end
1399
+
1400
+ ##
1401
+ # Specify how to handle the given signal.
1402
+ #
1403
+ # You can provide either a block to be called, a Proc to be called, or
1404
+ # the name of a method to be called. In each case, the block, Proc, or
1405
+ # method can optionally take one argument, the SignalException that was
1406
+ # raised.
1407
+ #
1408
+ # ### Example
1409
+ #
1410
+ # tool "foo" do
1411
+ # def run
1412
+ # sleep 10
1413
+ # end
1414
+ # on_signal("QUIT") do |e|
1415
+ # puts "Signal caught: #{e.signm}."
1416
+ # end
1417
+ # end
1418
+ #
1419
+ # @param signal [Integer,String,Symbol] The signal name or number
1420
+ # @param handler [Proc,Symbol,nil] The signal callback proc or method
1421
+ # name. Pass nil to disable signal handling.
1422
+ # @param block [Proc] The signal callback as a block.
1423
+ # @return [self]
1424
+ #
1425
+ def on_signal(signal, handler = nil, &block)
1426
+ # Source available in the toys-core gem
1427
+ end
1428
+
1429
+ ##
1430
+ # Specify how to handle usage errors.
1431
+ #
1432
+ # You can provide either a block to be called, a Proc to be called, or
1433
+ # the name of a method to be called. In each case, the block, Proc, or
1434
+ # method can optionally take one argument, the array of usage errors
1435
+ # reported.
1436
+ #
1437
+ # ### Example
1438
+ #
1439
+ # This tool runs even if a usage error is encountered, by setting the
1440
+ # `run` method as the usage error handler.
1441
+ #
1442
+ # tool "foo" do
1443
+ # def run
1444
+ # puts "Errors: #{usage_errors.join("\n")}"
1445
+ # end
1446
+ # on_usage_error :run
1447
+ # end
1448
+ #
1449
+ # @param handler [Proc,Symbol,nil] The interrupt callback proc or method
1450
+ # name. Pass nil to disable interrupt handling.
1451
+ # @param block [Proc] The interrupt callback as a block.
1452
+ # @return [self]
1453
+ #
1454
+ def on_usage_error(handler = nil, &block)
1455
+ # Source available in the toys-core gem
1456
+ end
1457
+
1458
+ ##
1459
+ # Specify that the given module should be mixed into this tool, and its
1460
+ # methods made available when running the tool.
1461
+ #
1462
+ # You can provide either a module, the string name of a mixin that you
1463
+ # have defined in this tool or one of its ancestors, or the symbol name
1464
+ # of a well-known mixin.
1465
+ #
1466
+ # ### Example
1467
+ #
1468
+ # Include the well-known mixin `:terminal` and perform some terminal
1469
+ # magic.
1470
+ #
1471
+ # tool "spin" do
1472
+ # include :terminal
1473
+ # def run
1474
+ # # The spinner method is defined by the :terminal mixin.
1475
+ # spinner(leading_text: "Waiting...", final_text: "\n") do
1476
+ # sleep 5
1477
+ # end
1478
+ # end
1479
+ # end
1480
+ #
1481
+ # @param mixin [Module,Symbol,String] Module or module name.
1482
+ # @param args [Object...] Arguments to pass to the initializer
1483
+ # @param kwargs [keywords] Keyword arguments to pass to the initializer
1484
+ # @return [self]
1485
+ #
1486
+ def include(mixin, *args, **kwargs)
1487
+ # Source available in the toys-core gem
1488
+ end
1489
+
1490
+ ##
1491
+ # Determine if the given module/mixin has already been included.
1492
+ #
1493
+ # You can provide either a module, the string name of a mixin that you
1494
+ # have defined in this tool or one of its ancestors, or the symbol name
1495
+ # of a well-known mixin.
1496
+ #
1497
+ # @param mod [Module,Symbol,String] Module or module name.
1498
+ #
1499
+ # @return [Boolean] Whether the mixin is included
1500
+ # @return [nil] if the current tool is not active.
1501
+ #
1502
+ def include?(mod)
1503
+ # Source available in the toys-core gem
1504
+ end
1505
+
1506
+ ##
1507
+ # Return the current source info object.
1508
+ #
1509
+ # @return [Toys::SourceInfo] Source info.
1510
+ #
1511
+ def source_info
1512
+ # Source available in the toys-core gem
1513
+ end
1514
+
1515
+ ##
1516
+ # Find the given data path (file or directory).
1517
+ #
1518
+ # Data directories are a convenient place to put images, archives, keys,
1519
+ # or other such static data needed by your tools. Data files are located
1520
+ # in a directory called `.data` inside a Toys directory. This directive
1521
+ # locates a data file during tool definition.
1522
+ #
1523
+ # ### Example
1524
+ #
1525
+ # This tool reads its description from a text file in the `.data`
1526
+ # directory.
1527
+ #
1528
+ # tool "mytool" do
1529
+ # path = find_data("mytool-desc.txt", type: :file)
1530
+ # desc IO.read(path) if path
1531
+ # def run
1532
+ # # ...
1533
+ # end
1534
+ # end
1535
+ #
1536
+ # @param path [String] The path to find
1537
+ # @param type [nil,:file,:directory] Type of file system object to find.
1538
+ # Default is `nil`, indicating any type.
1539
+ #
1540
+ # @return [String] Absolute path of the data.
1541
+ # @return [nil] if the given data path is not found.
1542
+ #
1543
+ def find_data(path, type: nil)
1544
+ # Source available in the toys-core gem
1545
+ end
1546
+
1547
+ ##
1548
+ # Return the context directory for this tool. Generally, this defaults
1549
+ # to the directory containing the toys config directory structure being
1550
+ # read, but it may be changed by setting a different context directory
1551
+ # for the tool.
1552
+ #
1553
+ # @return [String] Context directory path
1554
+ # @return [nil] if there is no context.
1555
+ #
1556
+ def context_directory
1557
+ # Source available in the toys-core gem
1558
+ end
1559
+
1560
+ ##
1561
+ # Return the current tool config. This object can be queried to determine
1562
+ # such information as the name, but it should not be altered.
1563
+ #
1564
+ # @return [Toys::ToolDefinition]
1565
+ #
1566
+ def current_tool
1567
+ # Source available in the toys-core gem
1568
+ end
1569
+
1570
+ ##
1571
+ # Set a custom context directory for this tool.
1572
+ #
1573
+ # @param dir [String] Context directory
1574
+ # @return [self]
1575
+ #
1576
+ def set_context_directory(dir)
1577
+ # Source available in the toys-core gem
1578
+ end
1579
+
1580
+ ##
1581
+ # Applies the given block to all subtools, recursively. Effectively, the
1582
+ # given block is run at the *end* of every tool block. This can be used,
1583
+ # for example, to provide some shared configuration for all tools.
1584
+ #
1585
+ # The block is applied only to subtools defined *after* the block
1586
+ # appears. Subtools defined before the block appears are not affected.
1587
+ #
1588
+ # ### Example
1589
+ #
1590
+ # It is common for tools to use the `:exec` mixin to invoke external
1591
+ # programs. This example automatically includes the exec mixin in all
1592
+ # subtools, recursively, so you do not have to repeat the `include`
1593
+ # directive in every tool.
1594
+ #
1595
+ # # .toys.rb
1596
+ #
1597
+ # subtool_apply do
1598
+ # # Include the mixin only if the tool hasn't already done so
1599
+ # unless include?(:exec)
1600
+ # include :exec, exit_on_nonzero_status: true
1601
+ # end
1602
+ # end
1603
+ #
1604
+ # tool "foo" do
1605
+ # def run
1606
+ # # This tool has access to methods defined by the :exec mixin
1607
+ # # because the above block is applied to the tool.
1608
+ # sh "echo hello"
1609
+ # end
1610
+ # end
1611
+ #
1612
+ def subtool_apply(&block)
1613
+ # Source available in the toys-core gem
1614
+ end
1615
+
1616
+ ##
1617
+ # Remove lower-priority sources from the load path. This prevents lower-
1618
+ # priority sources (such as Toys files from parent or global directories)
1619
+ # from executing or defining tools.
1620
+ #
1621
+ # This works only if no such sources have already loaded yet.
1622
+ #
1623
+ # @raise [Toys::ToolDefinitionError] if any lower-priority tools have
1624
+ # already been loaded.
1625
+ #
1626
+ def truncate_load_path!
1627
+ # Source available in the toys-core gem
1628
+ end
1629
+
1630
+ ##
1631
+ # Get the settings for this tool.
1632
+ #
1633
+ # @return [Toys::ToolDefinition::Settings] Tool-specific settings.
1634
+ #
1635
+ def settings
1636
+ # Source available in the toys-core gem
1637
+ end
1638
+
1639
+ ##
1640
+ # Determines whether the current Toys version satisfies the given
1641
+ # requirements.
1642
+ #
1643
+ # @return [Boolean] whether or not the requirements are satisfied
1644
+ #
1645
+ def toys_version?(*requirements)
1646
+ # Source available in the toys-core gem
1647
+ end
1648
+
1649
+ ##
1650
+ # Asserts that the current Toys version against the given requirements,
1651
+ # raising an exception if not.
1652
+ #
1653
+ # @return [self]
1654
+ #
1655
+ # @raise [Toys::ToolDefinitionError] if the current Toys version does not
1656
+ # satisfy the requirements.
1657
+ #
1658
+ def toys_version!(*requirements)
1659
+ # Source available in the toys-core gem
1660
+ end
1661
+ end
1662
+ end
1663
+ end