toys 0.12.2 → 0.13.0

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