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,524 +0,0 @@
1
- module Toys
2
- ##
3
- # **_Defined in the toys-core gem_**
4
- #
5
- # A settings class defines the structure of application settings, i.e. the
6
- # various fields that can be set, and their types. You can define a settings
7
- # structure by subclassing this base class, and using the provided methods.
8
- #
9
- # ### Attributes
10
- #
11
- # To define an attribute, use the {Settings.settings_attr} declaration.
12
- #
13
- # Example:
14
- #
15
- # class ServiceSettings < Toys::Settings
16
- # settings_attr :endpoint, default: "api.example.com"
17
- # end
18
- #
19
- # my_settings = ServiceSettings.new
20
- # my_settings.endpoint_set? # => false
21
- # my_settings.endpoint # => "api.example.com"
22
- # my_settings.endpoint = "rest.example.com"
23
- # my_settings.endpoint_set? # => true
24
- # my_settings.endpoint # => "rest.example.com"
25
- # my_settings.endpoint_unset!
26
- # my_settings.endpoint_set? # => false
27
- # my_settings.endpoint # => "api.example.com"
28
- #
29
- # An attribute has a name, a default value, and a type specification. The
30
- # name is used to define methods for getting and setting the attribute. The
31
- # default is returned if no value is set. (See the section below on parents
32
- # and defaults for more information.) The type specification governs what
33
- # values are allowed. (See the section below on type specifications.)
34
- #
35
- # Attribute names must start with an ascii letter, and may contain only ascii
36
- # letters, digits, and underscores. Unlike method names, they may not include
37
- # non-ascii unicode characters, nor may they end with `!` or `?`.
38
- # Additionally, the name `method_missing` is not allowed because of its
39
- # special behavior in Ruby.
40
- #
41
- # Each attribute defines four methods: a getter, a setter, an unsetter, and a
42
- # set detector. In the above example, the attribute named `:endpoint` creates
43
- # the following four methods:
44
- #
45
- # * `endpoint` - retrieves the attribute value, or a default if not set.
46
- # * `endpoint=(value)` - sets a new attribute value.
47
- # * `endpoint_unset!` - unsets the attribute, reverting to a default.
48
- # * `endpoint_set?` - returns a boolean, whether the attribute is set.
49
- #
50
- # ### Groups
51
- #
52
- # A group is a settings field that itself is a Settings object. You can use
53
- # it to group settings fields in a hierarchy.
54
- #
55
- # Example:
56
- #
57
- # class ServiceSettings < Toys::Settings
58
- # settings_attr :endpoint, default: "api.example.com"
59
- # settings_group :service_flags do
60
- # settings_attr :verbose, default: false
61
- # settings_attr :use_proxy, default: false
62
- # end
63
- # end
64
- #
65
- # my_settings = ServiceSettings.new
66
- # my_settings.service_flags.verbose # => false
67
- # my_settings.service_flags.verbose = true
68
- # my_settings.service_flags.verbose # => true
69
- # my_settings.endpoint # => "api.example.com"
70
- #
71
- # You can define a group inline, as in the example above, or create an
72
- # explicit settings class and use it for the group. For example:
73
- #
74
- # class Flags < Toys::Settings
75
- # settings_attr :verbose, default: false
76
- # settings_attr :use_proxy, default: false
77
- # end
78
- # class ServiceSettings < Toys::Settings
79
- # settings_attr :endpoint, default: "api.example.com"
80
- # settings_group :service_flags, Flags
81
- # end
82
- #
83
- # my_settings = ServiceSettings.new
84
- # my_settings.service_flags.verbose = true
85
- #
86
- # If the module enclosing a subclass of `Settings` is itself a subclass of
87
- # `Settings`, then the class is automatically added to its enclosing class as
88
- # a group. For example:
89
- #
90
- # class ServiceSettings < Toys::Settings
91
- # settings_attr :endpoint, default: "api.example.com"
92
- # # Automatically adds this as the group service_flags.
93
- # # The name is inferred (snake_cased) from the class name.
94
- # class ServiceFlags < Toys::Settings
95
- # settings_attr :verbose, default: false
96
- # settings_attr :use_proxy, default: false
97
- # end
98
- # end
99
- #
100
- # my_settings = ServiceSettings.new
101
- # my_settings.service_flags.verbose = true
102
- #
103
- # ### Type specifications
104
- #
105
- # A type specification is a restriction on the types of values allowed for a
106
- # settings field. Every attribute has a type specification. You can set it
107
- # explicitly by providing a `:type` argument or a block. If a type
108
- # specification is not provided explicitly, it is inferred from the default
109
- # value of the attribute.
110
- #
111
- # Type specifications can be any of the following:
112
- #
113
- # * A Module, restricting values to those that include the module.
114
- #
115
- # For example, a type specification of `Enumerable` would accept `[123]`
116
- # but not `123`.
117
- #
118
- # * A Class, restricting values to that class or any subclass.
119
- #
120
- # For example, a type specification of `Time` would accept `Time.now` but
121
- # not `DateTime.now`.
122
- #
123
- # Note that some classes will convert (i.e. parse) strings. For example,
124
- # a type specification of `Integer` will accept the string `"-123"`` and
125
- # convert it to the value `-123`. Classes that support parsing include:
126
- #
127
- # * `Date`
128
- # * `DateTime`
129
- # * `Float`
130
- # * `Integer`
131
- # * `Regexp`
132
- # * `Symbol`
133
- # * `Time`
134
- #
135
- # * A Regexp, restricting values to strings matching the regexp.
136
- #
137
- # For example, a type specification of `/^\w+$/` would match `"abc"` but
138
- # not `"abc!"`.
139
- #
140
- # * A Range, restricting values to objects that fall in the range and are
141
- # of the same class (or a subclass) as the endpoints. String values are
142
- # accepted if they can be converted to the endpoint class as specified by
143
- # a class type specification.
144
- #
145
- # For example, a type specification of `(1..5)` would match `5` but not
146
- # `6`. It would also match `"5"` because the String can be parsed into an
147
- # Integer in the range.
148
- #
149
- # * A specific value, any Symbol, String, Numeric, or the values `nil`,
150
- # `true`, or `false`, restricting the value to only that given value.
151
- #
152
- # For example, a type specification of `:foo` would match `:foo` but not
153
- # `:bar`.
154
- #
155
- # (It might not seem terribly useful to have an attribute that can take
156
- # only one value, but this type is generally used as part of a union
157
- # type, described below, to implement an enumeration.)
158
- #
159
- # * An Array representing a union type, each of whose elements is one of
160
- # the above types. Values are accepted if they match any of the elements.
161
- #
162
- # For example, a type specification of `[:a, :b :c]` would match `:a` but
163
- # not `"a"`. Similarly, a type specification of `[String, Integer, nil]`
164
- # would match `"hello"`, `123`, or `nil`, but not `123.4`.
165
- #
166
- # * A Proc that takes the proposed value and returns either the value if it
167
- # is legal, the converted value if it can be converted to a legal value,
168
- # or the constant {Toys::Settings::ILLEGAL_VALUE} if it cannot be
169
- # converted to a legal value. You may also pass a block to
170
- # `settings_attr` to set a Proc type specification.
171
- #
172
- # * A {Toys::Settings::Type} that checks and converts values.
173
- #
174
- # If you do not explicitly provide a type specification, one is inferred from
175
- # the attribute's default value. The rules are:
176
- #
177
- # * If the default value is `true` or `false`, then the type specification
178
- # inferred is `[true, false]`.
179
- #
180
- # * If the default value is `nil` or not provided, then the type
181
- # specification allows any object (i.e. is equivalent to `Object`).
182
- #
183
- # * Otherwise, the type specification allows any value of the same class as
184
- # the default value. For example, if the default value is `""`, the
185
- # effective type specification is `String`.
186
- #
187
- # Examples:
188
- #
189
- # class ServiceSettings < Toys::Settings
190
- # # Allows only strings because the default is a string.
191
- # settings_attr :endpoint, default: "example.com"
192
- # end
193
- #
194
- # class ServiceSettings < Toys::Settings
195
- # # Allows strings or nil.
196
- # settings_attr :endpoint, default: "example.com", type: [String, nil]
197
- # end
198
- #
199
- # class ServiceSettings < Toys::Settings
200
- # # Raises ArgumentError because the default is nil, which does not
201
- # # match the type specification. (You should either allow nil
202
- # # explicitly with `type: [String, nil]` or set the default to a
203
- # # suitable string such as the empty string "".)
204
- # settings_attr :endpoint, type: String
205
- # end
206
- #
207
- # ### Settings parents
208
- #
209
- # A settings object can have a "parent" which provides the values if they are
210
- # not set in the settings object. This lets you organize settings as
211
- # "defaults" and "overrides". A parent settings object provides the defaults,
212
- # and a child can selectively override certain values.
213
- #
214
- # To set the parent for a settings object, pass it as the argument to the
215
- # Settings constructor. When a field in a settings object is queried, it
216
- # looks up the value as follows:
217
- #
218
- # * If a field value is explicitly set in the settings object, that value
219
- # is returned.
220
- # * If the field is not set in the settings object, but the settings object
221
- # has a parent, the parent is queried. If that parent also does not have
222
- # a value for the field, it may query its parent in turn, and so forth.
223
- # * If we encounter a root settings with no parent, and still no value is
224
- # set for the field, the default for the *original* setting is returned.
225
- #
226
- # Example:
227
- #
228
- # class MySettings < Toys::Settings
229
- # settings_attr :str, default: "default"
230
- # end
231
- #
232
- # root_settings = MySettings.new
233
- # child_settings = MySettings.new(root_settings)
234
- # child_settings.str # => "default"
235
- # root_settings.str = "value_from_root"
236
- # child_settings.str # => "value_from_root"
237
- # child_settings.str = "value_from_child"
238
- # child_settings.str # => "value_from_child"
239
- # child_settings.str_unset!
240
- # child_settings.str # => "value_from_root"
241
- # root_settings.str_unset!
242
- # child_settings.str # => "default"
243
- #
244
- # Parents are honored through groups as well. For example:
245
- #
246
- # class MySettings < Toys::Settings
247
- # settings_group :flags do
248
- # settings_attr :verbose, default: false
249
- # settings_attr :force, default: false
250
- # end
251
- # end
252
- #
253
- # root_settings = MySettings.new
254
- # child_settings = MySettings.new(root_settings)
255
- # child_settings.flags.verbose # => false
256
- # root_settings.flags.verbose = true
257
- # child_settings.flags.verbose # => true
258
- #
259
- # Usually, a settings and its parent (and its parent, and so forth) should
260
- # have the same class. This guarantees that they define the same fields with
261
- # the same type specifications. However, this is not required. If a parent
262
- # does not define a particular field, it is treated as if that field is
263
- # unset, and lookup proceeds to its parent. To illustrate:
264
- #
265
- # class Settings1 < Toys::Settings
266
- # settings_attr :str, default: "default"
267
- # end
268
- # class Settings2 < Toys::Settings
269
- # end
270
- #
271
- # root_settings = Settings1.new
272
- # child_settings = Settings2.new(root_settings) # does not have str
273
- # grandchild_settings = Settings1.new(child_settings)
274
- #
275
- # grandchild_settings.str # => "default"
276
- # root_settings.str = "value_from_root"
277
- # grandchild_settings.str # => "value_from_root"
278
- #
279
- # Type specifications are enforced when falling back to parent values. If a
280
- # parent provides a value that is not allowed, it is treated as if the field
281
- # is unset, and lookup proceeds to its parent.
282
- #
283
- # class Settings1 < Toys::Settings
284
- # settings_attr :str, default: "default" # type spec is String
285
- # end
286
- # class Settings2 < Toys::Settings
287
- # settings_attr :str, default: 0 # type spec is Integer
288
- # end
289
- #
290
- # root_settings = Settings1.new
291
- # child_settings = Settings2.new(root_settings)
292
- # grandchild_settings = Settings1.new(child_settings)
293
- #
294
- # grandchild_settings.str # => "default"
295
- # child_settings.str = 123 # does not match grandchild's type
296
- # root_settings.str = "value_from_root"
297
- # grandchild_settings.str # => "value_from_root"
298
- #
299
- class Settings
300
- # A special value indicating a type check failure.
301
- ILLEGAL_VALUE = ::Object.new.freeze
302
-
303
- # A special type specification indicating infer from the default value.
304
- DEFAULT_TYPE = ::Object.new.freeze
305
-
306
- ##
307
- # **_Defined in the toys-core gem_**
308
- #
309
- # Error raised when a value does not match the type constraint.
310
- #
311
- class FieldError < ::StandardError
312
- ##
313
- # The value that did not match
314
- # @return [Object]
315
- #
316
- attr_reader :value
317
-
318
- ##
319
- # The settings class that rejected the value
320
- # @return [Class]
321
- #
322
- attr_reader :settings_class
323
-
324
- ##
325
- # The field that rejected the value
326
- # @return [Symbol]
327
- #
328
- attr_reader :field_name
329
-
330
- ##
331
- # A description of the type constraint, or nil if the field didn't exist.
332
- # @return [String, nil]
333
- #
334
- attr_reader :type_description
335
-
336
- ##
337
- # @private This interface is internal and subject to change without warning.
338
- #
339
- def initialize(value, settings_class, field_name, type_description)
340
- # Source available in the toys-core gem
341
- end
342
- end
343
-
344
- ##
345
- # **_Defined in the toys-core gem_**
346
- #
347
- # A type object that checks values.
348
- #
349
- # A Type includes a description string and a testing function. The testing
350
- # function takes a proposed value and returns either the value itself if it
351
- # is valid, a converted value if the value can be converted to a valid
352
- # value, or {ILLEGAL_VALUE} if the type check failed.
353
- #
354
- class Type
355
- ##
356
- # Create a new Type.
357
- #
358
- # @param description [String] Name of the type.
359
- # @param block [Proc] A testing function.
360
- #
361
- def initialize(description, &block)
362
- # Source available in the toys-core gem
363
- end
364
-
365
- ##
366
- # The name of the type.
367
- # @return [String]
368
- #
369
- attr_reader :description
370
-
371
- ##
372
- # Test a value, possibly converting to a legal value.
373
- #
374
- # @param val [Object] The value to be tested.
375
- # @return [Object] The validated value, the value converted to a legal
376
- # value, or {ILLEGAL_VALUE} if the type check is unsuccessful.
377
- #
378
- def call(val)
379
- # Source available in the toys-core gem
380
- end
381
-
382
- class << self
383
- ##
384
- # Create and return a Type given a type specification. See the
385
- # {Settings} class documentation for valid type specifications.
386
- #
387
- # @param type_spec [Object]
388
- # @return [Type]
389
- # @raise [ArgumentError] if the type specification is invalid.
390
- #
391
- def for_type_spec(type_spec)
392
- # Source available in the toys-core gem
393
- end
394
-
395
- ##
396
- # Create and return a Type given a default value. See the {Settings}
397
- # class documentation for the rules.
398
- #
399
- # @param value [Object]
400
- # @return [Type]
401
- #
402
- def for_default_value(value)
403
- # Source available in the toys-core gem
404
- end
405
- end
406
- end
407
-
408
- ##
409
- # Create a settings instance.
410
- #
411
- # @param parent [Settings,nil] Optional parent settings.
412
- #
413
- def initialize(parent: nil)
414
- # Source available in the toys-core gem
415
- end
416
-
417
- ##
418
- # Load the given hash of data into this settings object.
419
- #
420
- # @param data [Hash] The data as a hash of key-value pairs.
421
- # @param raise_on_failure [boolean] If `true`, raises an exception on the
422
- # first error encountered. If `false`, continues parsing and returns an
423
- # array of the errors raised.
424
- # @return [Array<FieldError>] An array of errors.
425
- #
426
- def load_data!(data, raise_on_failure: false)
427
- # Source available in the toys-core gem
428
- end
429
-
430
- ##
431
- # Parse the given YAML string and load the data into this settings object.
432
- #
433
- # @param str [String] The YAML-formatted string.
434
- # @param raise_on_failure [boolean] If `true`, raises an exception on the
435
- # first error encountered. If `false`, continues parsing and returns an
436
- # array of the errors raised.
437
- # @return [Array<FieldError>] An array of errors.
438
- #
439
- def load_yaml!(str, raise_on_failure: false)
440
- # Source available in the toys-core gem
441
- end
442
-
443
- ##
444
- # Parse the given YAML file and load the data into this settings object.
445
- #
446
- # @param filename [String] The path to the YAML-formatted file.
447
- # @param raise_on_failure [boolean] If `true`, raises an exception on the
448
- # first error encountered. If `false`, continues parsing and returns an
449
- # array of the errors raised.
450
- # @return [Array<FieldError>] An array of errors.
451
- #
452
- def load_yaml_file!(filename, raise_on_failure: false)
453
- # Source available in the toys-core gem
454
- end
455
-
456
- ##
457
- # Parse the given JSON string and load the data into this settings object.
458
- #
459
- # @param str [String] The JSON-formatted string.
460
- # @param raise_on_failure [boolean] If `true`, raises an exception on the
461
- # first error encountered. If `false`, continues parsing and returns an
462
- # array of the errors raised.
463
- # @return [Array<FieldError>] An array of errors.
464
- #
465
- def load_json!(str, raise_on_failure: false, **json_opts)
466
- # Source available in the toys-core gem
467
- end
468
-
469
- ##
470
- # Parse the given JSON file and load the data into this settings object.
471
- #
472
- # @param filename [String] The path to the JSON-formatted file.
473
- # @param raise_on_failure [boolean] If `true`, raises an exception on the
474
- # first error encountered. If `false`, continues parsing and returns an
475
- # array of the errors raised.
476
- # @return [Array<FieldError>] An array of errors.
477
- #
478
- def load_json_file!(filename, raise_on_failure: false, **json_opts)
479
- # Source available in the toys-core gem
480
- end
481
-
482
- class << self
483
- ##
484
- # Add an attribute field.
485
- #
486
- # @param name [Symbol,String] The name of the attribute.
487
- # @param default [Object] Optional. The final default value if the field
488
- # is not set in this settings object or any of its ancestors. If not
489
- # provided, `nil` is used.
490
- # @param type [Object] Optional. The type specification. If not provided,
491
- # one is inferred from the default value.
492
- #
493
- def settings_attr(name, default: nil, type: DEFAULT_TYPE, &block)
494
- # Source available in the toys-core gem
495
- end
496
-
497
- ##
498
- # Add a group field.
499
- #
500
- # Specify the group's structure by passing either a class (which must
501
- # subclass Settings) or a block (which will be called on the group's
502
- # class.)
503
- #
504
- # @param name [Symbol, String] The name of the group.
505
- # @param klass [Class] Optional. The class of the group (which must
506
- # subclass Settings). If not present, an anonymous subclass will be
507
- # created, and you must provide a block to configure it.
508
- #
509
- def settings_group(name, klass = nil, &block)
510
- # Source available in the toys-core gem
511
- end
512
-
513
- ##
514
- # @private This interface is internal and subject to change without warning.
515
- #
516
- # Returns the fields hash. This is shared between the settings class and
517
- # all its instances.
518
- #
519
- def fields
520
- # Source available in the toys-core gem
521
- end
522
- end
523
- end
524
- end