toys 0.15.6 → 0.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +6 -1
  3. data/README.md +2 -2
  4. data/builtins/system/tools.rb +1 -1
  5. data/lib/toys/templates/clean.rb +1 -1
  6. data/lib/toys/templates/gem_build.rb +1 -1
  7. data/lib/toys/templates/rubocop.rb +4 -1
  8. data/lib/toys/version.rb +1 -1
  9. metadata +8 -63
  10. data/core-docs/toys/acceptor.rb +0 -474
  11. data/core-docs/toys/arg_parser.rb +0 -397
  12. data/core-docs/toys/cli.rb +0 -466
  13. data/core-docs/toys/compat.rb +0 -2
  14. data/core-docs/toys/completion.rb +0 -340
  15. data/core-docs/toys/context.rb +0 -386
  16. data/core-docs/toys/core.rb +0 -14
  17. data/core-docs/toys/dsl/base.rb +0 -56
  18. data/core-docs/toys/dsl/flag.rb +0 -284
  19. data/core-docs/toys/dsl/flag_group.rb +0 -267
  20. data/core-docs/toys/dsl/internal.rb +0 -4
  21. data/core-docs/toys/dsl/positional_arg.rb +0 -155
  22. data/core-docs/toys/dsl/tool.rb +0 -1639
  23. data/core-docs/toys/errors.rb +0 -126
  24. data/core-docs/toys/flag.rb +0 -560
  25. data/core-docs/toys/flag_group.rb +0 -186
  26. data/core-docs/toys/input_file.rb +0 -17
  27. data/core-docs/toys/loader.rb +0 -363
  28. data/core-docs/toys/middleware.rb +0 -336
  29. data/core-docs/toys/mixin.rb +0 -142
  30. data/core-docs/toys/module_lookup.rb +0 -75
  31. data/core-docs/toys/positional_arg.rb +0 -145
  32. data/core-docs/toys/settings.rb +0 -524
  33. data/core-docs/toys/source_info.rb +0 -271
  34. data/core-docs/toys/standard_middleware/add_verbosity_flags.rb +0 -49
  35. data/core-docs/toys/standard_middleware/apply_config.rb +0 -24
  36. data/core-docs/toys/standard_middleware/handle_usage_errors.rb +0 -33
  37. data/core-docs/toys/standard_middleware/set_default_descriptions.rb +0 -222
  38. data/core-docs/toys/standard_middleware/show_help.rb +0 -190
  39. data/core-docs/toys/standard_middleware/show_root_version.rb +0 -45
  40. data/core-docs/toys/standard_mixins/bundler.rb +0 -98
  41. data/core-docs/toys/standard_mixins/exec.rb +0 -711
  42. data/core-docs/toys/standard_mixins/fileutils.rb +0 -18
  43. data/core-docs/toys/standard_mixins/gems.rb +0 -62
  44. data/core-docs/toys/standard_mixins/git_cache.rb +0 -41
  45. data/core-docs/toys/standard_mixins/highline.rb +0 -133
  46. data/core-docs/toys/standard_mixins/pager.rb +0 -50
  47. data/core-docs/toys/standard_mixins/terminal.rb +0 -135
  48. data/core-docs/toys/standard_mixins/xdg.rb +0 -49
  49. data/core-docs/toys/template.rb +0 -112
  50. data/core-docs/toys/tool_definition.rb +0 -1079
  51. data/core-docs/toys/utils/completion_engine.rb +0 -49
  52. data/core-docs/toys/utils/exec.rb +0 -776
  53. data/core-docs/toys/utils/gems.rb +0 -185
  54. data/core-docs/toys/utils/git_cache.rb +0 -353
  55. data/core-docs/toys/utils/help_text.rb +0 -134
  56. data/core-docs/toys/utils/pager.rb +0 -118
  57. data/core-docs/toys/utils/standard_ui.rb +0 -184
  58. data/core-docs/toys/utils/terminal.rb +0 -310
  59. data/core-docs/toys/utils/xdg.rb +0 -253
  60. data/core-docs/toys/wrappable_string.rb +0 -132
  61. data/core-docs/toys-core.rb +0 -111
