toys 0.12.1 → 0.13.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.yardopts +2 -0
- data/CHANGELOG.md +44 -0
- data/LICENSE.md +1 -1
- data/README.md +7 -4
- data/builtins/system/git-cache.rb +238 -0
- data/builtins/system/test.rb +37 -2
- data/core-docs/toys/acceptor.rb +432 -0
- data/core-docs/toys/arg_parser.rb +397 -0
- data/core-docs/toys/cli.rb +493 -0
- data/core-docs/toys/compat.rb +2 -0
- data/core-docs/toys/completion.rb +329 -0
- data/core-docs/toys/context.rb +321 -0
- data/core-docs/toys/core.rb +14 -0
- data/core-docs/toys/dsl/base.rb +56 -0
- data/core-docs/toys/dsl/flag.rb +261 -0
- data/core-docs/toys/dsl/flag_group.rb +259 -0
- data/core-docs/toys/dsl/internal.rb +4 -0
- data/core-docs/toys/dsl/positional_arg.rb +139 -0
- data/core-docs/toys/dsl/tool.rb +1530 -0
- data/core-docs/toys/errors.rb +93 -0
- data/core-docs/toys/flag.rb +549 -0
- data/core-docs/toys/flag_group.rb +186 -0
- data/core-docs/toys/input_file.rb +8 -0
- data/core-docs/toys/loader.rb +222 -0
- data/core-docs/toys/middleware.rb +295 -0
- data/core-docs/toys/mixin.rb +142 -0
- data/core-docs/toys/module_lookup.rb +75 -0
- data/core-docs/toys/positional_arg.rb +145 -0
- data/core-docs/toys/settings.rb +507 -0
- data/core-docs/toys/source_info.rb +127 -0
- data/core-docs/toys/standard_middleware/add_verbosity_flags.rb +49 -0
- data/core-docs/toys/standard_middleware/apply_config.rb +24 -0
- data/core-docs/toys/standard_middleware/handle_usage_errors.rb +33 -0
- data/core-docs/toys/standard_middleware/set_default_descriptions.rb +222 -0
- data/core-docs/toys/standard_middleware/show_help.rb +190 -0
- data/core-docs/toys/standard_middleware/show_root_version.rb +45 -0
- data/core-docs/toys/standard_mixins/bundler.rb +83 -0
- data/core-docs/toys/standard_mixins/exec.rb +645 -0
- data/core-docs/toys/standard_mixins/fileutils.rb +18 -0
- data/core-docs/toys/standard_mixins/gems.rb +48 -0
- data/core-docs/toys/standard_mixins/git_cache.rb +41 -0
- data/core-docs/toys/standard_mixins/highline.rb +133 -0
- data/core-docs/toys/standard_mixins/terminal.rb +135 -0
- data/core-docs/toys/standard_mixins/xdg.rb +49 -0
- data/core-docs/toys/template.rb +112 -0
- data/core-docs/toys/tool_definition.rb +926 -0
- data/core-docs/toys/utils/completion_engine.rb +49 -0
- data/core-docs/toys/utils/exec.rb +721 -0
- data/core-docs/toys/utils/gems.rb +185 -0
- data/core-docs/toys/utils/git_cache.rb +353 -0
- data/core-docs/toys/utils/help_text.rb +134 -0
- data/core-docs/toys/utils/terminal.rb +310 -0
- data/core-docs/toys/utils/xdg.rb +253 -0
- data/core-docs/toys/wrappable_string.rb +120 -0
- data/core-docs/toys-core.rb +63 -0
- data/docs/guide.md +497 -156
- data/lib/toys/standard_cli.rb +50 -36
- data/lib/toys/templates/clean.rb +18 -0
- data/lib/toys/templates/gem_build.rb +24 -0
- data/lib/toys/templates/minitest.rb +21 -0
- data/lib/toys/templates/rake.rb +23 -3
- data/lib/toys/templates/rdoc.rb +29 -0
- data/lib/toys/templates/rspec.rb +32 -4
- data/lib/toys/templates/rubocop.rb +14 -1
- data/lib/toys/templates/yardoc.rb +55 -0
- data/lib/toys/testing.rb +186 -109
- data/lib/toys/version.rb +1 -1
- data/lib/toys.rb +4 -2
- metadata +56 -6
@@ -0,0 +1,507 @@
|
|
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 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
|
+
end
|
336
|
+
|
337
|
+
##
|
338
|
+
# **_Defined in the toys-core gem_**
|
339
|
+
#
|
340
|
+
# A type object that checks values.
|
341
|
+
#
|
342
|
+
# A Type includes a description string and a testing function. The testing
|
343
|
+
# function takes a proposed value and returns either the value itself if it
|
344
|
+
# is valid, a converted value if the value can be converted to a valid
|
345
|
+
# value, or {ILLEGAL_VALUE} if the type check failed.
|
346
|
+
#
|
347
|
+
class Type
|
348
|
+
##
|
349
|
+
# Create a new Type.
|
350
|
+
#
|
351
|
+
# @param description [String] Name of the type.
|
352
|
+
# @param block [Proc] A testing function.
|
353
|
+
#
|
354
|
+
def initialize(description, &block)
|
355
|
+
# Source available in the toys-core gem
|
356
|
+
end
|
357
|
+
|
358
|
+
##
|
359
|
+
# The name of the type.
|
360
|
+
# @return [String]
|
361
|
+
#
|
362
|
+
attr_reader :description
|
363
|
+
|
364
|
+
##
|
365
|
+
# Test a value, possibly converting to a legal value.
|
366
|
+
#
|
367
|
+
# @param val [Object] The value to be tested.
|
368
|
+
# @return [Object] The validated value, the value converted to a legal
|
369
|
+
# value, or {ILLEGAL_VALUE} if the type check is unsuccessful.
|
370
|
+
#
|
371
|
+
def call(val)
|
372
|
+
# Source available in the toys-core gem
|
373
|
+
end
|
374
|
+
|
375
|
+
class << self
|
376
|
+
##
|
377
|
+
# Create and return a Type given a type specification. See the
|
378
|
+
# {Settings} class documentation for valid type specifications.
|
379
|
+
#
|
380
|
+
# @param type_spec [Object]
|
381
|
+
# @return [Type]
|
382
|
+
# @raise [ArgumentError] if the type specification is invalid.
|
383
|
+
#
|
384
|
+
def for_type_spec(type_spec)
|
385
|
+
# Source available in the toys-core gem
|
386
|
+
end
|
387
|
+
|
388
|
+
##
|
389
|
+
# Create and return a Type given a default value. See the {Settings}
|
390
|
+
# class documentation for the rules.
|
391
|
+
#
|
392
|
+
# @param value [Object]
|
393
|
+
# @return [Type]
|
394
|
+
#
|
395
|
+
def for_default_value(value)
|
396
|
+
# Source available in the toys-core gem
|
397
|
+
end
|
398
|
+
end
|
399
|
+
end
|
400
|
+
|
401
|
+
##
|
402
|
+
# Create a settings instance.
|
403
|
+
#
|
404
|
+
# @param parent [Settings,nil] Optional parent settings.
|
405
|
+
#
|
406
|
+
def initialize(parent: nil)
|
407
|
+
# Source available in the toys-core gem
|
408
|
+
end
|
409
|
+
|
410
|
+
##
|
411
|
+
# Load the given hash of data into this settings object.
|
412
|
+
#
|
413
|
+
# @param data [Hash] The data as a hash of key-value pairs.
|
414
|
+
# @param raise_on_failure [boolean] If `true`, raises an exception on the
|
415
|
+
# first error encountered. If `false`, continues parsing and returns an
|
416
|
+
# array of the errors raised.
|
417
|
+
# @return [Array<FieldError>] An array of errors.
|
418
|
+
#
|
419
|
+
def load_data!(data, raise_on_failure: false)
|
420
|
+
# Source available in the toys-core gem
|
421
|
+
end
|
422
|
+
|
423
|
+
##
|
424
|
+
# Parse the given YAML string and load the data into this settings object.
|
425
|
+
#
|
426
|
+
# @param str [String] The YAML-formatted string.
|
427
|
+
# @param raise_on_failure [boolean] If `true`, raises an exception on the
|
428
|
+
# first error encountered. If `false`, continues parsing and returns an
|
429
|
+
# array of the errors raised.
|
430
|
+
# @return [Array<FieldError>] An array of errors.
|
431
|
+
#
|
432
|
+
def load_yaml!(str, raise_on_failure: false)
|
433
|
+
# Source available in the toys-core gem
|
434
|
+
end
|
435
|
+
|
436
|
+
##
|
437
|
+
# Parse the given YAML file and load the data into this settings object.
|
438
|
+
#
|
439
|
+
# @param filename [String] The path to the YAML-formatted file.
|
440
|
+
# @param raise_on_failure [boolean] If `true`, raises an exception on the
|
441
|
+
# first error encountered. If `false`, continues parsing and returns an
|
442
|
+
# array of the errors raised.
|
443
|
+
# @return [Array<FieldError>] An array of errors.
|
444
|
+
#
|
445
|
+
def load_yaml_file!(filename, raise_on_failure: false)
|
446
|
+
# Source available in the toys-core gem
|
447
|
+
end
|
448
|
+
|
449
|
+
##
|
450
|
+
# Parse the given JSON string and load the data into this settings object.
|
451
|
+
#
|
452
|
+
# @param str [String] The JSON-formatted string.
|
453
|
+
# @param raise_on_failure [boolean] If `true`, raises an exception on the
|
454
|
+
# first error encountered. If `false`, continues parsing and returns an
|
455
|
+
# array of the errors raised.
|
456
|
+
# @return [Array<FieldError>] An array of errors.
|
457
|
+
#
|
458
|
+
def load_json!(str, raise_on_failure: false, **json_opts)
|
459
|
+
# Source available in the toys-core gem
|
460
|
+
end
|
461
|
+
|
462
|
+
##
|
463
|
+
# Parse the given JSON file and load the data into this settings object.
|
464
|
+
#
|
465
|
+
# @param filename [String] The path to the JSON-formatted file.
|
466
|
+
# @param raise_on_failure [boolean] If `true`, raises an exception on the
|
467
|
+
# first error encountered. If `false`, continues parsing and returns an
|
468
|
+
# array of the errors raised.
|
469
|
+
# @return [Array<FieldError>] An array of errors.
|
470
|
+
#
|
471
|
+
def load_json_file!(filename, raise_on_failure: false, **json_opts)
|
472
|
+
# Source available in the toys-core gem
|
473
|
+
end
|
474
|
+
|
475
|
+
class << self
|
476
|
+
##
|
477
|
+
# Add an attribute field.
|
478
|
+
#
|
479
|
+
# @param name [Symbol,String] The name of the attribute.
|
480
|
+
# @param default [Object] Optional. The final default value if the field
|
481
|
+
# is not set in this settings object or any of its ancestors. If not
|
482
|
+
# provided, `nil` is used.
|
483
|
+
# @param type [Object] Optional. The type specification. If not provided,
|
484
|
+
# one is inferred from the default value.
|
485
|
+
#
|
486
|
+
def settings_attr(name, default: nil, type: DEFAULT_TYPE, &block)
|
487
|
+
# Source available in the toys-core gem
|
488
|
+
end
|
489
|
+
|
490
|
+
##
|
491
|
+
# Add a group field.
|
492
|
+
#
|
493
|
+
# Specify the group's structure by passing either a class (which must
|
494
|
+
# subclass Settings) or a block (which will be called on the group's
|
495
|
+
# class.)
|
496
|
+
#
|
497
|
+
# @param name [Symbol, String] The name of the group.
|
498
|
+
# @param klass [Class] Optional. The class of the group (which must
|
499
|
+
# subclass Settings). If not present, an anonymous subclass will be
|
500
|
+
# created, and you must provide a block to configure it.
|
501
|
+
#
|
502
|
+
def settings_group(name, klass = nil, &block)
|
503
|
+
# Source available in the toys-core gem
|
504
|
+
end
|
505
|
+
end
|
506
|
+
end
|
507
|
+
end
|
@@ -0,0 +1,127 @@
|
|
1
|
+
module Toys
|
2
|
+
##
|
3
|
+
# **_Defined in the toys-core gem_**
|
4
|
+
#
|
5
|
+
# Information about the source of a tool, such as the file, git repository,
|
6
|
+
# or block that defined it.
|
7
|
+
#
|
8
|
+
class SourceInfo
|
9
|
+
##
|
10
|
+
# The parent of this SourceInfo.
|
11
|
+
#
|
12
|
+
# @return [Toys::SourceInfo] The parent.
|
13
|
+
# @return [nil] if this SourceInfo is the root.
|
14
|
+
#
|
15
|
+
attr_reader :parent
|
16
|
+
|
17
|
+
##
|
18
|
+
# The root ancestor of this SourceInfo.
|
19
|
+
#
|
20
|
+
# @return [Toys::SourceInfo] The root ancestor.
|
21
|
+
#
|
22
|
+
attr_reader :root
|
23
|
+
|
24
|
+
##
|
25
|
+
# The priority of tools defined by this source. Higher values indicate a
|
26
|
+
# higher priority. Lower priority values could be negative.
|
27
|
+
#
|
28
|
+
# @return [Integer] The priority.
|
29
|
+
#
|
30
|
+
attr_reader :priority
|
31
|
+
|
32
|
+
##
|
33
|
+
# The context directory path (normally the directory containing the
|
34
|
+
# toplevel toys file or directory).
|
35
|
+
#
|
36
|
+
# @return [String] The context directory path.
|
37
|
+
# @return [nil] if there is no context directory (perhaps because the tool
|
38
|
+
# is being defined from a block)
|
39
|
+
#
|
40
|
+
attr_reader :context_directory
|
41
|
+
|
42
|
+
##
|
43
|
+
# The source, which may be a path or a proc.
|
44
|
+
#
|
45
|
+
# @return [String] Path to the source file or directory.
|
46
|
+
# @return [Proc] The block serving as the source.
|
47
|
+
#
|
48
|
+
attr_reader :source
|
49
|
+
|
50
|
+
##
|
51
|
+
# Return the type of source.
|
52
|
+
#
|
53
|
+
# @return [:file,:directory,:proc]
|
54
|
+
#
|
55
|
+
attr_reader :source_type
|
56
|
+
|
57
|
+
##
|
58
|
+
# The path of the current source file or directory.
|
59
|
+
#
|
60
|
+
# @return [String] The source path
|
61
|
+
# @return [nil] if this source has no file system path.
|
62
|
+
#
|
63
|
+
attr_reader :source_path
|
64
|
+
|
65
|
+
##
|
66
|
+
# The source proc.
|
67
|
+
#
|
68
|
+
# @return [Proc] The source proc
|
69
|
+
# @return [nil] if this source has no proc.
|
70
|
+
#
|
71
|
+
attr_reader :source_proc
|
72
|
+
|
73
|
+
##
|
74
|
+
# The git remote.
|
75
|
+
#
|
76
|
+
# @return [String] The git remote
|
77
|
+
# @return [nil] if this source is not fron git.
|
78
|
+
#
|
79
|
+
attr_reader :git_remote
|
80
|
+
|
81
|
+
##
|
82
|
+
# The git path.
|
83
|
+
#
|
84
|
+
# @return [String] The git path. This could be the empty string.
|
85
|
+
# @return [nil] if this source is not fron git.
|
86
|
+
#
|
87
|
+
attr_reader :git_path
|
88
|
+
|
89
|
+
##
|
90
|
+
# The git commit.
|
91
|
+
#
|
92
|
+
# @return [String] The git commit.
|
93
|
+
# @return [nil] if this source is not fron git.
|
94
|
+
#
|
95
|
+
attr_reader :git_commit
|
96
|
+
|
97
|
+
##
|
98
|
+
# The user-visible name of this source.
|
99
|
+
#
|
100
|
+
# @return [String]
|
101
|
+
#
|
102
|
+
attr_reader :source_name
|
103
|
+
alias to_s source_name
|
104
|
+
|
105
|
+
##
|
106
|
+
# Locate the given data file or directory and return an absolute path.
|
107
|
+
#
|
108
|
+
# @param path [String] The relative path to find
|
109
|
+
# @param type [nil,:file,:directory] Type of file system object to find,
|
110
|
+
# or nil (the default) to return any type.
|
111
|
+
# @return [String] Absolute path of the resulting data.
|
112
|
+
# @return [nil] if the data was not found.
|
113
|
+
#
|
114
|
+
def find_data(path, type: nil)
|
115
|
+
# Source available in the toys-core gem
|
116
|
+
end
|
117
|
+
|
118
|
+
##
|
119
|
+
# Apply all lib paths in order from high to low priority
|
120
|
+
#
|
121
|
+
# @return [self]
|
122
|
+
#
|
123
|
+
def apply_lib_paths
|
124
|
+
# Source available in the toys-core gem
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module Toys
|
2
|
+
module StandardMiddleware
|
3
|
+
##
|
4
|
+
# **_Defined in the toys-core gem_**
|
5
|
+
#
|
6
|
+
# A middleware that provides flags for editing the verbosity.
|
7
|
+
#
|
8
|
+
# This middleware adds `-v`, `--verbose`, `-q`, and `--quiet` flags, if
|
9
|
+
# not already defined by the tool. These flags affect the setting of
|
10
|
+
# {Toys::Context::Key::VERBOSITY}, and, thus, the logger level.
|
11
|
+
#
|
12
|
+
class AddVerbosityFlags
|
13
|
+
##
|
14
|
+
# Default verbose flags
|
15
|
+
# @return [Array<String>]
|
16
|
+
#
|
17
|
+
DEFAULT_VERBOSE_FLAGS = ["-v", "--verbose"].freeze
|
18
|
+
|
19
|
+
##
|
20
|
+
# Default quiet flags
|
21
|
+
# @return [Array<String>]
|
22
|
+
#
|
23
|
+
DEFAULT_QUIET_FLAGS = ["-q", "--quiet"].freeze
|
24
|
+
|
25
|
+
##
|
26
|
+
# Create a AddVerbosityFlags middleware.
|
27
|
+
#
|
28
|
+
# @param verbose_flags [Boolean,Array<String>,Proc] Specify flags
|
29
|
+
# to increase verbosity. The value may be any of the following:
|
30
|
+
#
|
31
|
+
# * An array of flags that increase verbosity.
|
32
|
+
# * The `true` value to use {DEFAULT_VERBOSE_FLAGS}. (Default)
|
33
|
+
# * The `false` value to disable verbose flags.
|
34
|
+
# * A proc that takes a tool and returns any of the above.
|
35
|
+
#
|
36
|
+
# @param quiet_flags [Boolean,Array<String>,Proc] Specify flags
|
37
|
+
# to decrease verbosity. The value may be any of the following:
|
38
|
+
#
|
39
|
+
# * An array of flags that decrease verbosity.
|
40
|
+
# * The `true` value to use {DEFAULT_QUIET_FLAGS}. (Default)
|
41
|
+
# * The `false` value to disable quiet flags.
|
42
|
+
# * A proc that takes a tool and returns any of the above.
|
43
|
+
#
|
44
|
+
def initialize(verbose_flags: true, quiet_flags: true)
|
45
|
+
# Source available in the toys-core gem
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Toys
|
2
|
+
module StandardMiddleware
|
3
|
+
##
|
4
|
+
# **_Defined in the toys-core gem_**
|
5
|
+
#
|
6
|
+
# A middleware that applies the given block to all tool configurations.
|
7
|
+
#
|
8
|
+
class ApplyConfig
|
9
|
+
##
|
10
|
+
# Create an ApplyConfig middleware
|
11
|
+
#
|
12
|
+
# @param parent_source [Toys::SourceInfo] The SourceInfo corresponding to
|
13
|
+
# the source where this block is provided, or `nil` (the default) if
|
14
|
+
# the block does not come from a Toys file.
|
15
|
+
# @param source_name [String] A user-visible name for the source, or
|
16
|
+
# `nil` to use the default.
|
17
|
+
# @param block [Proc] The configuration to apply.
|
18
|
+
#
|
19
|
+
def initialize(parent_source: nil, source_name: nil, &block)
|
20
|
+
# Source available in the toys-core gem
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|