toys 0.13.1 → 0.14.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +37 -0
- data/README.md +18 -17
- data/builtins/system/.toys.rb +40 -0
- data/builtins/system/git-cache.rb +15 -10
- data/builtins/system/test.rb +2 -3
- data/builtins/system/tools.rb +145 -0
- data/core-docs/toys/acceptor.rb +50 -8
- data/core-docs/toys/cli.rb +3 -3
- data/core-docs/toys/completion.rb +11 -0
- data/core-docs/toys/context.rb +16 -2
- data/core-docs/toys/core.rb +1 -1
- data/core-docs/toys/dsl/tool.rb +15 -7
- data/core-docs/toys/errors.rb +33 -0
- data/core-docs/toys/flag.rb +11 -0
- data/core-docs/toys/input_file.rb +6 -0
- data/core-docs/toys/loader.rb +146 -5
- data/core-docs/toys/middleware.rb +42 -2
- data/core-docs/toys/settings.rb +17 -0
- data/core-docs/toys/source_info.rb +95 -0
- data/core-docs/toys/standard_mixins/exec.rb +69 -22
- data/core-docs/toys/standard_mixins/pager.rb +46 -0
- data/core-docs/toys/standard_mixins/xdg.rb +7 -7
- data/core-docs/toys/tool_definition.rb +69 -0
- data/core-docs/toys/utils/exec.rb +61 -27
- data/core-docs/toys/utils/pager.rb +104 -0
- data/core-docs/toys/wrappable_string.rb +12 -0
- data/docs/guide.md +92 -67
- data/lib/toys/testing.rb +33 -2
- data/lib/toys/version.rb +1 -1
- metadata +10 -6
data/core-docs/toys/errors.rb
CHANGED
@@ -51,6 +51,19 @@ module Toys
|
|
51
51
|
# thrown during tool execution.
|
52
52
|
#
|
53
53
|
class ContextualError < ::StandardError
|
54
|
+
##
|
55
|
+
# Construct a ContextualError. This exception type is thrown from
|
56
|
+
# {ContextualError.capture} and {ContextualError.capture_path} and should
|
57
|
+
# not be constructed directly.
|
58
|
+
#
|
59
|
+
# @private This interface is internal and subject to change without warning.
|
60
|
+
#
|
61
|
+
def initialize(cause, banner,
|
62
|
+
config_path: nil, config_line: nil,
|
63
|
+
tool_name: nil, tool_args: nil)
|
64
|
+
# Source available in the toys-core gem
|
65
|
+
end
|
66
|
+
|
54
67
|
##
|
55
68
|
# The underlying exception
|
56
69
|
# @return [::StandardError]
|
@@ -88,6 +101,26 @@ module Toys
|
|
88
101
|
attr_reader :tool_args
|
89
102
|
|
90
103
|
class << self
|
104
|
+
##
|
105
|
+
# Execute the given block, and wrap any exceptions thrown with a
|
106
|
+
# ContextualError. This is intended for loading a config file from the
|
107
|
+
# given path, and wraps any Ruby parsing errors.
|
108
|
+
#
|
109
|
+
# @private This interface is internal and subject to change without warning.
|
110
|
+
#
|
111
|
+
def capture_path(banner, path, **opts)
|
112
|
+
# Source available in the toys-core gem
|
113
|
+
end
|
114
|
+
|
115
|
+
##
|
116
|
+
# Execute the given block, and wrap any exceptions thrown with a
|
117
|
+
# ContextualError.
|
118
|
+
#
|
119
|
+
# @private This interface is internal and subject to change without warning.
|
120
|
+
#
|
121
|
+
def capture(banner, **opts)
|
122
|
+
# Source available in the toys-core gem
|
123
|
+
end
|
91
124
|
end
|
92
125
|
end
|
93
126
|
end
|
data/core-docs/toys/flag.rb
CHANGED
@@ -77,6 +77,7 @@ module Toys
|
|
77
77
|
# The type of flag (`:boolean` or `:value`)
|
78
78
|
# @return [:boolean] if this is a boolean flag (i.e. no value)
|
79
79
|
# @return [:value] if this flag takes a value (even if optional)
|
80
|
+
# @return [nil] if this flag is indeterminate
|
80
81
|
#
|
81
82
|
attr_reader :flag_type
|
82
83
|
|
@@ -111,6 +112,16 @@ module Toys
|
|
111
112
|
# @return [String]
|
112
113
|
#
|
113
114
|
attr_reader :canonical_str
|
115
|
+
|
116
|
+
##
|
117
|
+
# This method is accessible for testing only.
|
118
|
+
#
|
119
|
+
# @private This interface is internal and subject to change without warning.
|
120
|
+
#
|
121
|
+
def configure_canonical(canonical_flag_type, canonical_value_type,
|
122
|
+
canonical_value_label, canonical_value_delim)
|
123
|
+
# Source available in the toys-core gem
|
124
|
+
end
|
114
125
|
end
|
115
126
|
|
116
127
|
##
|
@@ -5,4 +5,10 @@
|
|
5
5
|
# is parsed, a module is created under this parent for that file's constants.
|
6
6
|
#
|
7
7
|
module Toys::InputFile # rubocop:disable Style/ClassAndModuleChildren
|
8
|
+
##
|
9
|
+
# @private This interface is internal and subject to change without warning.
|
10
|
+
#
|
11
|
+
def self.evaluate(tool_class, words, priority, remaining_words, source, loader)
|
12
|
+
# Source available in the toys-core gem
|
13
|
+
end
|
8
14
|
end
|
data/core-docs/toys/loader.rb
CHANGED
@@ -183,22 +183,31 @@ module Toys
|
|
183
183
|
|
184
184
|
##
|
185
185
|
# Returns a list of subtools for the given path, loading from the
|
186
|
-
# configuration if necessary.
|
186
|
+
# configuration if necessary. The list will be sorted by name.
|
187
187
|
#
|
188
188
|
# @param words [Array<String>] The name of the parent tool
|
189
189
|
# @param recursive [Boolean] If true, return all subtools recursively
|
190
190
|
# rather than just the immediate children (the default)
|
191
191
|
# @param include_hidden [Boolean] If true, include hidden subtools,
|
192
|
-
# e.
|
192
|
+
# i.e. names beginning with underscores. Defaults to false.
|
193
|
+
# @param include_namespaces [Boolean] If true, include namespaces,
|
194
|
+
# i.e. tools that are not runnable but have descendents that would have
|
195
|
+
# been listed by the current filters. Defaults to false.
|
196
|
+
# @param include_non_runnable [Boolean] If true, include tools that have
|
197
|
+
# no children and are not runnable. Defaults to false.
|
193
198
|
# @return [Array<Toys::ToolDefinition>] An array of subtools.
|
194
199
|
#
|
195
|
-
def list_subtools(words,
|
200
|
+
def list_subtools(words,
|
201
|
+
recursive: false,
|
202
|
+
include_hidden: false,
|
203
|
+
include_namespaces: false,
|
204
|
+
include_non_runnable: false)
|
196
205
|
# Source available in the toys-core gem
|
197
206
|
end
|
198
207
|
|
199
208
|
##
|
200
|
-
# Returns true if the given path has at least one subtool
|
201
|
-
# configuration if necessary.
|
209
|
+
# Returns true if the given path has at least one subtool, even if they are
|
210
|
+
# hidden or non-runnable. Loads from the configuration if necessary.
|
202
211
|
#
|
203
212
|
# @param words [Array<String>] The name of the parent tool
|
204
213
|
# @return [Boolean]
|
@@ -218,5 +227,137 @@ module Toys
|
|
218
227
|
def split_path(str)
|
219
228
|
# Source available in the toys-core gem
|
220
229
|
end
|
230
|
+
|
231
|
+
#### INTERNAL METHODS ####
|
232
|
+
|
233
|
+
##
|
234
|
+
# Get or create the tool definition for the given name and priority.
|
235
|
+
#
|
236
|
+
# @private This interface is internal and subject to change without warning.
|
237
|
+
#
|
238
|
+
def get_tool(words, priority, tool_class = nil)
|
239
|
+
# Source available in the toys-core gem
|
240
|
+
end
|
241
|
+
|
242
|
+
##
|
243
|
+
# Returns the active tool specified by the given words, with the given
|
244
|
+
# priority, without doing any loading. If the given priority matches the
|
245
|
+
# currently active tool, returns it. If the given priority is lower than
|
246
|
+
# the active priority, returns `nil`. If the given priority is higher than
|
247
|
+
# the active priority, returns and activates a new tool.
|
248
|
+
#
|
249
|
+
# @private This interface is internal and subject to change without warning.
|
250
|
+
#
|
251
|
+
def activate_tool(words, priority)
|
252
|
+
# Source available in the toys-core gem
|
253
|
+
end
|
254
|
+
|
255
|
+
##
|
256
|
+
# Returns true if the given tool name currently exists in the loader.
|
257
|
+
# Does not load the tool if not found.
|
258
|
+
#
|
259
|
+
# @private This interface is internal and subject to change without warning.
|
260
|
+
#
|
261
|
+
def tool_defined?(words)
|
262
|
+
# Source available in the toys-core gem
|
263
|
+
end
|
264
|
+
|
265
|
+
##
|
266
|
+
# Build a new tool.
|
267
|
+
# Called only from ToolData.
|
268
|
+
#
|
269
|
+
# @private This interface is internal and subject to change without warning.
|
270
|
+
#
|
271
|
+
def build_tool(words, priority, tool_class = nil)
|
272
|
+
# Source available in the toys-core gem
|
273
|
+
end
|
274
|
+
|
275
|
+
##
|
276
|
+
# Stop search at the given priority. Returns true if successful.
|
277
|
+
# Called only from the DSL.
|
278
|
+
#
|
279
|
+
# @private This interface is internal and subject to change without warning.
|
280
|
+
#
|
281
|
+
def stop_loading_at_priority(priority)
|
282
|
+
# Source available in the toys-core gem
|
283
|
+
end
|
284
|
+
|
285
|
+
##
|
286
|
+
# Loads the subtree under the given prefix.
|
287
|
+
#
|
288
|
+
# @private This interface is internal and subject to change without warning.
|
289
|
+
#
|
290
|
+
def load_for_prefix(prefix)
|
291
|
+
# Source available in the toys-core gem
|
292
|
+
end
|
293
|
+
|
294
|
+
##
|
295
|
+
# Attempt to get a well-known mixin module for the given symbolic name.
|
296
|
+
#
|
297
|
+
# @private This interface is internal and subject to change without warning.
|
298
|
+
#
|
299
|
+
def resolve_standard_mixin(name)
|
300
|
+
# Source available in the toys-core gem
|
301
|
+
end
|
302
|
+
|
303
|
+
##
|
304
|
+
# Attempt to get a well-known template class for the given symbolic name.
|
305
|
+
#
|
306
|
+
# @private This interface is internal and subject to change without warning.
|
307
|
+
#
|
308
|
+
def resolve_standard_template(name)
|
309
|
+
# Source available in the toys-core gem
|
310
|
+
end
|
311
|
+
|
312
|
+
##
|
313
|
+
# Load configuration from the given path. This is called from the `load`
|
314
|
+
# directive in the DSL.
|
315
|
+
#
|
316
|
+
# @private This interface is internal and subject to change without warning.
|
317
|
+
#
|
318
|
+
def load_path(parent_source, path, words, remaining_words, priority)
|
319
|
+
# Source available in the toys-core gem
|
320
|
+
end
|
321
|
+
|
322
|
+
##
|
323
|
+
# Load configuration from the given git remote. This is called from the
|
324
|
+
# `load_git` directive in the DSL.
|
325
|
+
#
|
326
|
+
# @private This interface is internal and subject to change without warning.
|
327
|
+
#
|
328
|
+
def load_git(parent_source, git_remote, git_path, git_commit, words, remaining_words, priority,
|
329
|
+
update: false)
|
330
|
+
# Source available in the toys-core gem
|
331
|
+
end
|
332
|
+
|
333
|
+
##
|
334
|
+
# Load a subtool block. Called from the `tool` directive in the DSL.
|
335
|
+
#
|
336
|
+
# @private This interface is internal and subject to change without warning.
|
337
|
+
#
|
338
|
+
def load_block(parent_source, block, words, remaining_words, priority)
|
339
|
+
# Source available in the toys-core gem
|
340
|
+
end
|
341
|
+
|
342
|
+
@git_cache_mutex = ::Monitor.new
|
343
|
+
@default_git_cache = nil
|
344
|
+
|
345
|
+
##
|
346
|
+
# Get a global default GitCache.
|
347
|
+
#
|
348
|
+
# @private This interface is internal and subject to change without warning.
|
349
|
+
#
|
350
|
+
def self.default_git_cache
|
351
|
+
# Source available in the toys-core gem
|
352
|
+
end
|
353
|
+
|
354
|
+
##
|
355
|
+
# Determine the next setting for remaining_words, given a word.
|
356
|
+
#
|
357
|
+
# @private This interface is internal and subject to change without warning.
|
358
|
+
#
|
359
|
+
def self.next_remaining_words(remaining_words, word)
|
360
|
+
# Source available in the toys-core gem
|
361
|
+
end
|
221
362
|
end
|
222
363
|
end
|
@@ -123,12 +123,21 @@ module Toys
|
|
123
123
|
def stack(input)
|
124
124
|
# Source available in the toys-core gem
|
125
125
|
end
|
126
|
+
|
127
|
+
##
|
128
|
+
# Create a spec from an array specification.
|
129
|
+
#
|
130
|
+
# @private This interface is internal and subject to change without warning.
|
131
|
+
#
|
132
|
+
def spec_from_array(array)
|
133
|
+
# Source available in the toys-core gem
|
134
|
+
end
|
126
135
|
end
|
127
136
|
|
128
137
|
##
|
129
138
|
# **_Defined in the toys-core gem_**
|
130
139
|
#
|
131
|
-
# A base class that provides default
|
140
|
+
# A base class that provides default no-op implementation of the middleware
|
132
141
|
# interface. This base class may optionally be subclassed by a middleware
|
133
142
|
# implementation.
|
134
143
|
#
|
@@ -214,12 +223,34 @@ module Toys
|
|
214
223
|
def hash
|
215
224
|
# Source available in the toys-core gem
|
216
225
|
end
|
226
|
+
|
227
|
+
##
|
228
|
+
# Internal constructor. Use {Toys::Middleware.spec} instead.
|
229
|
+
#
|
230
|
+
# @private This interface is internal and subject to change without warning.
|
231
|
+
#
|
232
|
+
def initialize(object, name, args, kwargs, block)
|
233
|
+
# Source available in the toys-core gem
|
234
|
+
end
|
217
235
|
end
|
218
236
|
|
219
237
|
##
|
220
238
|
# **_Defined in the toys-core gem_**
|
221
239
|
#
|
222
|
-
# A stack of middleware specs.
|
240
|
+
# A stack of middleware specs, which can be applied in order to a tool.
|
241
|
+
#
|
242
|
+
# A middleware stack is separated into three groups:
|
243
|
+
#
|
244
|
+
# * {#pre_specs}, which are applied first.
|
245
|
+
# * {#default_specs}, which are applied next. The default specs are set
|
246
|
+
# when the stack is created and are generally not modified.
|
247
|
+
# * {#post_specs}, which are applied third.
|
248
|
+
#
|
249
|
+
# When adding middleware to a stack, you should normally add them to the
|
250
|
+
# pre or post specs. By default, {Stack#add} appends to the pre specs,
|
251
|
+
# inserting new middleware just before the defaults.
|
252
|
+
#
|
253
|
+
# Use {Toys::Middleware.stack} to create a middleware stack.
|
223
254
|
#
|
224
255
|
class Stack
|
225
256
|
##
|
@@ -290,6 +321,15 @@ module Toys
|
|
290
321
|
def hash
|
291
322
|
# Source available in the toys-core gem
|
292
323
|
end
|
324
|
+
|
325
|
+
##
|
326
|
+
# Internal constructor. Use {Toys::Middleware.stack} instead.
|
327
|
+
#
|
328
|
+
# @private This interface is internal and subject to change without warning.
|
329
|
+
#
|
330
|
+
def initialize(default_specs: nil, pre_specs: nil, post_specs: nil)
|
331
|
+
# Source available in the toys-core gem
|
332
|
+
end
|
293
333
|
end
|
294
334
|
end
|
295
335
|
end
|
data/core-docs/toys/settings.rb
CHANGED
@@ -332,6 +332,13 @@ module Toys
|
|
332
332
|
# @return [String, nil]
|
333
333
|
#
|
334
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
|
335
342
|
end
|
336
343
|
|
337
344
|
##
|
@@ -502,6 +509,16 @@ module Toys
|
|
502
509
|
def settings_group(name, klass = nil, &block)
|
503
510
|
# Source available in the toys-core gem
|
504
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
|
505
522
|
end
|
506
523
|
end
|
507
524
|
end
|
@@ -123,5 +123,100 @@ module Toys
|
|
123
123
|
def apply_lib_paths
|
124
124
|
# Source available in the toys-core gem
|
125
125
|
end
|
126
|
+
|
127
|
+
##
|
128
|
+
# Create a SourceInfo.
|
129
|
+
#
|
130
|
+
# @private This interface is internal and subject to change without warning.
|
131
|
+
#
|
132
|
+
def initialize(parent, priority, context_directory, source_type, source_path, source_proc,
|
133
|
+
git_remote, git_path, git_commit, source_name, data_dir_name, lib_dir_name)
|
134
|
+
# Source available in the toys-core gem
|
135
|
+
end
|
136
|
+
|
137
|
+
##
|
138
|
+
# Create a child SourceInfo relative to the parent path.
|
139
|
+
#
|
140
|
+
# @private This interface is internal and subject to change without warning.
|
141
|
+
#
|
142
|
+
def relative_child(filename, source_name: nil)
|
143
|
+
# Source available in the toys-core gem
|
144
|
+
end
|
145
|
+
|
146
|
+
##
|
147
|
+
# Create a child SourceInfo with an absolute path.
|
148
|
+
#
|
149
|
+
# @private This interface is internal and subject to change without warning.
|
150
|
+
#
|
151
|
+
def absolute_child(child_path, source_name: nil)
|
152
|
+
# Source available in the toys-core gem
|
153
|
+
end
|
154
|
+
|
155
|
+
##
|
156
|
+
# Create a child SourceInfo with a git source.
|
157
|
+
#
|
158
|
+
# @private This interface is internal and subject to change without warning.
|
159
|
+
#
|
160
|
+
def git_child(child_git_remote, child_git_path, child_git_commit, child_path,
|
161
|
+
source_name: nil)
|
162
|
+
# Source available in the toys-core gem
|
163
|
+
end
|
164
|
+
|
165
|
+
##
|
166
|
+
# Create a proc child SourceInfo
|
167
|
+
#
|
168
|
+
# @private This interface is internal and subject to change without warning.
|
169
|
+
#
|
170
|
+
def proc_child(child_proc, source_name: nil)
|
171
|
+
# Source available in the toys-core gem
|
172
|
+
end
|
173
|
+
|
174
|
+
##
|
175
|
+
# Create a root source info for a file path.
|
176
|
+
#
|
177
|
+
# @private This interface is internal and subject to change without warning.
|
178
|
+
#
|
179
|
+
def self.create_path_root(source_path, priority,
|
180
|
+
context_directory: nil,
|
181
|
+
data_dir_name: nil,
|
182
|
+
lib_dir_name: nil,
|
183
|
+
source_name: nil)
|
184
|
+
# Source available in the toys-core gem
|
185
|
+
end
|
186
|
+
|
187
|
+
##
|
188
|
+
# Create a root source info for a cached git repo.
|
189
|
+
#
|
190
|
+
# @private This interface is internal and subject to change without warning.
|
191
|
+
#
|
192
|
+
def self.create_git_root(git_remote, git_path, git_commit, source_path, priority,
|
193
|
+
context_directory: nil,
|
194
|
+
data_dir_name: nil,
|
195
|
+
lib_dir_name: nil,
|
196
|
+
source_name: nil)
|
197
|
+
# Source available in the toys-core gem
|
198
|
+
end
|
199
|
+
|
200
|
+
##
|
201
|
+
# Create a root source info for a proc.
|
202
|
+
#
|
203
|
+
# @private This interface is internal and subject to change without warning.
|
204
|
+
#
|
205
|
+
def self.create_proc_root(source_proc, priority,
|
206
|
+
context_directory: nil,
|
207
|
+
data_dir_name: nil,
|
208
|
+
lib_dir_name: nil,
|
209
|
+
source_name: nil)
|
210
|
+
# Source available in the toys-core gem
|
211
|
+
end
|
212
|
+
|
213
|
+
##
|
214
|
+
# Check a path and determine the canonical path and type.
|
215
|
+
#
|
216
|
+
# @private This interface is internal and subject to change without warning.
|
217
|
+
#
|
218
|
+
def self.check_path(path, lenient)
|
219
|
+
# Source available in the toys-core gem
|
220
|
+
end
|
126
221
|
end
|
127
222
|
end
|
@@ -8,7 +8,7 @@ module Toys
|
|
8
8
|
# in a string. Also provides an interface for controlling a spawned
|
9
9
|
# process's streams.
|
10
10
|
#
|
11
|
-
# You
|
11
|
+
# You can make these methods available to your tool by including the
|
12
12
|
# following directive in your tool configuration:
|
13
13
|
#
|
14
14
|
# include :exec
|
@@ -54,54 +54,88 @@ module Toys
|
|
54
54
|
# options.
|
55
55
|
#
|
56
56
|
# Three general strategies are available for custom stream handling. First,
|
57
|
-
# you
|
57
|
+
# you can redirect to other streams such as files, IO objects, or Ruby
|
58
58
|
# strings. Some of these options map directly to options provided by the
|
59
|
-
# `Process#spawn` method. Second, you
|
60
|
-
# the streams programmatically. Third, you
|
59
|
+
# `Process#spawn` method. Second, you can use a controller to manipulate
|
60
|
+
# the streams programmatically. Third, you can capture output stream data
|
61
61
|
# and make it available in the result.
|
62
62
|
#
|
63
63
|
# Following is a full list of the stream handling options, along with how
|
64
64
|
# to specify them using the `:in`, `:out`, and `:err` options.
|
65
65
|
#
|
66
|
-
# * **Inherit parent stream:** You
|
66
|
+
# * **Inherit parent stream:** You can inherit the corresponding stream
|
67
67
|
# in the parent process by passing `:inherit` as the option value. This
|
68
68
|
# is the default if the subprocess is *not* run in the background.
|
69
|
-
#
|
69
|
+
#
|
70
|
+
# * **Redirect to null:** You can redirect to a null stream by passing
|
70
71
|
# `:null` as the option value. This connects to a stream that is not
|
71
72
|
# closed but contains no data, i.e. `/dev/null` on unix systems. This
|
72
73
|
# is the default if the subprocess is run in the background.
|
73
|
-
#
|
74
|
+
#
|
75
|
+
# * **Close the stream:** You can close the stream by passing `:close` as
|
74
76
|
# the option value. This is the same as passing `:close` to
|
75
77
|
# `Process#spawn`.
|
76
|
-
#
|
78
|
+
#
|
79
|
+
# * **Redirect to a file:** You can redirect to a file. This reads from
|
77
80
|
# an existing file when connected to `:in`, and creates or appends to a
|
78
81
|
# file when connected to `:out` or `:err`. To specify a file, use the
|
79
|
-
# setting `[:file, "/path/to/file"]`. You
|
82
|
+
# setting `[:file, "/path/to/file"]`. You can also, when writing a
|
80
83
|
# file, append an optional mode and permission code to the array. For
|
81
84
|
# example, `[:file, "/path/to/file", "a", 0644]`.
|
82
|
-
#
|
83
|
-
#
|
85
|
+
#
|
86
|
+
# * **Redirect to an IO object:** You can redirect to an IO object in the
|
87
|
+
# parent process, by passing the IO object as the option value. You can
|
84
88
|
# use any IO object. For example, you could connect the child's output
|
85
89
|
# to the parent's error using `out: $stderr`, or you could connect to
|
86
90
|
# an existing File stream. Unlike `Process#spawn`, this works for IO
|
87
91
|
# objects that do not have a corresponding file descriptor (such as
|
88
92
|
# StringIO objects). In such a case, a thread will be spawned to pipe
|
89
93
|
# the IO data through to the child process.
|
90
|
-
#
|
94
|
+
#
|
95
|
+
# * **Redirect to a pipe:** You can redirect to a pipe created using
|
96
|
+
# `IO.pipe` (i.e. a two-element array of read and write IO objects) by
|
97
|
+
# passing the array as the option value. This will connect the
|
98
|
+
# appropriate IO (either read or write), and close it in the parent.
|
99
|
+
# Thus, you can connect only one process to each end. If you want more
|
100
|
+
# direct control over IO closing behavior, pass the IO object (i.e. the
|
101
|
+
# element of the pipe array) directly.
|
102
|
+
#
|
103
|
+
# * **Combine with another child stream:** You can redirect one child
|
91
104
|
# output stream to another, to combine them. To merge the child's error
|
92
105
|
# stream into its output stream, use `err: [:child, :out]`.
|
93
|
-
#
|
106
|
+
#
|
107
|
+
# * **Read from a string:** You can pass a string to the input stream by
|
94
108
|
# setting `[:string, "the string"]`. This works only for `:in`.
|
95
|
-
#
|
109
|
+
#
|
110
|
+
# * **Capture output stream:** You can capture a stream and make it
|
96
111
|
# available on the {Toys::Utils::Exec::Result} object, using the
|
97
112
|
# setting `:capture`. This works only for the `:out` and `:err`
|
98
113
|
# streams.
|
99
|
-
#
|
114
|
+
#
|
115
|
+
# * **Use the controller:** You can hook a stream to the controller using
|
100
116
|
# the setting `:controller`. You can then manipulate the stream via the
|
101
117
|
# controller. If you pass a block to {Toys::StandardMixins::Exec#exec},
|
102
118
|
# it yields the {Toys::Utils::Exec::Controller}, giving you access to
|
103
119
|
# streams.
|
104
120
|
#
|
121
|
+
# * **Make copies of an output stream:** You can "tee," or duplicate the
|
122
|
+
# `:out` or `:err` stream and redirect those copies to various
|
123
|
+
# destinations. To specify a tee, use the setting `[:tee, ...]` where
|
124
|
+
# the additional array elements include two or more of the following.
|
125
|
+
# See the corresponding documentation above for more detail.
|
126
|
+
# * `:inherit` to direct to the parent process's stream.
|
127
|
+
# * `:capture` to capture the stream and store it in the result.
|
128
|
+
# * `:controller` to direct the stream to the controller.
|
129
|
+
# * `[:file, "/path/to/file"]` to write to a file.
|
130
|
+
# * An `IO` or `StringIO` object.
|
131
|
+
# * An array of two `IO` objects representing a pipe
|
132
|
+
#
|
133
|
+
# Additionally, the last element of the array can be a hash of options.
|
134
|
+
# Supported options include:
|
135
|
+
# * `:buffer_size` The size of the memory buffer for each element of
|
136
|
+
# the tee. Larger buffers may allow higher throughput. The default
|
137
|
+
# is 65536.
|
138
|
+
#
|
105
139
|
# ### Result handling
|
106
140
|
#
|
107
141
|
# A subprocess result is represented by a {Toys::Utils::Exec::Result}
|
@@ -191,7 +225,7 @@ module Toys
|
|
191
225
|
# not present, the command is not logged.
|
192
226
|
#
|
193
227
|
# * `:log_level` (Integer,false) Level for logging the actual command.
|
194
|
-
# Defaults to Logger::INFO if not present. You
|
228
|
+
# Defaults to Logger::INFO if not present. You can also pass `false` to
|
195
229
|
# disable logging of the command.
|
196
230
|
#
|
197
231
|
# * `:log_cmd` (String) The string logged for the actual command.
|
@@ -243,7 +277,7 @@ module Toys
|
|
243
277
|
end
|
244
278
|
|
245
279
|
##
|
246
|
-
# Execute a command. The command
|
280
|
+
# Execute a command. The command can be given as a single string to pass
|
247
281
|
# to a shell, or an array of strings indicating a posix command.
|
248
282
|
#
|
249
283
|
# If the process is not set to run in the background, and a block is
|
@@ -347,7 +381,7 @@ module Toys
|
|
347
381
|
##
|
348
382
|
# Execute a tool in the current CLI in a forked process.
|
349
383
|
#
|
350
|
-
# The command
|
384
|
+
# The command can be given as a single string or an array of strings,
|
351
385
|
# representing the tool to run and the arguments to pass.
|
352
386
|
#
|
353
387
|
# If the process is not set to run in the background, and a block is
|
@@ -382,7 +416,7 @@ module Toys
|
|
382
416
|
##
|
383
417
|
# Execute a tool in a separately spawned process.
|
384
418
|
#
|
385
|
-
# The command
|
419
|
+
# The command can be given as a single string or an array of strings,
|
386
420
|
# representing the tool to run and the arguments to pass.
|
387
421
|
#
|
388
422
|
# If the process is not set to run in the background, and a block is
|
@@ -425,7 +459,7 @@ module Toys
|
|
425
459
|
end
|
426
460
|
|
427
461
|
##
|
428
|
-
# Execute a command. The command
|
462
|
+
# Execute a command. The command can be given as a single string to pass
|
429
463
|
# to a shell, or an array of strings indicating a posix command.
|
430
464
|
#
|
431
465
|
# Captures standard out and returns it as a string.
|
@@ -527,7 +561,7 @@ module Toys
|
|
527
561
|
# Captures standard out and returns it as a string.
|
528
562
|
# Cannot be run in the background.
|
529
563
|
#
|
530
|
-
# The command
|
564
|
+
# The command can be given as a single string or an array of strings,
|
531
565
|
# representing the tool to run and the arguments to pass.
|
532
566
|
#
|
533
567
|
# If a block is provided, a {Toys::Utils::Exec::Controller} will be
|
@@ -563,7 +597,7 @@ module Toys
|
|
563
597
|
# Captures standard out and returns it as a string.
|
564
598
|
# Cannot be run in the background.
|
565
599
|
#
|
566
|
-
# The command
|
600
|
+
# The command can be given as a single string or an array of strings,
|
567
601
|
# representing the tool to run and the arguments to pass.
|
568
602
|
#
|
569
603
|
# If a block is provided, a {Toys::Utils::Exec::Controller} will be
|
@@ -640,6 +674,19 @@ module Toys
|
|
640
674
|
def exit_on_nonzero_status(status)
|
641
675
|
# Source available in the toys-core gem
|
642
676
|
end
|
677
|
+
|
678
|
+
##
|
679
|
+
# Returns an array of standard verbosity flags needed to replicate the
|
680
|
+
# current verbosity level. This is useful when you want to spawn tools
|
681
|
+
# with the same verbosity level as the current tool.
|
682
|
+
#
|
683
|
+
# @param short [Boolean] Whether to emit short rather than long flags.
|
684
|
+
# Default is false.
|
685
|
+
# @return [Array<String>]
|
686
|
+
#
|
687
|
+
def verbosity_flags(short: false)
|
688
|
+
# Source available in the toys-core gem
|
689
|
+
end
|
643
690
|
end
|
644
691
|
end
|
645
692
|
end
|