toys 0.12.2 → 0.13.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.
- checksums.yaml +4 -4
- data/.yardopts +2 -0
- data/CHANGELOG.md +35 -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,295 @@
|
|
1
|
+
module Toys
|
2
|
+
##
|
3
|
+
# **_Defined in the toys-core gem_**
|
4
|
+
#
|
5
|
+
# A middleware is an object that has the opportunity to alter the
|
6
|
+
# configuration and runtime behavior of each tool in a Toys CLI. A CLI
|
7
|
+
# contains an ordered list of middleware, known as the *middleware stack*,
|
8
|
+
# that together define the CLI's default behavior.
|
9
|
+
#
|
10
|
+
# Specifically, a middleware can perform two functions.
|
11
|
+
#
|
12
|
+
# First, it can modify the configuration of a tool. After tools are defined
|
13
|
+
# from configuration, the middleware stack can make modifications to each
|
14
|
+
# tool. A middleware can add flags and arguments to the tool, modify the
|
15
|
+
# description, or make any other changes to how the tool is set up.
|
16
|
+
#
|
17
|
+
# Second, a middleware can intercept and change tool execution. Like a Rack
|
18
|
+
# middleware, a Toys middleware can wrap execution with its own code,
|
19
|
+
# replace it outright, or leave it unmodified.
|
20
|
+
#
|
21
|
+
# Generally, a middleware is a class that implements one or more of the
|
22
|
+
# methods defined in this module: {Toys::Middleware#config}, and
|
23
|
+
# {Toys::Middleware#run}. This module provides default implementations that
|
24
|
+
# do nothing, but using them is not required. Middleware objects need respond
|
25
|
+
# only to methods they care about.
|
26
|
+
#
|
27
|
+
module Middleware
|
28
|
+
##
|
29
|
+
# This method is called *after* a tool has been defined, and gives this
|
30
|
+
# middleware the opportunity to modify the tool definition. It is passed
|
31
|
+
# the tool definition object and the loader, and can make any changes to
|
32
|
+
# the tool definition. In most cases, this method should also call
|
33
|
+
# `yield`, which passes control to the next middleware in the stack. A
|
34
|
+
# middleware can disable modifications done by subsequent middleware by
|
35
|
+
# omitting the `yield` call, but this is uncommon.
|
36
|
+
#
|
37
|
+
# This basic implementation does nothing and simply yields to the next
|
38
|
+
# middleware.
|
39
|
+
#
|
40
|
+
# @param tool [Toys::ToolDefinition] The tool definition to modify.
|
41
|
+
# @param loader [Toys::Loader] The loader that loaded this tool.
|
42
|
+
# @return [void]
|
43
|
+
#
|
44
|
+
def config(tool, loader)
|
45
|
+
# Source available in the toys-core gem
|
46
|
+
end
|
47
|
+
|
48
|
+
##
|
49
|
+
# This method is called when the tool is run. It gives the middleware an
|
50
|
+
# opportunity to modify the runtime behavior of the tool. It is passed
|
51
|
+
# the tool instance (i.e. the object that hosts a tool's `run` method),
|
52
|
+
# and you can use this object to access the tool's options and other
|
53
|
+
# context data. In most cases, this method should also call `yield`,
|
54
|
+
# which passes control to the next middleware in the stack. A middleware
|
55
|
+
# can "wrap" normal execution by calling `yield` somewhere in its
|
56
|
+
# implementation of this method, or it can completely replace the
|
57
|
+
# execution behavior by not calling `yield` at all.
|
58
|
+
#
|
59
|
+
# Like a tool's `run` method, this method's return value is unused. If
|
60
|
+
# you want to output from a tool, write to stdout or stderr. If you want
|
61
|
+
# to set the exit status code, call {Toys::Context#exit} on the context.
|
62
|
+
#
|
63
|
+
# This basic implementation does nothing and simply yields to the next
|
64
|
+
# middleware.
|
65
|
+
#
|
66
|
+
# @param context [Toys::Context] The tool execution context.
|
67
|
+
# @return [void]
|
68
|
+
#
|
69
|
+
def run(context)
|
70
|
+
# Source available in the toys-core gem
|
71
|
+
end
|
72
|
+
|
73
|
+
class << self
|
74
|
+
##
|
75
|
+
# Create a middleware spec.
|
76
|
+
#
|
77
|
+
# @overload spec(name, *args, **kwargs, &block)
|
78
|
+
# Create a spec indicating a given middleware name should be
|
79
|
+
# instantiated with the given arguments.
|
80
|
+
#
|
81
|
+
# @param name [String,Symbol,Class] The middleware name or class
|
82
|
+
# @param args [Array] The arguments to pass to the constructor
|
83
|
+
# @param kwargs [Hash] The keyword arguments to pass to the constructor
|
84
|
+
# @param block [Proc,nil] The block to pass to the constructor
|
85
|
+
# @return [Toys::Middleware::Spec] A spec
|
86
|
+
#
|
87
|
+
# @overload spec(array)
|
88
|
+
# Create a middleware spec from an array specification.
|
89
|
+
#
|
90
|
+
# The array must be 1-4 elements long. The first element must be the
|
91
|
+
# middleware name or class. The other three arguments may include any
|
92
|
+
# or all of the following optional elements, in any order:
|
93
|
+
# * An array for the positional arguments to pass to the constructor
|
94
|
+
# * A hash for the keyword arguments to pass to the constructor
|
95
|
+
# * A proc for the block to pass to the constructor
|
96
|
+
#
|
97
|
+
# @param array [Array] The array input
|
98
|
+
# @return [Toys::Middleware::Spec] A spec
|
99
|
+
#
|
100
|
+
# @overload spec(middleware_object)
|
101
|
+
# Create a spec wrapping an existing middleware object
|
102
|
+
#
|
103
|
+
# @param middleware_object [Toys::Middleware] The middleware object
|
104
|
+
# @return [Toys::Middleware::Spec] A spec
|
105
|
+
#
|
106
|
+
def spec(middleware, *args, **kwargs, &block)
|
107
|
+
# Source available in the toys-core gem
|
108
|
+
end
|
109
|
+
|
110
|
+
##
|
111
|
+
# Create a {Toys::Middleware::Stack} from an array of middleware specs.
|
112
|
+
# Each element may be one of the following:
|
113
|
+
#
|
114
|
+
# * A {Toys::Middleware} object
|
115
|
+
# * A {Toys::Middleware::Spec}
|
116
|
+
# * An array whose first element is a middleware name or class, and the
|
117
|
+
# subsequent elements are params that define what to pass to the class
|
118
|
+
# constructor (see {Toys::Middleware.spec})
|
119
|
+
#
|
120
|
+
# @param input [Array<Toys::Middleware,Toys::Middleware::Spec,Array>]
|
121
|
+
# @return [Toys::Middleware::Stack]
|
122
|
+
#
|
123
|
+
def stack(input)
|
124
|
+
# Source available in the toys-core gem
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
##
|
129
|
+
# **_Defined in the toys-core gem_**
|
130
|
+
#
|
131
|
+
# A base class that provides default NOP implementations of the middleware
|
132
|
+
# interface. This base class may optionally be subclassed by a middleware
|
133
|
+
# implementation.
|
134
|
+
#
|
135
|
+
class Base
|
136
|
+
include Middleware
|
137
|
+
end
|
138
|
+
|
139
|
+
##
|
140
|
+
# **_Defined in the toys-core gem_**
|
141
|
+
#
|
142
|
+
# A middleware specification, including the middleware class and the
|
143
|
+
# arguments to pass to the constructor.
|
144
|
+
#
|
145
|
+
# Use {Toys::Middleware.spec} to create a middleware spec.
|
146
|
+
#
|
147
|
+
class Spec
|
148
|
+
##
|
149
|
+
# Builds a middleware for this spec, given a ModuleLookup for middleware.
|
150
|
+
#
|
151
|
+
# If this spec wraps an existing middleware object, returns that object.
|
152
|
+
# Otherwise, constructs a middleware object from the spec.
|
153
|
+
#
|
154
|
+
# @param lookup [Toys::ModuleLookup] A module lookup to resolve
|
155
|
+
# middleware names
|
156
|
+
# @return [Toys::Middleware] The middleware
|
157
|
+
#
|
158
|
+
def build(lookup)
|
159
|
+
# Source available in the toys-core gem
|
160
|
+
end
|
161
|
+
|
162
|
+
##
|
163
|
+
# @return [Toys::Middleware] if this spec wraps a middleware object
|
164
|
+
# @return [nil] if this spec represents a class to instantiate
|
165
|
+
#
|
166
|
+
attr_reader :object
|
167
|
+
|
168
|
+
##
|
169
|
+
# @return [String,Symbol] if this spec represents a middleware name
|
170
|
+
# @return [Class] if this spec represents a middleware class
|
171
|
+
# @return [nil] if this spec wraps a middleware object
|
172
|
+
#
|
173
|
+
attr_reader :name
|
174
|
+
|
175
|
+
##
|
176
|
+
# @return [Array] the positional arguments to be passed to a middleware
|
177
|
+
# class constructor, or the empty array if there are no positional
|
178
|
+
# arguments
|
179
|
+
# @return [nil] if this spec wraps a middleware object
|
180
|
+
#
|
181
|
+
attr_reader :args
|
182
|
+
|
183
|
+
##
|
184
|
+
# @return [Hash] the keyword arguments to be passed to a middleware class
|
185
|
+
# constructor, or the empty hash if there are no keyword arguments
|
186
|
+
# @return [nil] if this spec wraps a middleware object
|
187
|
+
#
|
188
|
+
attr_reader :kwargs
|
189
|
+
|
190
|
+
##
|
191
|
+
# @return [Proc] if there is a block argument to be passed to a
|
192
|
+
# middleware class constructor
|
193
|
+
# @return [nil] if there is no block argument, or this spec wraps a
|
194
|
+
# middleware object
|
195
|
+
#
|
196
|
+
attr_reader :block
|
197
|
+
|
198
|
+
##
|
199
|
+
# Equality check
|
200
|
+
#
|
201
|
+
# @param other [Object]
|
202
|
+
# @return [Boolean]
|
203
|
+
#
|
204
|
+
def ==(other)
|
205
|
+
# Source available in the toys-core gem
|
206
|
+
end
|
207
|
+
alias eql? ==
|
208
|
+
|
209
|
+
##
|
210
|
+
# Return the hash code
|
211
|
+
#
|
212
|
+
# @return [Integer]
|
213
|
+
#
|
214
|
+
def hash
|
215
|
+
# Source available in the toys-core gem
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
219
|
+
##
|
220
|
+
# **_Defined in the toys-core gem_**
|
221
|
+
#
|
222
|
+
# A stack of middleware specs.
|
223
|
+
#
|
224
|
+
class Stack
|
225
|
+
##
|
226
|
+
# The middleware specs that precede the default set.
|
227
|
+
# @return [Array<Toys::Middleware:Spec>]
|
228
|
+
#
|
229
|
+
attr_reader :pre_specs
|
230
|
+
|
231
|
+
##
|
232
|
+
# The default set of middleware specs.
|
233
|
+
# @return [Array<Toys::Middleware:Spec>]
|
234
|
+
#
|
235
|
+
attr_reader :default_specs
|
236
|
+
|
237
|
+
##
|
238
|
+
# The middleware specs that follow the default set.
|
239
|
+
# @return [Array<Toys::Middleware:Spec>]
|
240
|
+
#
|
241
|
+
attr_reader :post_specs
|
242
|
+
|
243
|
+
##
|
244
|
+
# Add a middleware spec to the stack, in the default location, which is
|
245
|
+
# at the end of pre_specs). See {Toys::Middleware.spec} for a description
|
246
|
+
# of the arguments you can pass.
|
247
|
+
#
|
248
|
+
# @overload add(name, *args, **kwargs, &block)
|
249
|
+
# @overload add(array)
|
250
|
+
# @overload add(middleware_object)
|
251
|
+
#
|
252
|
+
def add(middleware, *args, **kwargs, &block)
|
253
|
+
# Source available in the toys-core gem
|
254
|
+
end
|
255
|
+
|
256
|
+
##
|
257
|
+
# Duplicate this stack.
|
258
|
+
#
|
259
|
+
# @return [Toys::Middleware::Stack]
|
260
|
+
#
|
261
|
+
def dup
|
262
|
+
# Source available in the toys-core gem
|
263
|
+
end
|
264
|
+
|
265
|
+
##
|
266
|
+
# Build the middleware in this stack.
|
267
|
+
#
|
268
|
+
# @return [Array<Toys::Middleware>]
|
269
|
+
#
|
270
|
+
def build(middleware_lookup)
|
271
|
+
# Source available in the toys-core gem
|
272
|
+
end
|
273
|
+
|
274
|
+
##
|
275
|
+
# Equality check
|
276
|
+
#
|
277
|
+
# @param other [Object]
|
278
|
+
# @return [Boolean]
|
279
|
+
#
|
280
|
+
def ==(other)
|
281
|
+
# Source available in the toys-core gem
|
282
|
+
end
|
283
|
+
alias eql? ==
|
284
|
+
|
285
|
+
##
|
286
|
+
# Return the hash code
|
287
|
+
#
|
288
|
+
# @return [Integer]
|
289
|
+
#
|
290
|
+
def hash
|
291
|
+
# Source available in the toys-core gem
|
292
|
+
end
|
293
|
+
end
|
294
|
+
end
|
295
|
+
end
|
@@ -0,0 +1,142 @@
|
|
1
|
+
module Toys
|
2
|
+
##
|
3
|
+
# **_Defined in the toys-core gem_**
|
4
|
+
#
|
5
|
+
# A mixin definition. Mixin modules should include this module.
|
6
|
+
#
|
7
|
+
# A mixin is a collection of methods that are available to be called from a
|
8
|
+
# tool implementation (i.e. its run method). The mixin is added to the tool
|
9
|
+
# class, so it has access to the same methods that can be called by the tool,
|
10
|
+
# such as {Toys::Context#get}.
|
11
|
+
#
|
12
|
+
# ### Usage
|
13
|
+
#
|
14
|
+
# To create a mixin, define a module, and include this module. Then define
|
15
|
+
# the methods you want to be available.
|
16
|
+
#
|
17
|
+
# If you want to perform some initialization specific to the mixin, you can
|
18
|
+
# provide an *initializer* block and/or an *inclusion* block. These can be
|
19
|
+
# specified by calling the module methods defined in
|
20
|
+
# {Toys::Mixin::ModuleMethods}.
|
21
|
+
#
|
22
|
+
# The initializer block is called when the tool context is instantiated
|
23
|
+
# in preparation for execution. It has access to context methods such as
|
24
|
+
# {Toys::Context#get}, and can perform setup for the tool execution itself,
|
25
|
+
# such as initializing some persistent state and storing it in the tool using
|
26
|
+
# {Toys::Context#set}. The initializer block is passed any extra arguments
|
27
|
+
# that were provided to the `include` directive. Define the initializer by
|
28
|
+
# calling {Toys::Mixin::ModuleMethods#on_initialize}.
|
29
|
+
#
|
30
|
+
# The inclusion block is called in the context of your tool class when your
|
31
|
+
# mixin is included. It is also passed any extra arguments that were provided
|
32
|
+
# to the `include` directive. It can be used to issue directives to define
|
33
|
+
# tools or other objects in the DSL, or even enhance the DSL by defining DSL
|
34
|
+
# methods specific to the mixin. Define the inclusion block by calling
|
35
|
+
# {Toys::Mixin::ModuleMethods#on_include}.
|
36
|
+
#
|
37
|
+
# ### Example
|
38
|
+
#
|
39
|
+
# This is an example that implements a simple counter. Whenever the counter
|
40
|
+
# is incremented, a log message is emitted. The tool can also retrieve the
|
41
|
+
# final counter value.
|
42
|
+
#
|
43
|
+
# # Define a mixin by creating a module that includes Toys::Mixin
|
44
|
+
# module MyCounterMixin
|
45
|
+
# include Toys::Mixin
|
46
|
+
#
|
47
|
+
# # Initialize the counter. Notice that the initializer is evaluated
|
48
|
+
# # in the context of the runtime context, so has access to the runtime
|
49
|
+
# # context state.
|
50
|
+
# on_initialize do |start = 0|
|
51
|
+
# set(:counter_value, start)
|
52
|
+
# end
|
53
|
+
#
|
54
|
+
# # Mixin methods are evaluated in the runtime context and so have
|
55
|
+
# # access to the runtime context state, just as if you had defined
|
56
|
+
# # them in your tool.
|
57
|
+
# def counter_value
|
58
|
+
# get(:counter_value)
|
59
|
+
# end
|
60
|
+
#
|
61
|
+
# def increment
|
62
|
+
# set(:counter_value, counter_value + 1)
|
63
|
+
# logger.info("Incremented counter")
|
64
|
+
# end
|
65
|
+
# end
|
66
|
+
#
|
67
|
+
# Now we can use it from a tool:
|
68
|
+
#
|
69
|
+
# tool "count-up" do
|
70
|
+
# # Pass 1 as an extra argument to the mixin initializer
|
71
|
+
# include MyCounterMixin, 1
|
72
|
+
#
|
73
|
+
# def run
|
74
|
+
# # Mixin methods can be called.
|
75
|
+
# 5.times { increment }
|
76
|
+
# puts "Final value is #{counter_value}"
|
77
|
+
# end
|
78
|
+
# end
|
79
|
+
#
|
80
|
+
module Mixin
|
81
|
+
##
|
82
|
+
# Create a mixin module with the given block.
|
83
|
+
#
|
84
|
+
# @param block [Proc] Defines the mixin module.
|
85
|
+
# @return [Class]
|
86
|
+
#
|
87
|
+
def self.create(&block)
|
88
|
+
# Source available in the toys-core gem
|
89
|
+
end
|
90
|
+
|
91
|
+
##
|
92
|
+
# **_Defined in the toys-core gem_**
|
93
|
+
#
|
94
|
+
# Methods that will be added to a mixin module object.
|
95
|
+
#
|
96
|
+
module ModuleMethods
|
97
|
+
##
|
98
|
+
# Set the initializer for this mixin. This block is evaluated in the
|
99
|
+
# runtime context before execution, and is passed any arguments provided
|
100
|
+
# to the `include` directive. It can perform any runtime initialization
|
101
|
+
# needed by the mixin.
|
102
|
+
#
|
103
|
+
# @param block [Proc] Sets the initializer proc.
|
104
|
+
# @return [self]
|
105
|
+
#
|
106
|
+
def on_initialize(&block)
|
107
|
+
# Source available in the toys-core gem
|
108
|
+
end
|
109
|
+
|
110
|
+
##
|
111
|
+
# The initializer proc for this mixin. This proc is evaluated in the
|
112
|
+
# runtime context before execution, and is passed any arguments provided
|
113
|
+
# to the `include` directive. It can perform any runtime initialization
|
114
|
+
# needed by the mixin.
|
115
|
+
#
|
116
|
+
# @return [Proc] The iniitiliazer for this mixin.
|
117
|
+
#
|
118
|
+
attr_accessor :initializer
|
119
|
+
|
120
|
+
##
|
121
|
+
# Set an inclusion proc for this mixin. This block is evaluated in the
|
122
|
+
# tool class immediately after the mixin is included, and is passed any
|
123
|
+
# arguments provided to the `include` directive.
|
124
|
+
#
|
125
|
+
# @param block [Proc] Sets the inclusion proc.
|
126
|
+
# @return [self]
|
127
|
+
#
|
128
|
+
def on_include(&block)
|
129
|
+
# Source available in the toys-core gem
|
130
|
+
end
|
131
|
+
|
132
|
+
##
|
133
|
+
# The inclusion proc for this mixin. This block is evaluated in the tool
|
134
|
+
# class immediately after the mixin is included, and is passed any
|
135
|
+
# arguments provided to the `include` directive.
|
136
|
+
#
|
137
|
+
# @return [Proc] The inclusion procedure for this mixin.
|
138
|
+
#
|
139
|
+
attr_accessor :inclusion
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
module Toys
|
2
|
+
##
|
3
|
+
# **_Defined in the toys-core gem_**
|
4
|
+
#
|
5
|
+
# A helper module that provides methods to do module lookups. This is
|
6
|
+
# used to obtain named helpers, middleware, and templates from the
|
7
|
+
# respective modules.
|
8
|
+
#
|
9
|
+
class ModuleLookup
|
10
|
+
class << self
|
11
|
+
##
|
12
|
+
# Convert the given string to a path element. Specifically, converts
|
13
|
+
# to `lower_snake_case`.
|
14
|
+
#
|
15
|
+
# @param str [String,Symbol] String to convert.
|
16
|
+
# @return [String] Converted string
|
17
|
+
#
|
18
|
+
def to_path_name(str)
|
19
|
+
# Source available in the toys-core gem
|
20
|
+
end
|
21
|
+
|
22
|
+
##
|
23
|
+
# Convert the given string to a module name. Specifically, converts
|
24
|
+
# to `UpperCamelCase`, and then to a symbol.
|
25
|
+
#
|
26
|
+
# @param str [String,Symbol] String to convert.
|
27
|
+
# @return [Symbol] Converted name
|
28
|
+
#
|
29
|
+
def to_module_name(str)
|
30
|
+
# Source available in the toys-core gem
|
31
|
+
end
|
32
|
+
|
33
|
+
##
|
34
|
+
# Given a require path, return the module expected to be defined.
|
35
|
+
#
|
36
|
+
# @param path [String] File path, delimited by forward slash
|
37
|
+
# @return [Module] The module loaded from that path
|
38
|
+
#
|
39
|
+
def path_to_module(path)
|
40
|
+
# Source available in the toys-core gem
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
##
|
45
|
+
# Create an empty ModuleLookup
|
46
|
+
#
|
47
|
+
def initialize
|
48
|
+
# Source available in the toys-core gem
|
49
|
+
end
|
50
|
+
|
51
|
+
##
|
52
|
+
# Add a lookup path for modules.
|
53
|
+
#
|
54
|
+
# @param path_base [String] The base require path
|
55
|
+
# @param module_base [Module] The base module, or `nil` (the default) to
|
56
|
+
# infer a default from the path base.
|
57
|
+
# @param high_priority [Boolean] If true, add to the head of the lookup
|
58
|
+
# path, otherwise add to the end.
|
59
|
+
# @return [self]
|
60
|
+
#
|
61
|
+
def add_path(path_base, module_base: nil, high_priority: false)
|
62
|
+
# Source available in the toys-core gem
|
63
|
+
end
|
64
|
+
|
65
|
+
##
|
66
|
+
# Obtain a named module. Returns `nil` if the name is not present.
|
67
|
+
#
|
68
|
+
# @param name [String,Symbol] The name of the module to return.
|
69
|
+
# @return [Module] The specified module
|
70
|
+
#
|
71
|
+
def lookup(name)
|
72
|
+
# Source available in the toys-core gem
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,145 @@
|
|
1
|
+
module Toys
|
2
|
+
##
|
3
|
+
# **_Defined in the toys-core gem_**
|
4
|
+
#
|
5
|
+
# Representation of a formal positional argument
|
6
|
+
#
|
7
|
+
class PositionalArg
|
8
|
+
##
|
9
|
+
# Create a PositionalArg definition.
|
10
|
+
#
|
11
|
+
# @param key [String,Symbol] The key to use to retrieve the value from
|
12
|
+
# the execution context.
|
13
|
+
# @param type [Symbol] The type of arg. Valid values are `:required`,
|
14
|
+
# `:optional`, and `:remaining`.
|
15
|
+
# @param accept [Object] An acceptor that validates and/or converts the
|
16
|
+
# value. See {Toys::Acceptor.create} for recognized formats. Optional.
|
17
|
+
# If not specified, defaults to {Toys::Acceptor::DEFAULT}.
|
18
|
+
# @param complete [Object] A specifier for shell tab completion. See
|
19
|
+
# {Toys::Completion.create} for recognized formats.
|
20
|
+
# @param display_name [String] A name to use for display (in help text and
|
21
|
+
# error reports). Defaults to the key in upper case.
|
22
|
+
# @param desc [String,Array<String>,Toys::WrappableString] Short
|
23
|
+
# description for the flag. See {Toys::ToolDefintion#desc} for a
|
24
|
+
# description of the allowed formats. Defaults to the empty string.
|
25
|
+
# @param long_desc [Array<String,Array<String>,Toys::WrappableString>]
|
26
|
+
# Long description for the flag. See {Toys::ToolDefintion#long_desc}
|
27
|
+
# for a description of the allowed formats. (But note that this param
|
28
|
+
# takes an Array of description lines, rather than a series of
|
29
|
+
# arguments.) Defaults to the empty array.
|
30
|
+
# @return [Toys::PositionalArg]
|
31
|
+
#
|
32
|
+
def self.create(key, type,
|
33
|
+
accept: nil, default: nil, complete: nil, desc: nil,
|
34
|
+
long_desc: nil, display_name: nil)
|
35
|
+
# Source available in the toys-core gem
|
36
|
+
end
|
37
|
+
|
38
|
+
##
|
39
|
+
# The key for this arg.
|
40
|
+
# @return [Symbol]
|
41
|
+
#
|
42
|
+
attr_reader :key
|
43
|
+
|
44
|
+
##
|
45
|
+
# Type of this argument.
|
46
|
+
# @return [:required,:optional,:remaining]
|
47
|
+
#
|
48
|
+
attr_reader :type
|
49
|
+
|
50
|
+
##
|
51
|
+
# The effective acceptor.
|
52
|
+
# @return [Toys::Acceptor::Base]
|
53
|
+
#
|
54
|
+
attr_accessor :acceptor
|
55
|
+
|
56
|
+
##
|
57
|
+
# The default value, which may be `nil`.
|
58
|
+
# @return [Object]
|
59
|
+
#
|
60
|
+
attr_reader :default
|
61
|
+
|
62
|
+
##
|
63
|
+
# The proc that determines shell completions for the value.
|
64
|
+
# @return [Proc,Toys::Completion::Base]
|
65
|
+
#
|
66
|
+
attr_reader :completion
|
67
|
+
|
68
|
+
##
|
69
|
+
# The short description string.
|
70
|
+
#
|
71
|
+
# When reading, this is always returned as a {Toys::WrappableString}.
|
72
|
+
#
|
73
|
+
# When setting, the description may be provided as any of the following:
|
74
|
+
# * A {Toys::WrappableString}.
|
75
|
+
# * A normal String, which will be transformed into a
|
76
|
+
# {Toys::WrappableString} using spaces as word delimiters.
|
77
|
+
# * An Array of String, which will be transformed into a
|
78
|
+
# {Toys::WrappableString} where each array element represents an
|
79
|
+
# individual word for wrapping.
|
80
|
+
#
|
81
|
+
# @return [Toys::WrappableString]
|
82
|
+
#
|
83
|
+
attr_reader :desc
|
84
|
+
|
85
|
+
##
|
86
|
+
# The long description strings.
|
87
|
+
#
|
88
|
+
# When reading, this is returned as an Array of {Toys::WrappableString}
|
89
|
+
# representing the lines in the description.
|
90
|
+
#
|
91
|
+
# When setting, the description must be provided as an Array where *each
|
92
|
+
# element* may be any of the following:
|
93
|
+
# * A {Toys::WrappableString} representing one line.
|
94
|
+
# * A normal String representing a line. This will be transformed into a
|
95
|
+
# {Toys::WrappableString} using spaces as word delimiters.
|
96
|
+
# * An Array of String representing a line. This will be transformed into
|
97
|
+
# a {Toys::WrappableString} where each array element represents an
|
98
|
+
# individual word for wrapping.
|
99
|
+
#
|
100
|
+
# @return [Array<Toys::WrappableString>]
|
101
|
+
#
|
102
|
+
attr_reader :long_desc
|
103
|
+
|
104
|
+
##
|
105
|
+
# The displayable name.
|
106
|
+
# @return [String]
|
107
|
+
#
|
108
|
+
attr_accessor :display_name
|
109
|
+
|
110
|
+
##
|
111
|
+
# Set the short description string.
|
112
|
+
#
|
113
|
+
# See {#desc} for details.
|
114
|
+
#
|
115
|
+
# @param desc [Toys::WrappableString,String,Array<String>]
|
116
|
+
#
|
117
|
+
def desc=(desc)
|
118
|
+
# Source available in the toys-core gem
|
119
|
+
end
|
120
|
+
|
121
|
+
##
|
122
|
+
# Set the long description strings.
|
123
|
+
#
|
124
|
+
# See {#long_desc} for details.
|
125
|
+
#
|
126
|
+
# @param long_desc [Array<Toys::WrappableString,String,Array<String>>]
|
127
|
+
#
|
128
|
+
def long_desc=(long_desc)
|
129
|
+
# Source available in the toys-core gem
|
130
|
+
end
|
131
|
+
|
132
|
+
##
|
133
|
+
# Append long description strings.
|
134
|
+
#
|
135
|
+
# You must pass an array of lines in the long description. See {#long_desc}
|
136
|
+
# for details on how each line may be represented.
|
137
|
+
#
|
138
|
+
# @param long_desc [Array<Toys::WrappableString,String,Array<String>>]
|
139
|
+
# @return [self]
|
140
|
+
#
|
141
|
+
def append_long_desc(long_desc)
|
142
|
+
# Source available in the toys-core gem
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|