@@ -1,1079 +0,0 @@
1
- module Toys
2
- ##
3
- # **_Defined in the toys-core gem_**
4
- #
5
- # A ToolDefinition describes a single command that can be invoked using Toys.
6
- # It has a name, a series of one or more words that you use to identify
7
- # the tool on the command line. It also has a set of formal flags and
8
- # command line arguments supported, and a block that gets run when the
9
- # tool is executed.
10
- #
11
- class ToolDefinition
12
- ##
13
- # **_Defined in the toys-core gem_**
14
- #
15
- # A Completion that implements the default algorithm for a tool.
16
- #
17
- class DefaultCompletion < Completion::Base
18
- ##
19
- # Create a completion given configuration options.
20
- #
21
- # @param complete_subtools [true,false] Whether to complete subtool names
22
- # @param include_hidden_subtools [true,false] Whether to include hidden
23
- # subtools (i.e. those beginning with an underscore)
24
- # @param complete_args [true,false] Whether to complete positional args
25
- # @param complete_flags [true,false] Whether to complete flag names
26
- # @param complete_flag_values [true,false] Whether to complete flag values
27
- # @param delegation_target [Array<String>,nil] Delegation target, or
28
- # `nil` if none.
29
- #
30
- def initialize(complete_subtools: true, include_hidden_subtools: false,
31
- complete_args: true, complete_flags: true, complete_flag_values: true,
32
- delegation_target: nil)
33
- # Source available in the toys-core gem
34
- end
35
-
36
- ##
37
- # Whether to complete subtool names
38
- # @return [true,false]
39
- #
40
- def complete_subtools?
41
- # Source available in the toys-core gem
42
- end
43
-
44
- ##
45
- # Whether to include hidden subtools
46
- # @return [true,false]
47
- #
48
- def include_hidden_subtools?
49
- # Source available in the toys-core gem
50
- end
51
-
52
- ##
53
- # Whether to complete flags
54
- # @return [true,false]
55
- #
56
- def complete_flags?
57
- # Source available in the toys-core gem
58
- end
59
-
60
- ##
61
- # Whether to complete positional args
62
- # @return [true,false]
63
- #
64
- def complete_args?
65
- # Source available in the toys-core gem
66
- end
67
-
68
- ##
69
- # Whether to complete flag values
70
- # @return [true,false]
71
- #
72
- def complete_flag_values?
73
- # Source available in the toys-core gem
74
- end
75
-
76
- ##
77
- # Delegation target, or nil for none.
78
- # @return [Array<String>] if there is a delegation target
79
- # @return [nil] if there is no delegation target
80
- #
81
- attr_accessor :delegation_target
82
-
83
- ##
84
- # Returns candidates for the current completion.
85
- #
86
- # @param context [Toys::Completion::Context] the current completion
87
- # context including the string fragment.
88
- # @return [Array<Toys::Completion::Candidate>] an array of candidates
89
- #
90
- def call(context)
91
- # Source available in the toys-core gem
92
- end
93
- end
94
-
95
- ##
96
- # **_Defined in the toys-core gem_**
97
- #
98
- # Tool-based settings class.
99
- #
100
- # The following settings are supported:
101
- #
102
- # * `propagate_helper_methods` (_boolean_) - Whether subtools should
103
- # inherit methods defined by parent tools. Defaults to `false`.
104
- #
105
- class Settings < ::Toys::Settings
106
- settings_attr :propagate_helper_methods, default: false
107
- end
108
-
109
- ##
110
- # Create a new tool.
111
- # Should be created only from the DSL via the Loader.
112
- #
113
- # @private This interface is internal and subject to change without warning.
114
- #
115
- def initialize(parent, full_name, priority, source_root, middleware_stack, middleware_lookup,
116
- tool_class = nil)
117
- # Source available in the toys-core gem
118
- end
119
-
120
- ##
121
- # Reset the definition of this tool, deleting all definition data but
122
- # leaving named acceptors, mixins, and templates intact.
123
- # Should be called only from the DSL.
124
- #
125
- # @private This interface is internal and subject to change without warning.
126
- #
127
- def reset_definition
128
- # Source available in the toys-core gem
129
- end
130
-
131
- ##
132
- # Settings for this tool
133
- #
134
- # @return [Toys::ToolDefinition::Settings]
135
- #
136
- attr_reader :settings
137
-
138
- ##
139
- # The name of the tool as an array of strings.
140
- # This array may not be modified.
141
- #
142
- # @return [Array<String>]
143
- #
144
- attr_reader :full_name
145
-
146
- ##
147
- # The priority of this tool definition.
148
- #
149
- # @return [Integer]
150
- #
151
- attr_reader :priority
152
-
153
- ##
154
- # The root source info defining this tool, or nil if there is no source.
155
- #
156
- # @return [Toys::SourceInfo,nil]
157
- #
158
- attr_reader :source_root
159
-
160
- ##
161
- # The tool class.
162
- #
163
- # @return [Class]
164
- #
165
- attr_reader :tool_class
166
-
167
- ##
168
- # The short description string.
169
- #
170
- # When reading, this is always returned as a {Toys::WrappableString}.
171
- #
172
- # When setting, the description may be provided as any of the following:
173
- # * A {Toys::WrappableString}.
174
- # * A normal String, which will be transformed into a
175
- # {Toys::WrappableString} using spaces as word delimiters.
176
- # * An Array of String, which will be transformed into a
177
- # {Toys::WrappableString} where each array element represents an
178
- # individual word for wrapping.
179
- #
180
- # @return [Toys::WrappableString]
181
- #
182
- attr_reader :desc
183
-
184
- ##
185
- # The long description strings.
186
- #
187
- # When reading, this is returned as an Array of {Toys::WrappableString}
188
- # representing the lines in the description.
189
- #
190
- # When setting, the description must be provided as an Array where *each
191
- # element* may be any of the following:
192
- # * A {Toys::WrappableString} representing one line.
193
- # * A normal String representing a line. This will be transformed into a
194
- # {Toys::WrappableString} using spaces as word delimiters.
195
- # * An Array of String representing a line. This will be transformed into
196
- # a {Toys::WrappableString} where each array element represents an
197
- # individual word for wrapping.
198
- #
199
- # @return [Array<Toys::WrappableString>]
200
- #
201
- attr_reader :long_desc
202
-
203
- ##
204
- # A list of all defined flag groups, in order.
205
- #
206
- # @return [Array<Toys::FlagGroup>]
207
- #
208
- attr_reader :flag_groups
209
-
210
- ##
211
- # A list of all defined flags.
212
- #
213
- # @return [Array<Toys::Flag>]
214
- #
215
- attr_reader :flags
216
-
217
- ##
218
- # A list of all defined required positional arguments.
219
- #
220
- # @return [Array<Toys::PositionalArg>]
221
- #
222
- attr_reader :required_args
223
-
224
- ##
225
- # A list of all defined optional positional arguments.
226
- #
227
- # @return [Array<Toys::PositionalArg>]
228
- #
229
- attr_reader :optional_args
230
-
231
- ##
232
- # The remaining arguments specification.
233
- #
234
- # @return [Toys::PositionalArg] The argument definition
235
- # @return [nil] if remaining arguments are not supported by this tool.
236
- #
237
- attr_reader :remaining_arg
238
-
239
- ##
240
- # A list of flags that have been used in the flag definitions.
241
- #
242
- # @return [Array<String>]
243
- #
244
- attr_reader :used_flags
245
-
246
- ##
247
- # The default context data set by arguments.
248
- #
249
- # @return [Hash]
250
- #
251
- attr_reader :default_data
252
-
253
- ##
254
- # The stack of middleware specs used for subtools.
255
- #
256
- # This array may be modified in place.
257
- #
258
- # @return [Array<Toys::Middleware::Spec>]
259
- #
260
- attr_reader :subtool_middleware_stack
261
-
262
- ##
263
- # The stack of built middleware specs for this tool.
264
- #
265
- # @return [Array<Toys::Middleware>]
266
- #
267
- attr_reader :built_middleware
268
-
269
- ##
270
- # Info on the source of this tool.
271
- #
272
- # @return [Toys::SourceInfo] The source info
273
- # @return [nil] if the source is not defined.
274
- #
275
- attr_reader :source_info
276
-
277
- ##
278
- # The custom context directory set for this tool.
279
- #
280
- # @return [String] The directory path
281
- # @return [nil] if no custom context directory is set.
282
- #
283
- attr_reader :custom_context_directory
284
-
285
- ##
286
- # The completion strategy for this tool.
287
- #
288
- # When reading, this may return an instance of one of the subclasses of
289
- # {Toys::Completion::Base}, or a Proc that duck-types it. Generally, this
290
- # defaults to a {Toys::ToolDefinition::DefaultCompletion}, providing a
291
- # standard algorithm that finds appropriate completions from flags,
292
- # positional arguments, and subtools.
293
- #
294
- # When setting, you may pass any of the following:
295
- # * `nil` or `:default` which sets the value to a default instance.
296
- # * A Hash of options to pass to the
297
- # {Toys::ToolDefinition::DefaultCompletion} constructor.
298
- # * Any other form recognized by {Toys::Completion.create}.
299
- #
300
- # @return [Toys::Completion::Base,Proc]
301
- #
302
- attr_reader :completion
303
-
304
- ##
305
- # The run handler.
306
- #
307
- # This handler is called to run the tool. Normally it is a method name,
308
- # represented by a symbol. (The default is `:run`.) It can be set to a
309
- # different method name, or to a proc that will be called with `self` set
310
- # to the tool context. Either way, it takes no arguments. The run handler
311
- # can also be explicitly set to `nil` indicating a non-runnable tool;
312
- # however, typically a tool is made non-runnable simply by leaving the run
313
- # handler set to `:run` and not defining the method.
314
- #
315
- # @return [Proc] if the run handler is defined as a Proc
316
- # @return [Symbol] if the run handler is defined as a method
317
- # @return [nil] if the tool is explicitly made non-runnable
318
- #
319
- attr_reader :run_handler
320
-
321
- ##
322
- # The usage error handler.
323
- #
324
- # This handler is called when at least one usage error is detected during
325
- # argument parsing, and is called instead of the `run` method. It can be
326
- # specified as a Proc, or a Symbol indicating a method to call. It
327
- # optionally takes an array of {Toys::ArgParser::UsageError} as the sole
328
- # argument.
329
- #
330
- # @return [Proc] if the usage error handler is defined as a Proc
331
- # @return [Symbol] if the user error handler is defined as a method
332
- # @return [nil] if there is no usage error handler
333
- #
334
- attr_reader :usage_error_handler
335
-
336
- ##
337
- # The full name of the delegate target, if any.
338
- #
339
- # @return [Array<String>] if this tool delegates
340
- # @return [nil] if this tool does not delegate
341
- #
342
- attr_reader :delegate_target
343
-
344
- ##
345
- # The local name of this tool, i.e. the last element of the full name.
346
- #
347
- # @return [String]
348
- #
349
- def simple_name
350
- # Source available in the toys-core gem
351
- end
352
-
353
- ##
354
- # A displayable name of this tool, generally the full name delimited by
355
- # spaces.
356
- #
357
- # @return [String]
358
- #
359
- def display_name
360
- # Source available in the toys-core gem
361
- end
362
-
363
- ##
364
- # Return the signal handler for the given signal.
365
- #
366
- # This handler is called when the given signal is received, immediately
367
- # taking over the execution as if it were the new run handler. The signal
368
- # handler can be specified as a Proc, or a Symbol indicating a method to
369
- # call. It optionally takes the `SignalException` as the sole argument.
370
- #
371
- # @param signal [Integer,String,Symbol] The signal number or name
372
- # @return [Proc] if the signal handler is defined as a Proc
373
- # @return [Symbol] if the signal handler is defined as a method
374
- # @return [nil] if there is no handler for the given signal
375
- #
376
- def signal_handler(signal)
377
- # Source available in the toys-core gem
378
- end
379
-
380
- ##
381
- # Return the interrupt handler. This is equivalent to `signal_handler(2)`.
382
- #
383
- # @return [Proc] if the interrupt signal handler is defined as a Proc
384
- # @return [Symbol] if the interrupt signal handler is defined as a method
385
- # @return [nil] if there is no handler for the interrupt signals
386
- #
387
- def interrupt_handler
388
- # Source available in the toys-core gem
389
- end
390
-
391
- ##
392
- # Returns true if this tool is a root tool.
393
- # @return [true,false]
394
- #
395
- def root?
396
- # Source available in the toys-core gem
397
- end
398
-
399
- ##
400
- # Returns true if this tool is marked as runnable.
401
- # @return [true,false]
402
- #
403
- def runnable?
404
- # Source available in the toys-core gem
405
- end
406
-
407
- ##
408
- # Returns true if this tool handles interrupts. This is equivalent to
409
- # `handles_signal?(2)`.
410
- #
411
- # @return [true,false]
412
- #
413
- def handles_interrupts?
414
- # Source available in the toys-core gem
415
- end
416
-
417
- ##
418
- # Returns true if this tool handles the given signal.
419
- #
420
- # @param signal [Integer,String,Symbol] The signal number or name
421
- # @return [true,false]
422
- #
423
- def handles_signal?(signal)
424
- # Source available in the toys-core gem
425
- end
426
-
427
- ##
428
- # Returns true if this tool handles usage errors.
429
- # @return [true,false]
430
- #
431
- def handles_usage_errors?
432
- # Source available in the toys-core gem
433
- end
434
-
435
- ##
436
- # Returns true if this tool has at least one included module.
437
- # @return [true,false]
438
- #
439
- def includes_modules?
440
- # Source available in the toys-core gem
441
- end
442
-
443
- ##
444
- # Returns true if there is a specific description set for this tool.
445
- # @return [true,false]
446
- #
447
- def includes_description?
448
- # Source available in the toys-core gem
449
- end
450
-
451
- ##
452
- # Returns true if at least one flag or positional argument is defined
453
- # for this tool.
454
- # @return [true,false]
455
- #
456
- def includes_arguments?
457
- # Source available in the toys-core gem
458
- end
459
-
460
- ##
461
- # Returns true if this tool has any definition information.
462
- # @return [true,false]
463
- #
464
- def includes_definition?
465
- # Source available in the toys-core gem
466
- end
467
-
468
- ##
469
- # Returns true if this tool's definition has been finished and is locked.
470
- # @return [true,false]
471
- #
472
- def definition_finished?
473
- # Source available in the toys-core gem
474
- end
475
-
476
- ##
477
- # Returns true if this tool has disabled argument parsing.
478
- # @return [true,false]
479
- #
480
- def argument_parsing_disabled?
481
- # Source available in the toys-core gem
482
- end
483
-
484
- ##
485
- # Returns true if this tool enforces flags before args.
486
- # @return [true,false]
487
- #
488
- def flags_before_args_enforced?
489
- # Source available in the toys-core gem
490
- end
491
-
492
- ##
493
- # Returns true if this tool requires exact flag matches.
494
- # @return [true,false]
495
- #
496
- def exact_flag_match_required?
497
- # Source available in the toys-core gem
498
- end
499
-
500
- ##
501
- # All arg definitions in order: required, optional, remaining.
502
- #
503
- # @return [Array<Toys::PositionalArg>]
504
- #
505
- def positional_args
506
- # Source available in the toys-core gem
507
- end
508
-
509
- ##
510
- # Resolve the given flag given the flag string. Returns an object that
511
- # describes the resolution result, including whether the resolution
512
- # matched a unique flag, the specific flag syntax that was matched, and
513
- # additional information.
514
- #
515
- # @param str [String] Flag string
516
- # @return [Toys::Flag::Resolution]
517
- #
518
- def resolve_flag(str)
519
- # Source available in the toys-core gem
520
- end
521
-
522
- ##
523
- # Get the named acceptor from this tool or its ancestors.
524
- #
525
- # @param name [String] The acceptor name.
526
- # @return [Toys::Acceptor::Base] The acceptor.
527
- # @return [nil] if no acceptor of the given name is found.
528
- #
529
- def lookup_acceptor(name)
530
- # Source available in the toys-core gem
531
- end
532
-
533
- ##
534
- # Get the named template from this tool or its ancestors.
535
- #
536
- # @param name [String] The template name.
537
- # @return [Class,nil] The template class.
538
- # @return [nil] if no template of the given name is found.
539
- #
540
- def lookup_template(name)
541
- # Source available in the toys-core gem
542
- end
543
-
544
- ##
545
- # Get the named mixin from this tool or its ancestors.
546
- #
547
- # @param name [String] The mixin name.
548
- # @return [Module] The mixin module.
549
- # @return [nil] if no mixin of the given name is found.
550
- #
551
- def lookup_mixin(name)
552
- # Source available in the toys-core gem
553
- end
554
-
555
- ##
556
- # Get the named completion from this tool or its ancestors.
557
- #
558
- # @param name [String] The completion name
559
- # @return [Toys::Completion::Base,Proc] The completion proc.
560
- # @return [nil] if no completion of the given name is found.
561
- #
562
- def lookup_completion(name)
563
- # Source available in the toys-core gem
564
- end
565
-
566
- ##
567
- # Include the given mixin in the tool class.
568
- #
569
- # The mixin must be given as a module. You can use {#lookup_mixin} to
570
- # resolve named mixins.
571
- #
572
- # @param mod [Module] The mixin module
573
- # @return [self]
574
- #
575
- def include_mixin(mod, *args, **kwargs)
576
- # Source available in the toys-core gem
577
- end
578
-
579
- ##
580
- # Sets the path to the file that defines this tool.
581
- # A tool may be defined from at most one path. If a different path is
582
- # already set, it is left unchanged.
583
- #
584
- # @param source [Toys::SourceInfo] Source info
585
- # @return [self]
586
- #
587
- def lock_source(source)
588
- # Source available in the toys-core gem
589
- end
590
-
591
- ##
592
- # Set the short description string.
593
- #
594
- # See {#desc} for details.
595
- #
596
- # @param desc [Toys::WrappableString,String,Array<String>]
597
- #
598
- def desc=(desc)
599
- # Source available in the toys-core gem
600
- end
601
-
602
- ##
603
- # Set the long description strings.
604
- #
605
- # See {#long_desc} for details.
606
- #
607
- # @param long_desc [Array<Toys::WrappableString,String,Array<String>>]
608
- #
609
- def long_desc=(long_desc)
610
- # Source available in the toys-core gem
611
- end
612
-
613
- ##
614
- # Append long description strings.
615
- #
616
- # You must pass an array of lines in the long description. See {#long_desc}
617
- # for details on how each line may be represented.
618
- #
619
- # @param long_desc [Array<Toys::WrappableString,String,Array<String>>]
620
- # @return [self]
621
- #
622
- def append_long_desc(long_desc)
623
- # Source available in the toys-core gem
624
- end
625
-
626
- ##
627
- # Add a named acceptor to the tool. This acceptor may be refereneced by
628
- # name when adding a flag or an arg. See {Toys::Acceptor.create} for
629
- # detailed information on how to specify an acceptor.
630
- #
631
- # @param name [String] The name of the acceptor.
632
- # @param acceptor [Toys::Acceptor::Base,Object] The acceptor to add. You
633
- # can provide either an acceptor object, or a spec understood by
634
- # {Toys::Acceptor.create}.
635
- # @param type_desc [String] Type description string, shown in help.
636
- # Defaults to the acceptor name.
637
- # @param block [Proc] Optional block used to create an acceptor. See
638
- # {Toys::Acceptor.create}.
639
- # @return [self]
640
- #
641
- def add_acceptor(name, acceptor = nil, type_desc: nil, &block)
642
- # Source available in the toys-core gem
643
- end
644
-
645
- ##
646
- # Add a named mixin module to this tool.
647
- # You may provide a mixin module or a block that configures one.
648
- #
649
- # @param name [String] The name of the mixin.
650
- # @param mixin_module [Module] The mixin module.
651
- # @param block [Proc] Define the mixin module here if a `mixin_module` is
652
- # not provided directly.
653
- # @return [self]
654
- #
655
- def add_mixin(name, mixin_module = nil, &block)
656
- # Source available in the toys-core gem
657
- end
658
-
659
- ##
660
- # Add a named completion proc to this tool. The completion may be
661
- # referenced by name when adding a flag or an arg. See
662
- # {Toys::Completion.create} for detailed information on how to specify a
663
- # completion.
664
- #
665
- # @param name [String] The name of the completion.
666
- # @param completion [Proc,Toys::Completion::Base,Object] The completion to
667
- # add. You can provide either a completion object, or a spec understood
668
- # by {Toys::Completion.create}.
669
- # @param options [Hash] Additional options to pass to the completion.
670
- # @param block [Proc] Optional block used to create a completion. See
671
- # {Toys::Completion.create}.
672
- # @return [self]
673
- #
674
- def add_completion(name, completion = nil, **options, &block)
675
- # Source available in the toys-core gem
676
- end
677
-
678
- ##
679
- # Add a named template class to this tool.
680
- # You may provide a template class or a block that configures one.
681
- #
682
- # @param name [String] The name of the template.
683
- # @param template_class [Class] The template class.
684
- # @param block [Proc] Define the template class here if a `template_class`
685
- # is not provided directly.
686
- # @return [self]
687
- #
688
- def add_template(name, template_class = nil, &block)
689
- # Source available in the toys-core gem
690
- end
691
-
692
- ##
693
- # Disable argument parsing for this tool.
694
- #
695
- # @return [self]
696
- #
697
- def disable_argument_parsing
698
- # Source available in the toys-core gem
699
- end
700
-
701
- ##
702
- # Enforce that flags must come before args for this tool.
703
- # You may disable enforcement by passoing `false` for the state.
704
- #
705
- # @param state [true,false]
706
- # @return [self]
707
- #
708
- def enforce_flags_before_args(state = true)
709
- # Source available in the toys-core gem
710
- end
711
-
712
- ##
713
- # Require that flags must match exactly. (If false, flags can match an
714
- # unambiguous substring.)
715
- #
716
- # @param state [true,false]
717
- # @return [self]
718
- #
719
- def require_exact_flag_match(state = true)
720
- # Source available in the toys-core gem
721
- end
722
-
723
- ##
724
- # Add a flag group to the group list.
725
- #
726
- # The type should be one of the following symbols:
727
- # * `:optional` All flags in the group are optional
728
- # * `:required` All flags in the group are required
729
- # * `:exactly_one` Exactly one flag in the group must be provided
730
- # * `:at_least_one` At least one flag in the group must be provided
731
- # * `:at_most_one` At most one flag in the group must be provided
732
- #
733
- # @param type [Symbol] The type of group. Default is `:optional`.
734
- # @param desc [String,Array<String>,Toys::WrappableString] Short
735
- # description for the group. See {Toys::ToolDefinition#desc} for a
736
- # description of allowed formats. Defaults to `"Flags"`.
737
- # @param long_desc [Array<String,Array<String>,Toys::WrappableString>]
738
- # Long description for the flag group. See
739
- # {Toys::ToolDefinition#long_desc} for a description of allowed
740
- # formats. Defaults to the empty array.
741
- # @param name [String,Symbol,nil] The name of the group, or nil for no
742
- # name.
743
- # @param report_collisions [true,false] If `true`, raise an exception if a
744
- # the given name is already taken. If `false`, ignore. Default is
745
- # `true`.
746
- # @param prepend [true,false] If `true`, prepend rather than append the
747
- # group to the list. Default is `false`.
748
- # @return [self]
749
- #
750
- def add_flag_group(type: :optional, desc: nil, long_desc: nil,
751
- name: nil, report_collisions: true, prepend: false)
752
- # Source available in the toys-core gem
753
- end
754
-
755
- ##
756
- # Add a flag to the current tool. Each flag must specify a key which
757
- # the script may use to obtain the flag value from the context.
758
- # You may then provide the flags themselves in `OptionParser` form.
759
- #
760
- # @param key [String,Symbol] The key to use to retrieve the value from
761
- # the execution context.
762
- # @param flags [Array<String>] The flags in OptionParser format. If empty,
763
- # a flag will be inferred from the key.
764
- # @param accept [Object] An acceptor that validates and/or converts the
765
- # value. You may provide either the name of an acceptor you have
766
- # defined, or one of the default acceptors provided by OptionParser.
767
- # Optional. If not specified, accepts any value as a string.
768
- # @param default [Object] The default value. This is the value that will
769
- # be set in the context if this flag is not provided on the command
770
- # line. Defaults to `nil`.
771
- # @param handler [Proc,nil,:set,:push] An optional handler for
772
- # setting/updating the value. A handler is a proc taking two
773
- # arguments, the given value and the previous value, returning the
774
- # new value that should be set. You may also specify a predefined
775
- # named handler. The `:set` handler (the default) replaces the
776
- # previous value (effectively `-> (val, _prev) { val }`). The
777
- # `:push` handler expects the previous value to be an array and
778
- # pushes the given value onto it; it should be combined with setting
779
- # `default: []` and is intended for "multi-valued" flags.
780
- # @param complete_flags [Object] A specifier for shell tab completion
781
- # for flag names associated with this flag. By default, a
782
- # {Toys::Flag::DefaultCompletion} is used, which provides the flag's
783
- # names as completion candidates. To customize completion, set this to
784
- # a hash of options to pass to the constructor for
785
- # {Toys::Flag::DefaultCompletion}, or pass any other spec recognized
786
- # by {Toys::Completion.create}.
787
- # @param complete_values [Object] A specifier for shell tab completion
788
- # for flag values associated with this flag. Pass any spec
789
- # recognized by {Toys::Completion.create}.
790
- # @param report_collisions [true,false] Raise an exception if a flag is
791
- # requested that is already in use or marked as disabled. Default is
792
- # true.
793
- # @param group [Toys::FlagGroup,String,Symbol,nil] Group for
794
- # this flag. You may provide a group name, a FlagGroup object, or
795
- # `nil` which denotes the default group.
796
- # @param desc [String,Array<String>,Toys::WrappableString] Short
797
- # description for the flag. See {Toys::ToolDefinition#desc} for a
798
- # description of allowed formats. Defaults to the empty string.
799
- # @param long_desc [Array<String,Array<String>,Toys::WrappableString>]
800
- # Long description for the flag. See {Toys::ToolDefinition#long_desc}
801
- # for a description of allowed formats. Defaults to the empty array.
802
- # @param display_name [String] A display name for this flag, used in help
803
- # text and error messages.
804
- # @return [self]
805
- #
806
- def add_flag(key, flags = [],
807
- accept: nil, default: nil, handler: nil, complete_flags: nil,
808
- complete_values: nil, report_collisions: true, group: nil, desc: nil,
809
- long_desc: nil, display_name: nil)
810
- # Source available in the toys-core gem
811
- end
812
-
813
- ##
814
- # Mark one or more flags as disabled, preventing their use by any
815
- # subsequent flag definition. This may be used to prevent middleware from
816
- # defining a particular flag.
817
- #
818
- # @param flags [String...] The flags to disable
819
- # @return [self]
820
- #
821
- def disable_flag(*flags)
822
- # Source available in the toys-core gem
823
- end
824
-
825
- ##
826
- # Add a required positional argument to the current tool. You must specify
827
- # a key which the script may use to obtain the argument value from the
828
- # context.
829
- #
830
- # @param key [String,Symbol] The key to use to retrieve the value from
831
- # the execution context.
832
- # @param accept [Object] An acceptor that validates and/or converts the
833
- # value. You may provide either the name of an acceptor you have
834
- # defined, or one of the default acceptors provided by OptionParser.
835
- # Optional. If not specified, accepts any value as a string.
836
- # @param complete [Object] A specifier for shell tab completion. See
837
- # {Toys::Completion.create} for recognized formats.
838
- # @param display_name [String] A name to use for display (in help text and
839
- # error reports). Defaults to the key in upper case.
840
- # @param desc [String,Array<String>,Toys::WrappableString] Short
841
- # description for the arg. See {Toys::ToolDefinition#desc} for a
842
- # description of allowed formats. Defaults to the empty string.
843
- # @param long_desc [Array<String,Array<String>,Toys::WrappableString>]
844
- # Long description for the arg. See {Toys::ToolDefinition#long_desc}
845
- # for a description of allowed formats. Defaults to the empty array.
846
- # @return [self]
847
- #
848
- def add_required_arg(key, accept: nil, complete: nil, display_name: nil,
849
- desc: nil, long_desc: nil)
850
- # Source available in the toys-core gem
851
- end
852
-
853
- ##
854
- # Add an optional positional argument to the current tool. You must specify
855
- # a key which the script may use to obtain the argument value from the
856
- # context. If an optional argument is not given on the command line, the
857
- # value is set to the given default.
858
- #
859
- # @param key [String,Symbol] The key to use to retrieve the value from
860
- # the execution context.
861
- # @param default [Object] The default value. This is the value that will
862
- # be set in the context if this argument is not provided on the command
863
- # line. Defaults to `nil`.
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, or one of the default acceptors provided by OptionParser.
867
- # Optional. If not specified, accepts any value as a string.
868
- # @param complete [Object] A specifier for shell tab completion. See
869
- # {Toys::Completion.create} for recognized formats.
870
- # @param display_name [String] A name to use for display (in help text and
871
- # error reports). Defaults to the key in upper case.
872
- # @param desc [String,Array<String>,Toys::WrappableString] Short
873
- # description for the arg. See {Toys::ToolDefinition#desc} for a
874
- # description of allowed formats. Defaults to the empty string.
875
- # @param long_desc [Array<String,Array<String>,Toys::WrappableString>]
876
- # Long description for the arg. See {Toys::ToolDefinition#long_desc}
877
- # for a description of allowed formats. Defaults to the empty array.
878
- # @return [self]
879
- #
880
- def add_optional_arg(key, default: nil, accept: nil, complete: nil,
881
- display_name: nil, desc: nil, long_desc: nil)
882
- # Source available in the toys-core gem
883
- end
884
-
885
- ##
886
- # Specify what should be done with unmatched positional arguments. You must
887
- # specify a key which the script may use to obtain the remaining args
888
- # from the context.
889
- #
890
- # @param key [String,Symbol] The key to use to retrieve the value from
891
- # the execution context.
892
- # @param default [Object] The default value. This is the value that will
893
- # be set in the context if no unmatched arguments are provided on the
894
- # command line. Defaults to the empty array `[]`.
895
- # @param accept [Object] An acceptor that validates and/or converts the
896
- # value. You may provide either the name of an acceptor you have
897
- # defined, or one of the default acceptors provided by OptionParser.
898
- # Optional. If not specified, accepts any value as a string.
899
- # @param complete [Object] A specifier for shell tab completion. See
900
- # {Toys::Completion.create} for recognized formats.
901
- # @param display_name [String] A name to use for display (in help text and
902
- # error reports). Defaults to the key in upper case.
903
- # @param desc [String,Array<String>,Toys::WrappableString] Short
904
- # description for the arg. See {Toys::ToolDefinition#desc} for a
905
- # description of allowed formats. Defaults to the empty string.
906
- # @param long_desc [Array<String,Array<String>,Toys::WrappableString>]
907
- # Long description for the arg. See {Toys::ToolDefinition#long_desc}
908
- # for a description of allowed formats. Defaults to the empty array.
909
- # @return [self]
910
- #
911
- def set_remaining_args(key, default: [], accept: nil, complete: nil,
912
- display_name: nil, desc: nil, long_desc: nil)
913
- # Source available in the toys-core gem
914
- end
915
-
916
- ##
917
- # Set the run handler.
918
- #
919
- # This handler is called to run the tool. Normally it is a method name,
920
- # represented by a symbol. (The default is `:run`.) It can be set to a
921
- # different method name, or to a proc that will be called with `self` set
922
- # to the tool context. Either way, it takes no arguments. The run handler
923
- # can also be explicitly set to `nil` indicating a non-runnable tool;
924
- # however, typically a tool is made non-runnable simply by leaving the run
925
- # handler set to `:run` and not defining the method.
926
- #
927
- # @param handler [Proc,Symbol,nil] the run handler
928
- #
929
- def run_handler=(handler)
930
- # Source available in the toys-core gem
931
- end
932
-
933
- ##
934
- # Set the interrupt handler. This is equivalent to calling
935
- # {#set_signal_handler} for the `SIGINT` signal.
936
- #
937
- # @param handler [Proc,Symbol] The interrupt signal handler
938
- #
939
- def interrupt_handler=(handler)
940
- # Source available in the toys-core gem
941
- end
942
-
943
- ##
944
- # Set the handler for the given signal.
945
- #
946
- # This handler is called when the given signal is received, immediately
947
- # taking over the execution as if it were the new `run` method. The signal
948
- # handler can be specified as a Proc, or a Symbol indicating a method to
949
- # call. It optionally takes the `SignalException` as the sole argument.
950
- #
951
- # @param signal [Integer,String,Symbol] The signal number or name
952
- # @param handler [Proc,Symbol] The signal handler
953
- #
954
- def set_signal_handler(signal, handler)
955
- # Source available in the toys-core gem
956
- end
957
-
958
- ##
959
- # Set the usage error handler.
960
- #
961
- # This handler is called when at least one usage error is detected during
962
- # argument parsing, and is called instead of the `run` method. It can be
963
- # specified as a Proc, or a Symbol indicating a method to call. It
964
- # optionally takes an array of {Toys::ArgParser::UsageError} as the sole
965
- # argument.
966
- #
967
- # @param handler [Proc,Symbol] The usage error handler
968
- #
969
- def usage_error_handler=(handler)
970
- # Source available in the toys-core gem
971
- end
972
-
973
- ##
974
- # Add an initializer.
975
- #
976
- # @param proc [Proc] The initializer block
977
- # @param args [Object...] Arguments to pass to the initializer
978
- # @param kwargs [keywords] Keyword arguments to pass to the initializer
979
- # @return [self]
980
- #
981
- def add_initializer(proc, *args, **kwargs)
982
- # Source available in the toys-core gem
983
- end
984
-
985
- ##
986
- # Set the custom context directory.
987
- #
988
- # See {#custom_context_directory} for details.
989
- #
990
- # @param dir [String]
991
- #
992
- def custom_context_directory=(dir)
993
- # Source available in the toys-core gem
994
- end
995
-
996
- ##
997
- # Set the completion strategy for this ToolDefinition.
998
- #
999
- # See {#completion} for details.
1000
- #
1001
- # @param spec [Object]
1002
- #
1003
- def completion=(spec)
1004
- # Source available in the toys-core gem
1005
- end
1006
-
1007
- ##
1008
- # Return the effective context directory.
1009
- # If there is a custom context directory, uses that. Otherwise, looks for
1010
- # a custom context directory up the tool ancestor chain. If none is
1011
- # found, uses the default context directory from the source info. It is
1012
- # possible for there to be no context directory at all, in which case,
1013
- # returns nil.
1014
- #
1015
- # @return [String] The effective context directory path.
1016
- # @return [nil] if there is no effective context directory.
1017
- #
1018
- def context_directory
1019
- # Source available in the toys-core gem
1020
- end
1021
-
1022
- ##
1023
- # Causes this tool to delegate to another tool.
1024
- #
1025
- # @param target [Array<String>] The full path to the delegate tool.
1026
- # @return [self]
1027
- #
1028
- def delegate_to(target)
1029
- # Source available in the toys-core gem
1030
- end
1031
-
1032
- ##
1033
- # Lookup the custom context directory in this tool and its ancestors.
1034
- #
1035
- # @private This interface is internal and subject to change without warning.
1036
- #
1037
- def lookup_custom_context_directory
1038
- # Source available in the toys-core gem
1039
- end
1040
-
1041
- ##
1042
- # Mark this tool as having at least one module included.
1043
- #
1044
- # @private This interface is internal and subject to change without warning.
1045
- #
1046
- def mark_includes_modules
1047
- # Source available in the toys-core gem
1048
- end
1049
-
1050
- ##
1051
- # Complete definition and run middleware configs. Should be called from
1052
- # the Loader only.
1053
- #
1054
- # @private This interface is internal and subject to change without warning.
1055
- #
1056
- def finish_definition(loader)
1057
- # Source available in the toys-core gem
1058
- end
1059
-
1060
- ##
1061
- # Run all initializers against a context. Called from the Runner.
1062
- #
1063
- # @private This interface is internal and subject to change without warning.
1064
- #
1065
- def run_initializers(context)
1066
- # Source available in the toys-core gem
1067
- end
1068
-
1069
- ##
1070
- # Check that the tool can still be defined. Should be called internally
1071
- # or from the DSL only.
1072
- #
1073
- # @private This interface is internal and subject to change without warning.
1074
- #
1075
- def check_definition_state(is_arg: false, is_method: false)
1076
- # Source available in the toys-core gem
1077
- end
1078
- end
1079
- end