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,776 +0,0 @@
1
- module Toys
2
- module Utils
3
- ##
4
- # **_Defined in the toys-core gem_**
5
- #
6
- # A service that executes subprocesses.
7
- #
8
- # This service provides a convenient interface for controlling spawned
9
- # processes and their streams. It also provides shortcuts for common cases
10
- # such as invoking Ruby in a subprocess or capturing output in a string.
11
- #
12
- # This class is not loaded by default. Before using it directly, you should
13
- # `require "toys/utils/exec"`
14
- #
15
- # ### The exec service
16
- #
17
- # The main entrypoint class is this one, {Toys::Utils::Exec}. It's a
18
- # "service" object that provides functionality, primarily methods that
19
- # spawn processes. Create it like any object:
20
- #
21
- # require "toys/utils/exec"
22
- # exec_service = Toys::Utils::Exec.new
23
- #
24
- # There are two "primitive" functions: {#exec} and {#exec_proc}. The {#exec}
25
- # method spawns an operating system process specified by an executable and
26
- # a set of arguments. The {#exec_proc} method takes a `Proc` and forks a
27
- # Ruby process. Both of these can be heavily configured with stream
28
- # handling, result handling, and numerous other options described below.
29
- # The class also provides convenience methods for common cases such as
30
- # spawning a Ruby process, spawning a shell script, or capturing output.
31
- #
32
- # The exec service class also stores default configuration that it applies
33
- # to processes it spawns. You can set these defaults when constructing the
34
- # service class, or at any time by calling {#configure_defaults}.
35
- #
36
- # ### Controlling processes
37
- #
38
- # A process can be started in the *foreground* or the *background*. If you
39
- # start a foreground process, it will "take over" your standard input and
40
- # output streams by default, and it will keep control until it completes.
41
- # If you start a background process, its streams will be redirected to null
42
- # by default, and control will be returned to you immediately.
43
- #
44
- # While a process is running, you can control it using a
45
- # {Toys::Utils::Exec::Controller} object. Use a controller to interact with
46
- # the process's input and output streams, send it signals, or wait for it
47
- # to complete.
48
- #
49
- # When running a process in the foreground, the controller will be yielded
50
- # to an optional block. For example, the following code starts a process in
51
- # the foreground and passes its output stream to a controller.
52
- #
53
- # exec_service.exec(["git", "init"], out: :controller) do |controller|
54
- # loop do
55
- # line = controller.out.gets
56
- # break if line.nil?
57
- # puts "Got line: #{line}"
58
- # end
59
- # end
60
- #
61
- # When running a process in the background, the controller is returned from
62
- # the method that starts the process:
63
- #
64
- # controller = exec_service.exec(["git", "init"], background: true)
65
- #
66
- # ### Stream handling
67
- #
68
- # By default, subprocess streams are connected to the corresponding streams
69
- # in the parent process. You can change this behavior, redirecting streams
70
- # or providing ways to control them, using the `:in`, `:out`, and `:err`
71
- # options.
72
- #
73
- # Three general strategies are available for custom stream handling. First,
74
- # you can redirect to other streams such as files, IO objects, or Ruby
75
- # strings. Some of these options map directly to options provided by the
76
- # `Process#spawn` method. Second, you can use a controller to manipulate
77
- # the streams programmatically. Third, you can capture output stream data
78
- # and make it available in the result.
79
- #
80
- # Following is a full list of the stream handling options, along with how
81
- # to specify them using the `:in`, `:out`, and `:err` options.
82
- #
83
- # * **Inherit parent stream:** You can inherit the corresponding stream
84
- # in the parent process by passing `:inherit` as the option value. This
85
- # is the default if the subprocess is *not* run in the background.
86
- #
87
- # * **Redirect to null:** You can redirect to a null stream by passing
88
- # `:null` as the option value. This connects to a stream that is not
89
- # closed but contains no data, i.e. `/dev/null` on unix systems. This
90
- # is the default if the subprocess is run in the background.
91
- #
92
- # * **Close the stream:** You can close the stream by passing `:close` as
93
- # the option value. This is the same as passing `:close` to
94
- # `Process#spawn`.
95
- #
96
- # * **Redirect to a file:** You can redirect to a file. This reads from
97
- # an existing file when connected to `:in`, and creates or appends to a
98
- # file when connected to `:out` or `:err`. To specify a file, use the
99
- # setting `[:file, "/path/to/file"]`. You can also, when writing a
100
- # file, append an optional mode and permission code to the array. For
101
- # example, `[:file, "/path/to/file", "a", 0644]`.
102
- #
103
- # * **Redirect to an IO object:** You can redirect to an IO object in the
104
- # parent process, by passing the IO object as the option value. You can
105
- # use any IO object. For example, you could connect the child's output
106
- # to the parent's error using `out: $stderr`, or you could connect to
107
- # an existing File stream. Unlike `Process#spawn`, this works for IO
108
- # objects that do not have a corresponding file descriptor (such as
109
- # StringIO objects). In such a case, a thread will be spawned to pipe
110
- # the IO data through to the child process.
111
- #
112
- # * **Redirect to a pipe:** You can redirect to a pipe created using
113
- # `IO.pipe` (i.e. a two-element array of read and write IO objects) by
114
- # passing the array as the option value. This will connect the
115
- # appropriate IO (either read or write), and close it in the parent.
116
- # Thus, you can connect only one process to each end. If you want more
117
- # direct control over IO closing behavior, pass the IO object (i.e. the
118
- # element of the pipe array) directly.
119
- #
120
- # * **Combine with another child stream:** You can redirect one child
121
- # output stream to another, to combine them. To merge the child's error
122
- # stream into its output stream, use `err: [:child, :out]`.
123
- #
124
- # * **Read from a string:** You can pass a string to the input stream by
125
- # setting `[:string, "the string"]`. This works only for `:in`.
126
- #
127
- # * **Capture output stream:** You can capture a stream and make it
128
- # available on the {Toys::Utils::Exec::Result} object, using the
129
- # setting `:capture`. This works only for the `:out` and `:err`
130
- # streams.
131
- #
132
- # * **Use the controller:** You can hook a stream to the controller using
133
- # the setting `:controller`. You can then manipulate the stream via the
134
- # controller. If you pass a block to {Toys::Utils::Exec#exec}, it
135
- # yields the {Toys::Utils::Exec::Controller}, giving you access to
136
- # streams.
137
- #
138
- # * **Make copies of an output stream:** You can "tee," or duplicate the
139
- # `:out` or `:err` stream and redirect those copies to various
140
- # destinations. To specify a tee, use the setting `[:tee, ...]` where
141
- # the additional array elements include two or more of the following.
142
- # See the corresponding documentation above for more detail.
143
- # * `:inherit` to direct to the parent process's stream.
144
- # * `:capture` to capture the stream and store it in the result.
145
- # * `:controller` to direct the stream to the controller.
146
- # * `[:file, "/path/to/file"]` to write to a file.
147
- # * An `IO` or `StringIO` object.
148
- # * An array of two `IO` objects representing a pipe
149
- #
150
- # Additionally, the last element of the array can be a hash of options.
151
- # Supported options include:
152
- # * `:buffer_size` The size of the memory buffer for each element of
153
- # the tee. Larger buffers may allow higher throughput. The default
154
- # is 65536.
155
- #
156
- # ### Result handling
157
- #
158
- # A subprocess result is represented by a {Toys::Utils::Exec::Result}
159
- # object, which includes the exit code, the content of any captured output
160
- # streams, and any exeption raised when attempting to run the process.
161
- # When you run a process in the foreground, the method will return a result
162
- # object. When you run a process in the background, you can obtain the
163
- # result from the controller once the process completes.
164
- #
165
- # The following example demonstrates running a process in the foreground
166
- # and getting the exit code:
167
- #
168
- # result = exec_service.exec(["git", "init"])
169
- # puts "exit code: #{result.exit_code}"
170
- #
171
- # The following example demonstrates starting a process in the background,
172
- # waiting for it to complete, and getting its exit code:
173
- #
174
- # controller = exec_service.exec(["git", "init"], background: true)
175
- # result = controller.result(timeout: 1.0)
176
- # if result
177
- # puts "exit code: #{result.exit_code}"
178
- # else
179
- # puts "timed out"
180
- # end
181
- #
182
- # You can also provide a callback that is executed once a process
183
- # completes. For example:
184
- #
185
- # my_callback = proc do |result|
186
- # puts "exit code: #{result.exit_code}"
187
- # end
188
- # exec_service.exec(["git", "init"], result_callback: my_callback)
189
- #
190
- # ### Configuration options
191
- #
192
- # A variety of options can be used to control subprocesses. These can be
193
- # provided to any method that starts a subprocess. Youc an also set
194
- # defaults by calling {Toys::Utils::Exec#configure_defaults}.
195
- #
196
- # Options that affect the behavior of subprocesses:
197
- #
198
- # * `:env` (Hash) Environment variables to pass to the subprocess.
199
- # Keys represent variable names and should be strings. Values should be
200
- # either strings or `nil`, which unsets the variable.
201
- #
202
- # * `:background` (Boolean) Runs the process in the background if `true`.
203
- #
204
- # * `:result_callback` (Proc) Called and passed the result object when
205
- # the subprocess exits.
206
- #
207
- # Options for connecting input and output streams. See the section above on
208
- # stream handling for info on the values that can be passed.
209
- #
210
- # * `:in` Connects the input stream of the subprocess. See the section on
211
- # stream handling.
212
- #
213
- # * `:out` Connects the standard output stream of the subprocess. See the
214
- # section on stream handling.
215
- #
216
- # * `:err` Connects the standard error stream of the subprocess. See the
217
- # section on stream handling.
218
- #
219
- # Options related to logging and reporting:
220
- #
221
- # * `:logger` (Logger) Logger to use for logging the actual command. If
222
- # not present, the command is not logged.
223
- #
224
- # * `:log_level` (Integer,false) Level for logging the actual command.
225
- # Defaults to Logger::INFO if not present. You can also pass `false` to
226
- # disable logging of the command.
227
- #
228
- # * `:log_cmd` (String) The string logged for the actual command.
229
- # Defaults to the `inspect` representation of the command.
230
- #
231
- # * `:name` (Object) An optional object that can be used to identify this
232
- # subprocess. It is available in the controller and result objects.
233
- #
234
- # In addition, the following options recognized by
235
- # [`Process#spawn`](https://ruby-doc.org/core/Process.html#method-c-spawn)
236
- # are supported.
237
- #
238
- # * `:chdir` (String) Set the working directory for the command.
239
- #
240
- # * `:close_others` (Boolean) Whether to close non-redirected
241
- # non-standard file descriptors.
242
- #
243
- # * `:new_pgroup` (Boolean) Create new process group (Windows only).
244
- #
245
- # * `:pgroup` (Integer,true,nil) The process group setting.
246
- #
247
- # * `:umask` (Integer) Umask setting for the new process.
248
- #
249
- # * `:unsetenv_others` (Boolean) Clear environment variables except those
250
- # explicitly set.
251
- #
252
- # Any other option key will result in an `ArgumentError`.
253
- #
254
- class Exec
255
- ##
256
- # Create an exec service.
257
- #
258
- # @param block [Proc] A block that is called if a key is not found. It is
259
- # passed the unknown key, and expected to return a default value
260
- # (which can be nil).
261
- # @param opts [keywords] Initial default options. See {Toys::Utils::Exec}
262
- # for a description of the options.
263
- #
264
- def initialize(**opts, &block)
265
- # Source available in the toys-core gem
266
- end
267
-
268
- ##
269
- # Set default options. See {Toys::Utils::Exec} for a description of the
270
- # options.
271
- #
272
- # @param opts [keywords] New default options to set
273
- # @return [self]
274
- #
275
- def configure_defaults(**opts)
276
- # Source available in the toys-core gem
277
- end
278
-
279
- ##
280
- # Execute a command. The command can be given as a single string to pass
281
- # to a shell, or an array of strings indicating a posix command.
282
- #
283
- # If the process is not set to run in the background, and a block is
284
- # provided, a {Toys::Utils::Exec::Controller} will be yielded to it.
285
- #
286
- # @param cmd [String,Array<String>] The command to execute.
287
- # @param opts [keywords] The command options. See the section on
288
- # configuration options in the {Toys::Utils::Exec} class docs.
289
- # @yieldparam controller [Toys::Utils::Exec::Controller] A controller
290
- # for the subprocess streams.
291
- #
292
- # @return [Toys::Utils::Exec::Controller] The subprocess controller, if
293
- # the process is running in the background.
294
- # @return [Toys::Utils::Exec::Result] The result, if the process ran in
295
- # the foreground.
296
- #
297
- def exec(cmd, **opts, &block)
298
- # Source available in the toys-core gem
299
- end
300
-
301
- ##
302
- # Spawn a ruby process and pass the given arguments to it.
303
- #
304
- # If the process is not set to run in the background, and a block is
305
- # provided, a {Toys::Utils::Exec::Controller} will be yielded to it.
306
- #
307
- # @param args [String,Array<String>] The arguments to ruby.
308
- # @param opts [keywords] The command options. See the section on
309
- # configuration options in the {Toys::Utils::Exec} class docs.
310
- # @yieldparam controller [Toys::Utils::Exec::Controller] A controller
311
- # for the subprocess streams.
312
- #
313
- # @return [Toys::Utils::Exec::Controller] The subprocess controller, if
314
- # the process is running in the background.
315
- # @return [Toys::Utils::Exec::Result] The result, if the process ran in
316
- # the foreground.
317
- #
318
- def exec_ruby(args, **opts, &block)
319
- # Source available in the toys-core gem
320
- end
321
- alias ruby exec_ruby
322
-
323
- ##
324
- # Execute a proc in a fork.
325
- #
326
- # If the process is not set to run in the background, and a block is
327
- # provided, a {Toys::Utils::Exec::Controller} will be yielded to it.
328
- #
329
- # @param func [Proc] The proc to call.
330
- # @param opts [keywords] The command options. See the section on
331
- # configuration options in the {Toys::Utils::Exec} class docs.
332
- # @yieldparam controller [Toys::Utils::Exec::Controller] A controller
333
- # for the subprocess streams.
334
- #
335
- # @return [Toys::Utils::Exec::Controller] The subprocess controller, if
336
- # the process is running in the background.
337
- # @return [Toys::Utils::Exec::Result] The result, if the process ran in
338
- # the foreground.
339
- #
340
- def exec_proc(func, **opts, &block)
341
- # Source available in the toys-core gem
342
- end
343
-
344
- ##
345
- # Execute a command. The command can be given as a single string to pass
346
- # to a shell, or an array of strings indicating a posix command.
347
- #
348
- # Captures standard out and returns it as a string.
349
- # Cannot be run in the background.
350
- #
351
- # If a block is provided, a {Toys::Utils::Exec::Controller} will be
352
- # yielded to it.
353
- #
354
- # @param cmd [String,Array<String>] The command to execute.
355
- # @param opts [keywords] The command options. See the section on
356
- # configuration options in the {Toys::Utils::Exec} class docs.
357
- # @yieldparam controller [Toys::Utils::Exec::Controller] A controller
358
- # for the subprocess streams.
359
- #
360
- # @return [String] What was written to standard out.
361
- #
362
- def capture(cmd, **opts, &block)
363
- # Source available in the toys-core gem
364
- end
365
-
366
- ##
367
- # Spawn a ruby process and pass the given arguments to it.
368
- #
369
- # Captures standard out and returns it as a string.
370
- # Cannot be run in the background.
371
- #
372
- # If a block is provided, a {Toys::Utils::Exec::Controller} will be
373
- # yielded to it.
374
- #
375
- # @param args [String,Array<String>] The arguments to ruby.
376
- # @param opts [keywords] The command options. See the section on
377
- # configuration options in the {Toys::Utils::Exec} class docs.
378
- # @yieldparam controller [Toys::Utils::Exec::Controller] A controller
379
- # for the subprocess streams.
380
- #
381
- # @return [String] What was written to standard out.
382
- #
383
- def capture_ruby(args, **opts, &block)
384
- # Source available in the toys-core gem
385
- end
386
-
387
- ##
388
- # Execute a proc in a fork.
389
- #
390
- # Captures standard out and returns it as a string.
391
- # Cannot be run in the background.
392
- #
393
- # If a block is provided, a {Toys::Utils::Exec::Controller} will be
394
- # yielded to it.
395
- #
396
- # @param func [Proc] The proc to call.
397
- # @param opts [keywords] The command options. See the section on
398
- # configuration options in the {Toys::Utils::Exec} class docs.
399
- # @yieldparam controller [Toys::Utils::Exec::Controller] A controller
400
- # for the subprocess streams.
401
- #
402
- # @return [String] What was written to standard out.
403
- #
404
- def capture_proc(func, **opts, &block)
405
- # Source available in the toys-core gem
406
- end
407
-
408
- ##
409
- # Execute the given string in a shell. Returns the exit code.
410
- # Cannot be run in the background.
411
- #
412
- # If a block is provided, a {Toys::Utils::Exec::Controller} will be
413
- # yielded to it.
414
- #
415
- # @param cmd [String] The shell command to execute.
416
- # @param opts [keywords] The command options. See the section on
417
- # configuration options in the {Toys::Utils::Exec} class docs.
418
- # @yieldparam controller [Toys::Utils::Exec::Controller] A controller
419
- # for the subprocess streams.
420
- #
421
- # @return [Integer] The exit code
422
- #
423
- def sh(cmd, **opts, &block)
424
- # Source available in the toys-core gem
425
- end
426
-
427
- ##
428
- # **_Defined in the toys-core gem_**
429
- #
430
- # An object that controls a subprocess. This object is returned from an
431
- # execution running in the background, or is yielded to a control block
432
- # for an execution running in the foreground.
433
- # You can use this object to interact with the subcommand's streams,
434
- # send signals to the process, and get its result.
435
- #
436
- class Controller
437
- ##
438
- # The subcommand's name.
439
- # @return [Object]
440
- #
441
- attr_reader :name
442
-
443
- ##
444
- # The subcommand's standard input stream (which can be written to).
445
- #
446
- # @return [IO] if the command was configured with `in: :controller`
447
- # @return [nil] if the command was not configured with
448
- # `in: :controller`
449
- #
450
- attr_reader :in
451
-
452
- ##
453
- # The subcommand's standard output stream (which can be read from).
454
- #
455
- # @return [IO] if the command was configured with `out: :controller`
456
- # @return [nil] if the command was not configured with
457
- # `out: :controller`
458
- #
459
- attr_reader :out
460
-
461
- ##
462
- # The subcommand's standard error stream (which can be read from).
463
- #
464
- # @return [IO] if the command was configured with `err: :controller`
465
- # @return [nil] if the command was not configured with
466
- # `err: :controller`
467
- #
468
- attr_reader :err
469
-
470
- ##
471
- # The process ID.
472
- #
473
- # Exactly one of {#exception} and {#pid} will be non-nil.
474
- #
475
- # @return [Integer] if the process start was successful
476
- # @return [nil] if the process could not be started.
477
- #
478
- attr_reader :pid
479
-
480
- ##
481
- # The exception raised when the process failed to start.
482
- #
483
- # Exactly one of {#exception} and {#pid} will be non-nil.
484
- #
485
- # @return [Exception] if the process failed to start.
486
- # @return [nil] if the process start was successful.
487
- #
488
- attr_reader :exception
489
-
490
- ##
491
- # Captures the remaining data in the given stream.
492
- # After calling this, do not read directly from the stream.
493
- #
494
- # @param which [:out,:err] Which stream to capture
495
- # @return [self]
496
- #
497
- def capture(which)
498
- # Source available in the toys-core gem
499
- end
500
-
501
- ##
502
- # Captures the remaining data in the standard output stream.
503
- # After calling this, do not read directly from the stream.
504
- #
505
- # @return [self]
506
- #
507
- def capture_out
508
- # Source available in the toys-core gem
509
- end
510
-
511
- ##
512
- # Captures the remaining data in the standard error stream.
513
- # After calling this, do not read directly from the stream.
514
- #
515
- # @return [self]
516
- #
517
- def capture_err
518
- # Source available in the toys-core gem
519
- end
520
-
521
- ##
522
- # Redirects the remainder of the given stream.
523
- #
524
- # You can specify the stream as an IO or IO-like object, or as a file
525
- # specified by its path. If specifying a file, you can optionally
526
- # provide the mode and permissions for the call to `File#open`. You can
527
- # also specify the value `:null` to indicate the null file.
528
- #
529
- # After calling this, do not interact directly with the stream.
530
- #
531
- # @param which [:in,:out,:err] Which stream to redirect
532
- # @param io [IO,StringIO,String,:null] Where to redirect the stream
533
- # @param io_args [Object...] The mode and permissions for opening the
534
- # file, if redirecting to/from a file.
535
- # @return [self]
536
- #
537
- def redirect(which, io, *io_args)
538
- # Source available in the toys-core gem
539
- end
540
-
541
- ##
542
- # Redirects the remainder of the standard input stream.
543
- #
544
- # You can specify the stream as an IO or IO-like object, or as a file
545
- # specified by its path. If specifying a file, you can optionally
546
- # provide the mode and permissions for the call to `File#open`. You can
547
- # also specify the value `:null` to indicate the null file.
548
- #
549
- # After calling this, do not interact directly with the stream.
550
- #
551
- # @param io [IO,StringIO,String,:null] Where to redirect the stream
552
- # @param io_args [Object...] The mode and permissions for opening the
553
- # file, if redirecting from a file.
554
- # @return [self]
555
- #
556
- def redirect_in(io, *io_args)
557
- # Source available in the toys-core gem
558
- end
559
-
560
- ##
561
- # Redirects the remainder of the standard output stream.
562
- #
563
- # You can specify the stream as an IO or IO-like object, or as a file
564
- # specified by its path. If specifying a file, you can optionally
565
- # provide the mode and permissions for the call to `File#open`. You can
566
- # also specify the value `:null` to indicate the null file.
567
- #
568
- # After calling this, do not interact directly with the stream.
569
- #
570
- # @param io [IO,StringIO,String,:null] Where to redirect the stream
571
- # @param io_args [Object...] The mode and permissions for opening the
572
- # file, if redirecting to a file.
573
- # @return [self]
574
- #
575
- def redirect_out(io, *io_args)
576
- # Source available in the toys-core gem
577
- end
578
-
579
- ##
580
- # Redirects the remainder of the standard error stream.
581
- #
582
- # You can specify the stream as an IO or IO-like object, or as a file
583
- # specified by its path. If specifying a file, you can optionally
584
- # provide the mode and permissions for the call to `File#open`.
585
- #
586
- # After calling this, do not interact directly with the stream.
587
- #
588
- # @param io [IO,StringIO,String] Where to redirect the stream
589
- # @param io_args [Object...] The mode and permissions for opening the
590
- # file, if redirecting to a file.
591
- # @return [self]
592
- #
593
- def redirect_err(io, *io_args)
594
- # Source available in the toys-core gem
595
- end
596
-
597
- ##
598
- # Send the given signal to the process. The signal can be specified
599
- # by name or number.
600
- #
601
- # @param sig [Integer,String] The signal to send.
602
- # @return [self]
603
- #
604
- def kill(sig)
605
- # Source available in the toys-core gem
606
- end
607
- alias signal kill
608
-
609
- ##
610
- # Determine whether the subcommand is still executing
611
- #
612
- # @return [Boolean]
613
- #
614
- def executing?
615
- # Source available in the toys-core gem
616
- end
617
-
618
- ##
619
- # Wait for the subcommand to complete, and return a result object.
620
- #
621
- # Closes the control streams if present. The stdin stream is always
622
- # closed, even if the call times out. The stdout and stderr streams are
623
- # closed only after the command terminates.
624
- #
625
- # @param timeout [Numeric,nil] The timeout in seconds, or `nil` to
626
- # wait indefinitely.
627
- # @return [Toys::Utils::Exec::Result] The result object
628
- # @return [nil] if a timeout occurred.
629
- #
630
- def result(timeout: nil)
631
- # Source available in the toys-core gem
632
- end
633
- end
634
-
635
- ##
636
- # **_Defined in the toys-core gem_**
637
- #
638
- # The result returned from a subcommand execution. This includes the
639
- # identifying name of the execution (if any), the result status of the
640
- # execution, and any captured stream output.
641
- #
642
- # Possible result statuses are:
643
- #
644
- # * The process failed to start. {Result#failed?} will return true, and
645
- # {Result#exception} will return an exception describing the failure
646
- # (often an errno).
647
- # * The process executed and exited with a normal exit code. Either
648
- # {Result#success?} or {Result#error?} will return true, and
649
- # {Result.exit_code} will return the numeric exit code.
650
- # * The process executed but was terminated by an uncaught signal.
651
- # {Result#signaled?} will return true, and {Result#signal_code} will
652
- # return the numeric signal code.
653
- #
654
- class Result
655
- ##
656
- # The subcommand's name.
657
- #
658
- # @return [Object]
659
- #
660
- attr_reader :name
661
-
662
- ##
663
- # The captured output string.
664
- #
665
- # @return [String] The string captured from stdout.
666
- # @return [nil] if the command was not configured to capture stdout.
667
- #
668
- attr_reader :captured_out
669
-
670
- ##
671
- # The captured error string.
672
- #
673
- # @return [String] The string captured from stderr.
674
- # @return [nil] if the command was not configured to capture stderr.
675
- #
676
- attr_reader :captured_err
677
-
678
- ##
679
- # The Ruby process status object, providing various information about
680
- # the ending state of the process.
681
- #
682
- # Exactly one of {#exception} and {#status} will be non-nil.
683
- #
684
- # @return [Process::Status] The status, if the process was successfully
685
- # spanwed and terminated.
686
- # @return [nil] if the process could not be started.
687
- #
688
- attr_reader :status
689
-
690
- ##
691
- # The exception raised if a process couldn't be started.
692
- #
693
- # Exactly one of {#exception} and {#status} will be non-nil.
694
- # Exactly one of {#exception}, {#exit_code}, or {#signal_code} will be
695
- # non-nil.
696
- #
697
- # @return [Exception] The exception raised from process start.
698
- # @return [nil] if the process started successfully.
699
- #
700
- attr_reader :exception
701
-
702
- ##
703
- # The numeric status code for a process that exited normally,
704
- #
705
- # Exactly one of {#exception}, {#exit_code}, or {#signal_code} will be
706
- # non-nil.
707
- #
708
- # @return [Integer] the numeric status code, if the process started
709
- # successfully and exited normally.
710
- # @return [nil] if the process did not start successfully, or was
711
- # terminated by an uncaught signal.
712
- #
713
- def exit_code
714
- # Source available in the toys-core gem
715
- end
716
-
717
- ##
718
- # The numeric signal code that caused process termination.
719
- #
720
- # Exactly one of {#exception}, {#exit_code}, or {#signal_code} will be
721
- # non-nil.
722
- #
723
- # @return [Integer] The signal that caused the process to terminate.
724
- # @return [nil] if the process did not start successfully, or executed
725
- # and exited with a normal exit code.
726
- #
727
- def signal_code
728
- # Source available in the toys-core gem
729
- end
730
- alias term_signal signal_code
731
-
732
- ##
733
- # Returns true if the subprocess failed to start, or false if the
734
- # process was able to execute.
735
- #
736
- # @return [Boolean]
737
- #
738
- def failed?
739
- # Source available in the toys-core gem
740
- end
741
-
742
- ##
743
- # Returns true if the subprocess terminated due to an unhandled signal,
744
- # or false if the process failed to start or exited normally.
745
- #
746
- # @return [Boolean]
747
- #
748
- def signaled?
749
- # Source available in the toys-core gem
750
- end
751
-
752
- ##
753
- # Returns true if the subprocess terminated with a zero status, or
754
- # false if the process failed to start, terminated due to a signal, or
755
- # returned a nonzero status.
756
- #
757
- # @return [Boolean]
758
- #
759
- def success?
760
- # Source available in the toys-core gem
761
- end
762
-
763
- ##
764
- # Returns true if the subprocess terminated with a nonzero status, or
765
- # false if the process failed to start, terminated due to a signal, or
766
- # returned a zero status.
767
- #
768
- # @return [Boolean]
769
- #
770
- def error?
771
- # Source available in the toys-core gem
772
- end
773
- end
774
- end
775
- end
776
- end