toys 0.20.0 → 0.21.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/CHANGELOG.md +31 -0
- data/builtins/system/bash-completion.rb +2 -2
- data/builtins/system/zsh-completion.rb +2 -2
- data/core-docs/toys/core.rb +1 -1
- data/core-docs/toys/settings.rb +21 -2
- data/core-docs/toys/standard_middleware/show_help.rb +7 -7
- data/core-docs/toys/standard_middleware/show_root_version.rb +1 -1
- data/core-docs/toys/standard_mixins/bundler.rb +2 -1
- data/core-docs/toys/standard_mixins/exec.rb +74 -32
- data/core-docs/toys/standard_mixins/xdg.rb +1 -1
- data/core-docs/toys/utils/exec.rb +111 -49
- data/core-docs/toys/utils/gems.rb +7 -1
- data/core-docs/toys/utils/git_cache.rb +24 -9
- data/core-docs/toys/utils/xdg.rb +114 -11
- data/lib/toys/templates/clean.rb +1 -1
- data/lib/toys/version.rb +1 -1
- metadata +7 -7
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 87582d55a2f60738d19c3c4d717f93910c5cc677f5e210c8418366baf2e91921
|
|
4
|
+
data.tar.gz: f82f165fa06113b1ad398c5cb2d5e62217d860924f00e5b0d3b6172824d4a116
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5a9dad0dcdd8c83d678dfe23522faaa38b62bb765e16f7b6aafce2ce014920d13addce0d32a619f4c5d80e21f8e79b40ff8c0936381169df17d080d3d2500aec
|
|
7
|
+
data.tar.gz: 0f2b4c0cc5cf87ed070d7f21d57f8a9b2051277c5651f5e4d210b9ebb2a9498df93dde3203cb54437c19f8991ed348ab3b9d59c5a944c3070aa22e09a7cdd14e
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,36 @@
|
|
|
1
1
|
# Release History
|
|
2
2
|
|
|
3
|
+
### v0.21.0 / 2026-03-23
|
|
4
|
+
|
|
5
|
+
This release includes a variety of small fixes and updates toward improving product polish in preparation for a 1.0 release. It focuses on the following areas:
|
|
6
|
+
|
|
7
|
+
* Updates to the help system
|
|
8
|
+
* FIXED / BREAKING CHANGE: The help middleware omits the subtool filter flags on runnable tools that have subtools
|
|
9
|
+
* Updates to bundler integration
|
|
10
|
+
* FIXED: Fixed some cleanup issues when bundler setup fails
|
|
11
|
+
* Updates to the exec utility
|
|
12
|
+
* ADDED: Support for the `:unbundle` option which removes any existing bundle for a subprocess
|
|
13
|
+
* FIXED: Fixed several thread-safety issues with the controller
|
|
14
|
+
* FIXED: The result callback is now called in background mode if the result is never explicitly obtained from the controller
|
|
15
|
+
* Updates to the git_cache utility
|
|
16
|
+
* ADDED: Support for filtering lookups of ref and source info
|
|
17
|
+
* ADDED: Support for SHA-256 repos
|
|
18
|
+
* FIXED: Fixed failure to get a parent directory after previously getting a descendant object
|
|
19
|
+
* FIXED: GitCache no longer unnecessarily sets the write bit on files copied into a specified directory
|
|
20
|
+
* FIXED: GitCache no longer cleans out existing files when writing to a shared source, which should reduce issues with concurrent clients
|
|
21
|
+
* Updates to the XDG utility
|
|
22
|
+
* FIXED / BREAKING CHANGE: The XDG utility returns an empty array (instead of the system defaults) from the corresponding methods if `XDG_DATA_DIRS` or `XDG_CONFIG_DIRS` is nonempty but contains only relative paths
|
|
23
|
+
* ADDED: Provided `lookup_state` and `lookup_cache` methods on the XDG utility
|
|
24
|
+
* Updates to the settings system:
|
|
25
|
+
* FIXED: Block certain reserved names from being used as Settings field names
|
|
26
|
+
* FIXED: Fixed `Settings#load_data!` when subclassing another settings class
|
|
27
|
+
* FIXED: Reject non-String values in Settings regexp type spec
|
|
28
|
+
* FIXED: Settings guards against unknown classes when loading YAML on older Ruby versions
|
|
29
|
+
* FIXED: Settings guards against `ILLEGAL_VALUE` being passed to `range.member?`
|
|
30
|
+
* FIXED: Settings does a better job choosing exact-match values when using a union type
|
|
31
|
+
* FIXED: Settings reject non-numeric strings in Integer and Float converters
|
|
32
|
+
* FIXED: Settings propagates nested group errors in `Settings#load_data!`
|
|
33
|
+
|
|
3
34
|
### v0.20.0 / 2026-03-09
|
|
4
35
|
|
|
5
36
|
Toys 0.20 is a major release with several new features and a number of fixes, including a few minor breaking changes.
|
|
@@ -60,7 +60,7 @@ tool "install" do
|
|
|
60
60
|
require "shellwords"
|
|
61
61
|
path = ::File.join(::File.dirname(::File.dirname(__dir__)), "share", "bash-completion.sh")
|
|
62
62
|
exes = executable_names.empty? ? [::Toys::StandardCLI::EXECUTABLE_NAME] : executable_names
|
|
63
|
-
puts Shellwords.join(["source", path] + exes)
|
|
63
|
+
puts ::Shellwords.join(["source", path] + exes)
|
|
64
64
|
end
|
|
65
65
|
end
|
|
66
66
|
|
|
@@ -84,6 +84,6 @@ tool "remove" do
|
|
|
84
84
|
require "shellwords"
|
|
85
85
|
path = ::File.join(::File.dirname(::File.dirname(__dir__)), "share", "bash-completion-remove.sh")
|
|
86
86
|
exes = executable_names.empty? ? [::Toys::StandardCLI::EXECUTABLE_NAME] : executable_names
|
|
87
|
-
puts Shellwords.join(["source", path] + exes)
|
|
87
|
+
puts ::Shellwords.join(["source", path] + exes)
|
|
88
88
|
end
|
|
89
89
|
end
|
|
@@ -40,7 +40,7 @@ tool "install" do
|
|
|
40
40
|
require "shellwords"
|
|
41
41
|
path = ::File.join(::File.dirname(::File.dirname(__dir__)), "share", "zsh-completion.sh")
|
|
42
42
|
exes = executable_names.empty? ? [::Toys::StandardCLI::EXECUTABLE_NAME] : executable_names
|
|
43
|
-
puts Shellwords.join(["source", path] + exes)
|
|
43
|
+
puts ::Shellwords.join(["source", path] + exes)
|
|
44
44
|
end
|
|
45
45
|
end
|
|
46
46
|
|
|
@@ -64,7 +64,7 @@ tool "remove" do
|
|
|
64
64
|
require "shellwords"
|
|
65
65
|
path = ::File.join(::File.dirname(::File.dirname(__dir__)), "share", "zsh-completion-remove.sh")
|
|
66
66
|
exes = executable_names.empty? ? [::Toys::StandardCLI::EXECUTABLE_NAME] : executable_names
|
|
67
|
-
puts Shellwords.join(["source", path] + exes)
|
|
67
|
+
puts ::Shellwords.join(["source", path] + exes)
|
|
68
68
|
end
|
|
69
69
|
end
|
|
70
70
|
|
data/core-docs/toys/core.rb
CHANGED
data/core-docs/toys/settings.rb
CHANGED
|
@@ -35,8 +35,12 @@ module Toys
|
|
|
35
35
|
# Attribute names must start with an ascii letter, and may contain only ascii
|
|
36
36
|
# letters, digits, and underscores. Unlike method names, they may not include
|
|
37
37
|
# non-ascii unicode characters, nor may they end with `!` or `?`.
|
|
38
|
-
# Additionally,
|
|
39
|
-
#
|
|
38
|
+
# Additionally, some names are reserved because they would shadow critical
|
|
39
|
+
# Ruby methods or interfere with Settings' internal behavior (see
|
|
40
|
+
# {Toys::Settings::RESERVED_FIELD_NAMES} for the complete list, which
|
|
41
|
+
# currently includes names such as `class`, `clone`, `dup`, `freeze`, `hash`,
|
|
42
|
+
# `initialize`, `method_missing`, `object_id`, `public_send`, `raise`,
|
|
43
|
+
# `require`, and `send`).
|
|
40
44
|
#
|
|
41
45
|
# Each attribute defines four methods: a getter, a setter, an unsetter, and a
|
|
42
46
|
# set detector. In the above example, the attribute named `:endpoint` creates
|
|
@@ -297,12 +301,27 @@ module Toys
|
|
|
297
301
|
# grandchild_settings.str # => "value_from_root"
|
|
298
302
|
#
|
|
299
303
|
class Settings
|
|
304
|
+
##
|
|
300
305
|
# A special value indicating a type check failure.
|
|
306
|
+
#
|
|
301
307
|
ILLEGAL_VALUE = ::Object.new.freeze
|
|
302
308
|
|
|
309
|
+
##
|
|
303
310
|
# A special type specification indicating infer from the default value.
|
|
311
|
+
#
|
|
304
312
|
DEFAULT_TYPE = ::Object.new.freeze
|
|
305
313
|
|
|
314
|
+
##
|
|
315
|
+
# Field names that are not allowed because they would shadow critical Ruby
|
|
316
|
+
# methods or break Settings' own internal method calls.
|
|
317
|
+
#
|
|
318
|
+
# @return [Array<String>]
|
|
319
|
+
#
|
|
320
|
+
RESERVED_FIELD_NAMES = [
|
|
321
|
+
"class", "clone", "dup", "freeze", "hash", "initialize",
|
|
322
|
+
"method_missing", "object_id", "public_send", "raise", "require", "send"
|
|
323
|
+
].freeze
|
|
324
|
+
|
|
306
325
|
##
|
|
307
326
|
# **_Defined in the toys-core gem_**
|
|
308
327
|
#
|
|
@@ -53,43 +53,43 @@ module Toys
|
|
|
53
53
|
# Key set when the show help flag is present
|
|
54
54
|
# @return [Object]
|
|
55
55
|
#
|
|
56
|
-
SHOW_HELP_KEY = Object.new.freeze
|
|
56
|
+
SHOW_HELP_KEY = ::Object.new.freeze
|
|
57
57
|
|
|
58
58
|
##
|
|
59
59
|
# Key set when the show usage flag is present
|
|
60
60
|
# @return [Object]
|
|
61
61
|
#
|
|
62
|
-
SHOW_USAGE_KEY = Object.new.freeze
|
|
62
|
+
SHOW_USAGE_KEY = ::Object.new.freeze
|
|
63
63
|
|
|
64
64
|
##
|
|
65
65
|
# Key set when the show subtool list flag is present
|
|
66
66
|
# @return [Object]
|
|
67
67
|
#
|
|
68
|
-
SHOW_LIST_KEY = Object.new.freeze
|
|
68
|
+
SHOW_LIST_KEY = ::Object.new.freeze
|
|
69
69
|
|
|
70
70
|
##
|
|
71
71
|
# Key for the recursive setting
|
|
72
72
|
# @return [Object]
|
|
73
73
|
#
|
|
74
|
-
RECURSIVE_SUBTOOLS_KEY = Object.new.freeze
|
|
74
|
+
RECURSIVE_SUBTOOLS_KEY = ::Object.new.freeze
|
|
75
75
|
|
|
76
76
|
##
|
|
77
77
|
# Key for the search string
|
|
78
78
|
# @return [Object]
|
|
79
79
|
#
|
|
80
|
-
SEARCH_STRING_KEY = Object.new.freeze
|
|
80
|
+
SEARCH_STRING_KEY = ::Object.new.freeze
|
|
81
81
|
|
|
82
82
|
##
|
|
83
83
|
# Key for the show-all-subtools setting
|
|
84
84
|
# @return [Object]
|
|
85
85
|
#
|
|
86
|
-
SHOW_ALL_SUBTOOLS_KEY = Object.new.freeze
|
|
86
|
+
SHOW_ALL_SUBTOOLS_KEY = ::Object.new.freeze
|
|
87
87
|
|
|
88
88
|
##
|
|
89
89
|
# Key for the tool name
|
|
90
90
|
# @return [Object]
|
|
91
91
|
#
|
|
92
|
-
TOOL_NAME_KEY = Object.new.freeze
|
|
92
|
+
TOOL_NAME_KEY = ::Object.new.freeze
|
|
93
93
|
|
|
94
94
|
##
|
|
95
95
|
# Create a ShowHelp middleware.
|
|
@@ -23,7 +23,8 @@ module Toys
|
|
|
23
23
|
# The following parameters can be passed when including this mixin:
|
|
24
24
|
#
|
|
25
25
|
# * `:static` (Boolean) Has the same effect as passing `:static` to the
|
|
26
|
-
# `:setup` parameter.
|
|
26
|
+
# `:setup` parameter. This is present largely for historical
|
|
27
|
+
# compatibility, but it is supported and _not_ deprecated.
|
|
27
28
|
#
|
|
28
29
|
# * `:setup` (:auto,:manual,:static) A symbol indicating when the bundle
|
|
29
30
|
# should be installed. Possible values are:
|
|
@@ -35,36 +35,6 @@ module Toys
|
|
|
35
35
|
# but you can also retrieve the service object itself by calling
|
|
36
36
|
# {Toys::Context#get} with the key {Toys::StandardMixins::Exec::KEY}.
|
|
37
37
|
#
|
|
38
|
-
# ### Controlling processes
|
|
39
|
-
#
|
|
40
|
-
# A process can be started in the *foreground* or the *background*. If you
|
|
41
|
-
# start a foreground process, it will "take over" your standard input and
|
|
42
|
-
# output streams by default, and it will keep control until it completes.
|
|
43
|
-
# If you start a background process, its streams will be redirected to null
|
|
44
|
-
# by default, and control will be returned to you immediately.
|
|
45
|
-
#
|
|
46
|
-
# While a process is running, you can control it using a
|
|
47
|
-
# {Toys::Utils::Exec::Controller} object. Use a controller to interact with
|
|
48
|
-
# the process's input and output streams, send it signals, or wait for it
|
|
49
|
-
# to complete.
|
|
50
|
-
#
|
|
51
|
-
# When running a process in the foreground, the controller will be yielded
|
|
52
|
-
# to an optional block. For example, the following code starts a process in
|
|
53
|
-
# the foreground and passes its output stream to a controller.
|
|
54
|
-
#
|
|
55
|
-
# exec(["git", "init"], out: :controller) do |controller|
|
|
56
|
-
# loop do
|
|
57
|
-
# line = controller.out.gets
|
|
58
|
-
# break if line.nil?
|
|
59
|
-
# puts "Got line: #{line}"
|
|
60
|
-
# end
|
|
61
|
-
# end
|
|
62
|
-
#
|
|
63
|
-
# When running a process in the background, the controller is returned from
|
|
64
|
-
# the method that starts the process:
|
|
65
|
-
#
|
|
66
|
-
# controller = exec(["git", "init"], background: true)
|
|
67
|
-
#
|
|
68
38
|
# ### Stream handling
|
|
69
39
|
#
|
|
70
40
|
# By default, subprocess streams are connected to the corresponding streams
|
|
@@ -84,7 +54,7 @@ module Toys
|
|
|
84
54
|
#
|
|
85
55
|
# * **Inherit parent stream:** You can inherit the corresponding stream
|
|
86
56
|
# in the parent process by passing `:inherit` as the option value. This
|
|
87
|
-
# is the default if the subprocess is
|
|
57
|
+
# is the default if the subprocess is run in the foreground.
|
|
88
58
|
#
|
|
89
59
|
# * **Redirect to null:** You can redirect to a null stream by passing
|
|
90
60
|
# `:null` as the option value. This connects to a stream that is not
|
|
@@ -136,7 +106,7 @@ module Toys
|
|
|
136
106
|
# the setting `:controller`. You can then manipulate the stream via the
|
|
137
107
|
# controller. If you pass a block to {Toys::StandardMixins::Exec#exec},
|
|
138
108
|
# it yields the {Toys::Utils::Exec::Controller}, giving you access to
|
|
139
|
-
# streams.
|
|
109
|
+
# streams. See the section below on controlling processes.
|
|
140
110
|
#
|
|
141
111
|
# * **Make copies of an output stream:** You can "tee," or duplicate the
|
|
142
112
|
# `:out` or `:err` stream and redirect those copies to various
|
|
@@ -156,6 +126,68 @@ module Toys
|
|
|
156
126
|
# the tee. Larger buffers may allow higher throughput. The default
|
|
157
127
|
# is 65536.
|
|
158
128
|
#
|
|
129
|
+
# ### Controlling processes
|
|
130
|
+
#
|
|
131
|
+
# A process can be started in the *foreground* or the *background*. If you
|
|
132
|
+
# start a foreground process, it will inherit your standard input and
|
|
133
|
+
# output streams by default, and it will keep control until it completes.
|
|
134
|
+
# If you start a background process, its streams will be redirected to null
|
|
135
|
+
# by default, and control will be returned to you immediately.
|
|
136
|
+
#
|
|
137
|
+
# While a process is running, you can control it using a
|
|
138
|
+
# {Toys::Utils::Exec::Controller} object. Use a controller to interact with
|
|
139
|
+
# the process's input and output streams, send it signals, or wait for it
|
|
140
|
+
# to complete.
|
|
141
|
+
#
|
|
142
|
+
# When running a process in the foreground, the controller will be yielded
|
|
143
|
+
# to an optional block. For example, the following code starts a process in
|
|
144
|
+
# the foreground and passes its output stream to a controller.
|
|
145
|
+
#
|
|
146
|
+
# exec(["git", "init"], out: :controller) do |controller|
|
|
147
|
+
# loop do
|
|
148
|
+
# line = controller.out.gets
|
|
149
|
+
# break if line.nil?
|
|
150
|
+
# puts "Got line: #{line}"
|
|
151
|
+
# end
|
|
152
|
+
# end
|
|
153
|
+
#
|
|
154
|
+
# At the end of the block, if the controller is handling the process's
|
|
155
|
+
# input stream, that stream will automatically be closed. The following
|
|
156
|
+
# example programmatically sends data to the `wc` unix program, and
|
|
157
|
+
# captures its output. Because the controller is handling the input stream,
|
|
158
|
+
# it automatically closes the stream at the end of the block, which causes
|
|
159
|
+
# `wc` to end.
|
|
160
|
+
#
|
|
161
|
+
# result = exec(["wc"], in: :controller, out: :capture) do |controller|
|
|
162
|
+
# controller.in.puts "Hello, world!"
|
|
163
|
+
# end
|
|
164
|
+
# puts "Results: #{result.captured_out}"
|
|
165
|
+
#
|
|
166
|
+
# Otherwise, depending on the process's behavior, it may continue to run
|
|
167
|
+
# after the end of the block. Control will not be returned to the caller
|
|
168
|
+
# until the process actually terminates. Conversely, it is also possible
|
|
169
|
+
# the process could terminate by itself while the block is still executing.
|
|
170
|
+
# You can call controller methods to obtain the process's actual current
|
|
171
|
+
# state.
|
|
172
|
+
#
|
|
173
|
+
# When running a process in the background, the controller is returned
|
|
174
|
+
# immediately from the method that starts the process. In the following
|
|
175
|
+
# example, git init is kicked off in the background and the output is
|
|
176
|
+
# thrown away to /dev/null.
|
|
177
|
+
#
|
|
178
|
+
# controller = exec(["git", "init"], background: true)
|
|
179
|
+
#
|
|
180
|
+
# In this mode, use the returned controller to query the process's state
|
|
181
|
+
# and interact with it. Streams directed to the controller are not
|
|
182
|
+
# automatically closed, so you will need to do so yourself. Following is an
|
|
183
|
+
# example of running `wc` in the background:
|
|
184
|
+
#
|
|
185
|
+
# controller = exec(["wc"], background: true,
|
|
186
|
+
# in: :controller, out: :controller)
|
|
187
|
+
# controller.in.puts "Hello, world!"
|
|
188
|
+
# controller.in.close # Do this explicitly to cause wc to finish
|
|
189
|
+
# puts "Results: #{controller.out.read}" # Read the entire stream
|
|
190
|
+
#
|
|
159
191
|
# ### Result handling
|
|
160
192
|
#
|
|
161
193
|
# A subprocess result is represented by a {Toys::Utils::Exec::Result}
|
|
@@ -193,6 +225,12 @@ module Toys
|
|
|
193
225
|
# puts "exit code: #{result.exit_code}"
|
|
194
226
|
# end
|
|
195
227
|
#
|
|
228
|
+
# In foreground mode, the callback is executed in the calling thread, after
|
|
229
|
+
# the process terminates (and after any controller block has completed) but
|
|
230
|
+
# before control is returned to the caller. In background mode, the
|
|
231
|
+
# callback is executed asynchronously in a separate thread after the
|
|
232
|
+
# process terminates.
|
|
233
|
+
#
|
|
196
234
|
# Finally, you can force your tool to exit if a subprocess fails, similar
|
|
197
235
|
# to setting the `set -e` option in bash, by setting the
|
|
198
236
|
# `:exit_on_nonzero_status` option. This is often set as a default
|
|
@@ -216,6 +254,10 @@ module Toys
|
|
|
216
254
|
#
|
|
217
255
|
# * `:background` (Boolean) Runs the process in the background if `true`.
|
|
218
256
|
#
|
|
257
|
+
# * `:unbundle` (Boolean) Disables any existing bundle when running the
|
|
258
|
+
# subprocess. Has no effect if Bundler isn't active at the call point.
|
|
259
|
+
# Cannot be used when executing in a fork, e.g. via {#exec_proc}.
|
|
260
|
+
#
|
|
219
261
|
# Options related to handling results
|
|
220
262
|
#
|
|
221
263
|
# * `:result_callback` (Proc,Symbol) A procedure that is called, and
|
|
@@ -10,7 +10,7 @@ module Toys
|
|
|
10
10
|
# utility methods that locate base directories and search paths for
|
|
11
11
|
# application state, configuration, caches, and other data, according to
|
|
12
12
|
# the [XDG Base Directory Spec version
|
|
13
|
-
# 0.8](https://specifications.freedesktop.org/basedir
|
|
13
|
+
# 0.8](https://specifications.freedesktop.org/basedir/0.8/).
|
|
14
14
|
#
|
|
15
15
|
# @example
|
|
16
16
|
#
|
|
@@ -33,36 +33,6 @@ module Toys
|
|
|
33
33
|
# to processes it spawns. You can set these defaults when constructing the
|
|
34
34
|
# service class, or at any time by calling {#configure_defaults}.
|
|
35
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
36
|
# ### Stream handling
|
|
67
37
|
#
|
|
68
38
|
# By default, subprocess streams are connected to the corresponding streams
|
|
@@ -82,7 +52,7 @@ module Toys
|
|
|
82
52
|
#
|
|
83
53
|
# * **Inherit parent stream:** You can inherit the corresponding stream
|
|
84
54
|
# in the parent process by passing `:inherit` as the option value. This
|
|
85
|
-
# is the default if the subprocess is
|
|
55
|
+
# is the default if the subprocess is run in the foreground.
|
|
86
56
|
#
|
|
87
57
|
# * **Redirect to null:** You can redirect to a null stream by passing
|
|
88
58
|
# `:null` as the option value. This connects to a stream that is not
|
|
@@ -134,7 +104,7 @@ module Toys
|
|
|
134
104
|
# the setting `:controller`. You can then manipulate the stream via the
|
|
135
105
|
# controller. If you pass a block to {Toys::Utils::Exec#exec}, it
|
|
136
106
|
# yields the {Toys::Utils::Exec::Controller}, giving you access to
|
|
137
|
-
# streams.
|
|
107
|
+
# streams. See the section below on controlling processes.
|
|
138
108
|
#
|
|
139
109
|
# * **Make copies of an output stream:** You can "tee," or duplicate the
|
|
140
110
|
# `:out` or `:err` stream and redirect those copies to various
|
|
@@ -154,6 +124,70 @@ module Toys
|
|
|
154
124
|
# the tee. Larger buffers may allow higher throughput. The default
|
|
155
125
|
# is 65536.
|
|
156
126
|
#
|
|
127
|
+
# ### Controlling processes
|
|
128
|
+
#
|
|
129
|
+
# A process can be started in the *foreground* or the *background*. If you
|
|
130
|
+
# start a foreground process, it will inherit your standard input and
|
|
131
|
+
# output streams by default, and it will keep control until it completes.
|
|
132
|
+
# If you start a background process, its streams will be redirected to null
|
|
133
|
+
# by default, and control will be returned to you immediately.
|
|
134
|
+
#
|
|
135
|
+
# While a process is running, you can control it using a
|
|
136
|
+
# {Toys::Utils::Exec::Controller} object. Use a controller to interact with
|
|
137
|
+
# the process's input and output streams, send it signals, or wait for it
|
|
138
|
+
# to complete.
|
|
139
|
+
#
|
|
140
|
+
# When running a process in the foreground, the controller will be yielded
|
|
141
|
+
# to an optional block. For example, the following code starts a process in
|
|
142
|
+
# the foreground and passes its output stream to a controller.
|
|
143
|
+
#
|
|
144
|
+
# exec_service.exec(["git", "init"], out: :controller) do |controller|
|
|
145
|
+
# loop do
|
|
146
|
+
# line = controller.out.gets
|
|
147
|
+
# break if line.nil?
|
|
148
|
+
# puts "Got line: #{line}"
|
|
149
|
+
# end
|
|
150
|
+
# end
|
|
151
|
+
#
|
|
152
|
+
# At the end of the block, if the controller is handling the process's
|
|
153
|
+
# input stream, that stream will automatically be closed. The following
|
|
154
|
+
# example programmatically sends data to the `wc` unix program, and
|
|
155
|
+
# captures its output. Because the controller is handling the input stream,
|
|
156
|
+
# it automatically closes the stream at the end of the block, which causes
|
|
157
|
+
# `wc` to end.
|
|
158
|
+
#
|
|
159
|
+
# result = exec_service.exec(["wc"],
|
|
160
|
+
# in: :controller,
|
|
161
|
+
# out: :capture) do |controller|
|
|
162
|
+
# controller.in.puts "Hello, world!"
|
|
163
|
+
# end
|
|
164
|
+
# puts "Results: #{result.captured_out}"
|
|
165
|
+
#
|
|
166
|
+
# Otherwise, depending on the process's behavior, it may continue to run
|
|
167
|
+
# after the end of the block. Control will not be returned to the caller
|
|
168
|
+
# until the process actually terminates. Conversely, it is also possible
|
|
169
|
+
# the process could terminate by itself while the block is still executing.
|
|
170
|
+
# You can call controller methods to obtain the process's actual current
|
|
171
|
+
# state.
|
|
172
|
+
#
|
|
173
|
+
# When running a process in the background, the controller is returned
|
|
174
|
+
# immediately from the method that starts the process. In the following
|
|
175
|
+
# example, git init is kicked off in the background and the output is
|
|
176
|
+
# thrown away to /dev/null.
|
|
177
|
+
#
|
|
178
|
+
# controller = exec_service.exec(["git", "init"], background: true)
|
|
179
|
+
#
|
|
180
|
+
# In this mode, use the returned controller to query the process's state
|
|
181
|
+
# and interact with it. Streams directed to the controller are not
|
|
182
|
+
# automatically closed, so you will need to do so yourself. Following is an
|
|
183
|
+
# example of running `wc` in the background:
|
|
184
|
+
#
|
|
185
|
+
# controller = exec_service.exec(["wc"], background: true,
|
|
186
|
+
# in: :controller, out: :controller)
|
|
187
|
+
# controller.in.puts "Hello, world!"
|
|
188
|
+
# controller.in.close # Do this explicitly to cause wc to finish
|
|
189
|
+
# puts "Results: #{controller.out.read}" # Read the entire stream
|
|
190
|
+
#
|
|
157
191
|
# ### Result handling
|
|
158
192
|
#
|
|
159
193
|
# A subprocess result is represented by a {Toys::Utils::Exec::Result}
|
|
@@ -188,6 +222,12 @@ module Toys
|
|
|
188
222
|
# end
|
|
189
223
|
# exec_service.exec(["git", "init"], result_callback: my_callback)
|
|
190
224
|
#
|
|
225
|
+
# In foreground mode, the callback is executed in the calling thread, after
|
|
226
|
+
# the process terminates (and after any controller block has completed) but
|
|
227
|
+
# before control is returned to the caller. In background mode, the
|
|
228
|
+
# callback is executed asynchronously in a separate thread after the
|
|
229
|
+
# process terminates.
|
|
230
|
+
#
|
|
191
231
|
# ### Configuration options
|
|
192
232
|
#
|
|
193
233
|
# A variety of options can be used to control subprocesses. These can be
|
|
@@ -200,10 +240,16 @@ module Toys
|
|
|
200
240
|
# Keys represent variable names and should be strings. Values should be
|
|
201
241
|
# either strings or `nil`, which unsets the variable.
|
|
202
242
|
#
|
|
203
|
-
# * `:background` (
|
|
243
|
+
# * `:background` (boolean) Runs the process in the background if `true`.
|
|
204
244
|
#
|
|
205
245
|
# * `:result_callback` (Proc) Called and passed the result object when
|
|
206
|
-
# the subprocess exits.
|
|
246
|
+
# the subprocess exits. If the process was run in the background, this
|
|
247
|
+
# callback is executed in a separate thread. If the process was run in
|
|
248
|
+
# the foreground, this callback is executed in the calling thread.
|
|
249
|
+
#
|
|
250
|
+
# * `:unbundle` (boolean) Disables any existing bundle when running the
|
|
251
|
+
# subprocess. Has no effect if Bundler isn't active at the call point.
|
|
252
|
+
# Cannot be used when executing in a fork, e.g. via {#exec_proc}.
|
|
207
253
|
#
|
|
208
254
|
# Options for connecting input and output streams. See the section above on
|
|
209
255
|
# stream handling for info on the values that can be passed.
|
|
@@ -238,16 +284,16 @@ module Toys
|
|
|
238
284
|
#
|
|
239
285
|
# * `:chdir` (String) Set the working directory for the command.
|
|
240
286
|
#
|
|
241
|
-
# * `:close_others` (
|
|
287
|
+
# * `:close_others` (boolean) Whether to close non-redirected
|
|
242
288
|
# non-standard file descriptors.
|
|
243
289
|
#
|
|
244
|
-
# * `:new_pgroup` (
|
|
290
|
+
# * `:new_pgroup` (boolean) Create new process group (Windows only).
|
|
245
291
|
#
|
|
246
292
|
# * `:pgroup` (Integer,true,nil) The process group setting.
|
|
247
293
|
#
|
|
248
294
|
# * `:umask` (Integer) Umask setting for the new process.
|
|
249
295
|
#
|
|
250
|
-
# * `:unsetenv_others` (
|
|
296
|
+
# * `:unsetenv_others` (boolean) Clear environment variables except those
|
|
251
297
|
# explicitly set.
|
|
252
298
|
#
|
|
253
299
|
# Any other option key will result in an `ArgumentError`.
|
|
@@ -494,7 +540,10 @@ module Toys
|
|
|
494
540
|
# After calling this, do not read directly from the stream.
|
|
495
541
|
#
|
|
496
542
|
# @param which [:out,:err] Which stream to capture
|
|
497
|
-
#
|
|
543
|
+
#
|
|
544
|
+
# @return [self] if the stream was captured
|
|
545
|
+
# @return [nil] if the stream was not captured because the process has
|
|
546
|
+
# completed or did not start successfully
|
|
498
547
|
#
|
|
499
548
|
def capture(which)
|
|
500
549
|
# Source available in the toys-core gem
|
|
@@ -538,7 +587,10 @@ module Toys
|
|
|
538
587
|
# @param io [IO,StringIO,String,:null] Where to redirect the stream
|
|
539
588
|
# @param io_args [Object...] The mode and permissions for opening the
|
|
540
589
|
# file, if redirecting to/from a file.
|
|
541
|
-
#
|
|
590
|
+
#
|
|
591
|
+
# @return [self] if the stream was redirected
|
|
592
|
+
# @return [nil] if the stream was not redirected because the process
|
|
593
|
+
# has completed or did not start successfully
|
|
542
594
|
#
|
|
543
595
|
def redirect(which, io, *io_args)
|
|
544
596
|
# Source available in the toys-core gem
|
|
@@ -557,7 +609,10 @@ module Toys
|
|
|
557
609
|
# @param io [IO,StringIO,String,:null] Where to redirect the stream
|
|
558
610
|
# @param io_args [Object...] The mode and permissions for opening the
|
|
559
611
|
# file, if redirecting from a file.
|
|
560
|
-
#
|
|
612
|
+
#
|
|
613
|
+
# @return [self] if the stream was redirected
|
|
614
|
+
# @return [nil] if the stream was not redirected because the process
|
|
615
|
+
# has completed or did not start successfully
|
|
561
616
|
#
|
|
562
617
|
def redirect_in(io, *io_args)
|
|
563
618
|
# Source available in the toys-core gem
|
|
@@ -576,7 +631,10 @@ module Toys
|
|
|
576
631
|
# @param io [IO,StringIO,String,:null] Where to redirect the stream
|
|
577
632
|
# @param io_args [Object...] The mode and permissions for opening the
|
|
578
633
|
# file, if redirecting to a file.
|
|
579
|
-
#
|
|
634
|
+
#
|
|
635
|
+
# @return [self] if the stream was redirected
|
|
636
|
+
# @return [nil] if the stream was not redirected because the process
|
|
637
|
+
# has completed or did not start successfully
|
|
580
638
|
#
|
|
581
639
|
def redirect_out(io, *io_args)
|
|
582
640
|
# Source available in the toys-core gem
|
|
@@ -587,14 +645,18 @@ module Toys
|
|
|
587
645
|
#
|
|
588
646
|
# You can specify the stream as an IO or IO-like object, or as a file
|
|
589
647
|
# specified by its path. If specifying a file, you can optionally
|
|
590
|
-
# provide the mode and permissions for the call to `File#open`.
|
|
648
|
+
# provide the mode and permissions for the call to `File#open`. You can
|
|
649
|
+
# also specify the value `:null` to indicate the null file.
|
|
591
650
|
#
|
|
592
651
|
# After calling this, do not interact directly with the stream.
|
|
593
652
|
#
|
|
594
|
-
# @param io [IO,StringIO,String] Where to redirect the stream
|
|
653
|
+
# @param io [IO,StringIO,String,:null] Where to redirect the stream
|
|
595
654
|
# @param io_args [Object...] The mode and permissions for opening the
|
|
596
655
|
# file, if redirecting to a file.
|
|
597
|
-
#
|
|
656
|
+
#
|
|
657
|
+
# @return [self] if the stream was redirected
|
|
658
|
+
# @return [nil] if the stream was not redirected because the process
|
|
659
|
+
# has completed or did not start successfully
|
|
598
660
|
#
|
|
599
661
|
def redirect_err(io, *io_args)
|
|
600
662
|
# Source available in the toys-core gem
|
|
@@ -615,7 +677,7 @@ module Toys
|
|
|
615
677
|
##
|
|
616
678
|
# Determine whether the subcommand is still executing
|
|
617
679
|
#
|
|
618
|
-
# @return [
|
|
680
|
+
# @return [boolean]
|
|
619
681
|
#
|
|
620
682
|
def executing?
|
|
621
683
|
# Source available in the toys-core gem
|
|
@@ -735,7 +797,7 @@ module Toys
|
|
|
735
797
|
# Returns true if the subprocess failed to start, or false if the
|
|
736
798
|
# process was able to execute.
|
|
737
799
|
#
|
|
738
|
-
# @return [
|
|
800
|
+
# @return [boolean]
|
|
739
801
|
#
|
|
740
802
|
def failed?
|
|
741
803
|
# Source available in the toys-core gem
|
|
@@ -745,7 +807,7 @@ module Toys
|
|
|
745
807
|
# Returns true if the subprocess terminated due to an unhandled signal,
|
|
746
808
|
# or false if the process failed to start or exited normally.
|
|
747
809
|
#
|
|
748
|
-
# @return [
|
|
810
|
+
# @return [boolean]
|
|
749
811
|
#
|
|
750
812
|
def signaled?
|
|
751
813
|
# Source available in the toys-core gem
|
|
@@ -756,7 +818,7 @@ module Toys
|
|
|
756
818
|
# false if the process failed to start, terminated due to a signal, or
|
|
757
819
|
# returned a nonzero status.
|
|
758
820
|
#
|
|
759
|
-
# @return [
|
|
821
|
+
# @return [boolean]
|
|
760
822
|
#
|
|
761
823
|
def success?
|
|
762
824
|
# Source available in the toys-core gem
|
|
@@ -767,7 +829,7 @@ module Toys
|
|
|
767
829
|
# false if the process failed to start, terminated due to a signal, or
|
|
768
830
|
# returned a zero status.
|
|
769
831
|
#
|
|
770
|
-
# @return [
|
|
832
|
+
# @return [boolean]
|
|
771
833
|
#
|
|
772
834
|
def error?
|
|
773
835
|
# Source available in the toys-core gem
|
|
@@ -122,11 +122,12 @@ module Toys
|
|
|
122
122
|
#
|
|
123
123
|
# The default is `:error`.
|
|
124
124
|
#
|
|
125
|
+
# @param default_confirm [Boolean] The default confirmation result, if
|
|
126
|
+
# `on_missing` is set to `:confirm`. Defaults to true.
|
|
125
127
|
# @param terminal [Toys::Utils::Terminal] Terminal to use (optional)
|
|
126
128
|
# @param input [IO] Input IO (optional, defaults to STDIN)
|
|
127
129
|
# @param output [IO] Output IO (optional, defaults to STDOUT)
|
|
128
130
|
# @param suppress_confirm [Boolean] Deprecated. Use `on_missing` instead.
|
|
129
|
-
# @param default_confirm [Boolean] Deprecated. Use `on_missing` instead.
|
|
130
131
|
#
|
|
131
132
|
def initialize(on_missing: nil,
|
|
132
133
|
on_conflict: nil,
|
|
@@ -191,7 +192,12 @@ module Toys
|
|
|
191
192
|
# Source available in the toys-core gem
|
|
192
193
|
end
|
|
193
194
|
|
|
195
|
+
@delete_at_exit_mutex = ::Mutex.new
|
|
196
|
+
@delete_at_exit_list = nil
|
|
197
|
+
|
|
194
198
|
# @private
|
|
199
|
+
# This is a class method so the at_exit block doesn't hold onto an
|
|
200
|
+
# instance for the duration of the Ruby process
|
|
195
201
|
def self.delete_at_exit(path)
|
|
196
202
|
# Source available in the toys-core gem
|
|
197
203
|
end
|
|
@@ -4,7 +4,7 @@ module Toys
|
|
|
4
4
|
# **_Defined in the toys-core gem_**
|
|
5
5
|
#
|
|
6
6
|
# This object provides cached access to remote git data. Given a remote
|
|
7
|
-
# repository, a path, and a commit, it makes the files
|
|
7
|
+
# repository, a path, and a commit, it makes the files available in the
|
|
8
8
|
# local filesystem. Access is cached, so repeated requests for the same
|
|
9
9
|
# commit and path in the same repo do not hit the remote repository again.
|
|
10
10
|
#
|
|
@@ -76,16 +76,27 @@ module Toys
|
|
|
76
76
|
# A list of git refs (branches, tags, shas) that have been accessed
|
|
77
77
|
# from this repo.
|
|
78
78
|
#
|
|
79
|
+
# @param ref [String,nil] If provided, return only entries matching
|
|
80
|
+
# this ref name. If omitted, return all entries.
|
|
79
81
|
# @return [Array<RefInfo>]
|
|
80
82
|
#
|
|
81
|
-
|
|
83
|
+
def refs(ref: nil)
|
|
84
|
+
# Source available in the toys-core gem
|
|
85
|
+
end
|
|
82
86
|
|
|
83
87
|
##
|
|
84
88
|
# A list of shared source files and directories accessed for this repo.
|
|
85
89
|
#
|
|
90
|
+
# @param sha [String,nil] If provided, return only entries matching
|
|
91
|
+
# this SHA. If omitted, entries for all SHAs are included.
|
|
92
|
+
# @param git_path [String,nil] If provided, return only entries
|
|
93
|
+
# matching this git path. If omitted, entries for all paths are
|
|
94
|
+
# included.
|
|
86
95
|
# @return [Array<SourceInfo>]
|
|
87
96
|
#
|
|
88
|
-
|
|
97
|
+
def sources(sha: nil, git_path: nil)
|
|
98
|
+
# Source available in the toys-core gem
|
|
99
|
+
end
|
|
89
100
|
|
|
90
101
|
##
|
|
91
102
|
# Convert this RepoInfo to a hash suitable for JSON output
|
|
@@ -132,14 +143,14 @@ module Toys
|
|
|
132
143
|
##
|
|
133
144
|
# The timestamp when this ref was last accessed
|
|
134
145
|
#
|
|
135
|
-
# @return [Time]
|
|
146
|
+
# @return [Time,nil]
|
|
136
147
|
#
|
|
137
148
|
attr_reader :last_accessed
|
|
138
149
|
|
|
139
150
|
##
|
|
140
151
|
# The timestamp when this ref was last updated
|
|
141
152
|
#
|
|
142
|
-
# @return [Time]
|
|
153
|
+
# @return [Time,nil]
|
|
143
154
|
#
|
|
144
155
|
attr_reader :last_updated
|
|
145
156
|
|
|
@@ -195,7 +206,7 @@ module Toys
|
|
|
195
206
|
##
|
|
196
207
|
# The timestamp when this ref was last accessed
|
|
197
208
|
#
|
|
198
|
-
# @return [Time]
|
|
209
|
+
# @return [Time,nil]
|
|
199
210
|
#
|
|
200
211
|
attr_reader :last_accessed
|
|
201
212
|
|
|
@@ -257,7 +268,7 @@ module Toys
|
|
|
257
268
|
#
|
|
258
269
|
# The resulting files are either copied into a directory you provide in
|
|
259
270
|
# the `:into` parameter, or populated into a _shared_ source directory if
|
|
260
|
-
# you omit the `:
|
|
271
|
+
# you omit the `:into` parameter. In the latter case, it is important
|
|
261
272
|
# that you do not modify the returned files or directories, nor add or
|
|
262
273
|
# remove any files from the directories returned, to avoid confusing
|
|
263
274
|
# callers that could be given the same directory. If you need to make any
|
|
@@ -278,9 +289,12 @@ module Toys
|
|
|
278
289
|
# `false` to specify whether to update, or an integer to update if
|
|
279
290
|
# last update was done at least that many seconds ago. Default is
|
|
280
291
|
# `false`.
|
|
292
|
+
# @param timestamp [Integer,nil] The timestamp for recording the access
|
|
293
|
+
# time and determining whether a resource is stale. Normally, you
|
|
294
|
+
# should leave this out and it will default to the current time.
|
|
281
295
|
#
|
|
282
296
|
# @return [String] The full path to the cached files. The returned path
|
|
283
|
-
# will
|
|
297
|
+
# will correspond to the path given. For example, if you provide the
|
|
284
298
|
# path `Gemfile` representing a single file in the repository, the
|
|
285
299
|
# returned path will point directly to the cached copy of that file.
|
|
286
300
|
#
|
|
@@ -320,7 +334,8 @@ module Toys
|
|
|
320
334
|
# Be careful not to remove repos that are currently in use by other
|
|
321
335
|
# GitCache clients.
|
|
322
336
|
#
|
|
323
|
-
# @param remotes [Array<String>,:all] The remotes to remove.
|
|
337
|
+
# @param remotes [Array<String>,:all,nil] The remotes to remove. If set
|
|
338
|
+
# to :all or nil, removes all repos.
|
|
324
339
|
# @return [Array<String>] The remotes actually removed.
|
|
325
340
|
#
|
|
326
341
|
def remove_repos(remotes)
|
data/core-docs/toys/utils/xdg.rb
CHANGED
|
@@ -9,7 +9,7 @@ module Toys
|
|
|
9
9
|
# This class provides utility methods that locate base directories and
|
|
10
10
|
# search paths for application state, configuration, caches, and other
|
|
11
11
|
# data, according to the [XDG Base Directory Spec version
|
|
12
|
-
# 0.8](https://specifications.freedesktop.org/basedir
|
|
12
|
+
# 0.8](https://specifications.freedesktop.org/basedir/0.8/).
|
|
13
13
|
#
|
|
14
14
|
# Tools can use the `:xdg` mixin for convenient access to this class.
|
|
15
15
|
#
|
|
@@ -19,7 +19,7 @@ module Toys
|
|
|
19
19
|
#
|
|
20
20
|
# xdg = Toys::Utils::XDG.new
|
|
21
21
|
#
|
|
22
|
-
# # Get config file paths, in order from most to least
|
|
22
|
+
# # Get config file paths, in order from most to least important
|
|
23
23
|
# config_files = xdg.lookup_config("my-config.toml")
|
|
24
24
|
# config_files.each { |path| read_my_config(path) }
|
|
25
25
|
#
|
|
@@ -41,6 +41,14 @@ module Toys
|
|
|
41
41
|
# use the Windows known folder paths.
|
|
42
42
|
#
|
|
43
43
|
class XDG
|
|
44
|
+
##
|
|
45
|
+
# **_Defined in the toys-core gem_**
|
|
46
|
+
#
|
|
47
|
+
# An error raised in certain cases when a lookup fails.
|
|
48
|
+
#
|
|
49
|
+
class Error < ::StandardError
|
|
50
|
+
end
|
|
51
|
+
|
|
44
52
|
##
|
|
45
53
|
# Create an instance of XDG.
|
|
46
54
|
#
|
|
@@ -63,6 +71,7 @@ module Toys
|
|
|
63
71
|
##
|
|
64
72
|
# Returns the absolute path to the single base directory relative to
|
|
65
73
|
# which user-specific data files should be written.
|
|
74
|
+
#
|
|
66
75
|
# Corresponds to the value of the `$XDG_DATA_HOME` environment variable
|
|
67
76
|
# and its defaults according to the XDG Base Directory Spec.
|
|
68
77
|
#
|
|
@@ -75,6 +84,7 @@ module Toys
|
|
|
75
84
|
##
|
|
76
85
|
# Returns the absolute path to the single base directory relative to
|
|
77
86
|
# which user-specific configuration files should be written.
|
|
87
|
+
#
|
|
78
88
|
# Corresponds to the value of the `$XDG_CONFIG_HOME` environment variable
|
|
79
89
|
# and its defaults according to the XDG Base Directory Spec.
|
|
80
90
|
#
|
|
@@ -87,6 +97,7 @@ module Toys
|
|
|
87
97
|
##
|
|
88
98
|
# Returns the absolute path to the single base directory relative to
|
|
89
99
|
# which user-specific state files should be written.
|
|
100
|
+
#
|
|
90
101
|
# Corresponds to the value of the `$XDG_STATE_HOME` environment variable
|
|
91
102
|
# and its defaults according to the XDG Base Directory Spec.
|
|
92
103
|
#
|
|
@@ -99,6 +110,7 @@ module Toys
|
|
|
99
110
|
##
|
|
100
111
|
# Returns the absolute path to the single base directory relative to
|
|
101
112
|
# which user-specific non-essential (cached) data should be written.
|
|
113
|
+
#
|
|
102
114
|
# Corresponds to the value of the `$XDG_CACHE_HOME` environment variable
|
|
103
115
|
# and its defaults according to the XDG Base Directory Spec.
|
|
104
116
|
#
|
|
@@ -111,6 +123,7 @@ module Toys
|
|
|
111
123
|
##
|
|
112
124
|
# Returns the absolute path to the single base directory relative to
|
|
113
125
|
# which user-specific executable files may be written.
|
|
126
|
+
#
|
|
114
127
|
# Returns the value of `$HOME/.local/bin` as specified by the XDG Base
|
|
115
128
|
# Directory Spec.
|
|
116
129
|
#
|
|
@@ -125,6 +138,7 @@ module Toys
|
|
|
125
138
|
# which data files should be searched, as an array of absolute paths.
|
|
126
139
|
# The array is ordered from most to least important, and does _not_
|
|
127
140
|
# include the data home directory.
|
|
141
|
+
#
|
|
128
142
|
# Corresponds to the value of the `$XDG_DATA_DIRS` environment variable
|
|
129
143
|
# and its defaults according to the XDG Base Directory Spec.
|
|
130
144
|
#
|
|
@@ -139,6 +153,7 @@ module Toys
|
|
|
139
153
|
# which configuration files should be searched, as an array of absolute
|
|
140
154
|
# paths. The array is ordered from most to least important, and does
|
|
141
155
|
# _not_ include the config home directory.
|
|
156
|
+
#
|
|
142
157
|
# Corresponds to the value of the `$XDG_CONFIG_DIRS` environment variable
|
|
143
158
|
# and its defaults according to the XDG Base Directory Spec.
|
|
144
159
|
#
|
|
@@ -151,7 +166,15 @@ module Toys
|
|
|
151
166
|
##
|
|
152
167
|
# Returns the absolute path to the single base directory relative to
|
|
153
168
|
# which user-specific runtime files and other file objects should be
|
|
154
|
-
# placed.
|
|
169
|
+
# placed.
|
|
170
|
+
#
|
|
171
|
+
# Corresponds to the value of the `$XDG_RUNTIME_DIR` environment variable
|
|
172
|
+
# according to the XDG Base Directory Spec.
|
|
173
|
+
#
|
|
174
|
+
# **Important:** Returns `nil` if the `$XDG_RUNTIME_DIR` environment
|
|
175
|
+
# variable is unset or invalid. In such a case, it is the caller's
|
|
176
|
+
# responsibility to determine a fallback strategy, as this library cannot
|
|
177
|
+
# by itself implement a compliant fallback without OS help.
|
|
155
178
|
#
|
|
156
179
|
# @return [String,nil]
|
|
157
180
|
#
|
|
@@ -159,11 +182,34 @@ module Toys
|
|
|
159
182
|
# Source available in the toys-core gem
|
|
160
183
|
end
|
|
161
184
|
|
|
185
|
+
##
|
|
186
|
+
# Returns the absolute path to the single base directory relative to
|
|
187
|
+
# which user-specific runtime files and other file objects should be
|
|
188
|
+
# placed.
|
|
189
|
+
#
|
|
190
|
+
# Corresponds to the value of the `$XDG_RUNTIME_DIR` environment variable
|
|
191
|
+
# according to the XDG Base Directory Spec.
|
|
192
|
+
#
|
|
193
|
+
# Raises {Toys::Utils::XDG::Error} if the `$XDG_RUNTIME_DIR` environment
|
|
194
|
+
# variable is unset or invalid. Unlike {#runtime_dir}, does not return
|
|
195
|
+
# nil.
|
|
196
|
+
#
|
|
197
|
+
# @return [String]
|
|
198
|
+
#
|
|
199
|
+
def runtime_dir!
|
|
200
|
+
# Source available in the toys-core gem
|
|
201
|
+
end
|
|
202
|
+
|
|
162
203
|
##
|
|
163
204
|
# Searches the data directories for an object with the given relative
|
|
164
205
|
# path, and returns an array of absolute paths to all objects found in
|
|
165
|
-
#
|
|
166
|
-
# from most to least important.
|
|
206
|
+
# all data directories (i.e. {#data_home} and {#data_dirs}), in order
|
|
207
|
+
# from most to least important. Returns the empty array if no suitable
|
|
208
|
+
# objects are found.
|
|
209
|
+
#
|
|
210
|
+
# If multiple objects are found, the caller should implement its own
|
|
211
|
+
# logic to resolve them. For example, it can select the first (most
|
|
212
|
+
# important) object, or implement logic to combine the contents.
|
|
167
213
|
#
|
|
168
214
|
# @param path [String] Relative path of the object to search for
|
|
169
215
|
# @param type [String,Symbol,Array<String,Symbol>] The type(s) of objects
|
|
@@ -181,8 +227,13 @@ module Toys
|
|
|
181
227
|
##
|
|
182
228
|
# Searches the config directories for an object with the given relative
|
|
183
229
|
# path, and returns an array of absolute paths to all objects found in
|
|
184
|
-
#
|
|
185
|
-
# order from most to least important.
|
|
230
|
+
# all config directories (i.e. {#config_home} and {#config_dirs}), in
|
|
231
|
+
# order from most to least important. Returns the empty array if no
|
|
232
|
+
# suitable objects are found.
|
|
233
|
+
#
|
|
234
|
+
# If multiple objects are found, the caller should implement its own
|
|
235
|
+
# logic to resolve them. For example, it can select the first (most
|
|
236
|
+
# important) object, or implement logic to combine the contents.
|
|
186
237
|
#
|
|
187
238
|
# @param path [String] Relative path of the object to search for
|
|
188
239
|
# @param type [String,Symbol,Array<String,Symbol>] The type(s) of objects
|
|
@@ -197,6 +248,50 @@ module Toys
|
|
|
197
248
|
# Source available in the toys-core gem
|
|
198
249
|
end
|
|
199
250
|
|
|
251
|
+
##
|
|
252
|
+
# Searches the state directory ({#state_home}) for an object with the
|
|
253
|
+
# given relative path, and returns an array of zero or one absolute paths
|
|
254
|
+
# to any found object. Because the XDG basedir spec does not provide for
|
|
255
|
+
# a list of fallback directories for state files (i.e. there is no
|
|
256
|
+
# `XDG_STATE_DIRS` variable or list of default paths), this will return a
|
|
257
|
+
# maximum of one result. However, it returns an array for consistency
|
|
258
|
+
# with the {#lookup_data} and {#lookup_config} methods.
|
|
259
|
+
#
|
|
260
|
+
# @param path [String] Relative path of the object to search for
|
|
261
|
+
# @param type [String,Symbol,Array<String,Symbol>] The type(s) of objects
|
|
262
|
+
# to find. You can specify any of the types defined by
|
|
263
|
+
# [File::Stat#ftype](https://ruby-doc.org/core/File/Stat.html#method-i-ftype),
|
|
264
|
+
# such as `file` or `directory`, or the special type `any`. Types can
|
|
265
|
+
# be specified as strings or the corresponding symbols. If this
|
|
266
|
+
# argument is not provided, the default of `file` is used.
|
|
267
|
+
# @return [Array<String>]
|
|
268
|
+
#
|
|
269
|
+
def lookup_state(path, type: :file)
|
|
270
|
+
# Source available in the toys-core gem
|
|
271
|
+
end
|
|
272
|
+
|
|
273
|
+
##
|
|
274
|
+
# Searches the cache directory ({#cache_home}) for an object with the
|
|
275
|
+
# given relative path, and returns an array of zero or one absolute paths
|
|
276
|
+
# to any found object. Because the XDG basedir spec does not provide for
|
|
277
|
+
# a list of fallback directories for cache files (i.e. there is no
|
|
278
|
+
# `XDG_CACHE_DIRS` variable or list of default paths), this will return a
|
|
279
|
+
# maximum of one result. However, it returns an array for consistency
|
|
280
|
+
# with the {#lookup_data} and {#lookup_config} methods.
|
|
281
|
+
#
|
|
282
|
+
# @param path [String] Relative path of the object to search for
|
|
283
|
+
# @param type [String,Symbol,Array<String,Symbol>] The type(s) of objects
|
|
284
|
+
# to find. You can specify any of the types defined by
|
|
285
|
+
# [File::Stat#ftype](https://ruby-doc.org/core/File/Stat.html#method-i-ftype),
|
|
286
|
+
# such as `file` or `directory`, or the special type `any`. Types can
|
|
287
|
+
# be specified as strings or the corresponding symbols. If this
|
|
288
|
+
# argument is not provided, the default of `file` is used.
|
|
289
|
+
# @return [Array<String>]
|
|
290
|
+
#
|
|
291
|
+
def lookup_cache(path, type: :file)
|
|
292
|
+
# Source available in the toys-core gem
|
|
293
|
+
end
|
|
294
|
+
|
|
200
295
|
##
|
|
201
296
|
# Returns the absolute path to a directory under {#data_home}, creating
|
|
202
297
|
# it if it doesn't already exist.
|
|
@@ -204,7 +299,9 @@ module Toys
|
|
|
204
299
|
# @param path [String] The relative path to the subdir within the base
|
|
205
300
|
# data directory.
|
|
206
301
|
# @return [String] The absolute path to the subdir.
|
|
207
|
-
# @raise [
|
|
302
|
+
# @raise [SystemCallError] If a non-directory already exists there. It is
|
|
303
|
+
# unspecified which specific error will be raised; it typically could
|
|
304
|
+
# be `Errno::EEXIST` or `Errno::ENOTDIR`.
|
|
208
305
|
#
|
|
209
306
|
def ensure_data_subdir(path)
|
|
210
307
|
# Source available in the toys-core gem
|
|
@@ -217,7 +314,9 @@ module Toys
|
|
|
217
314
|
# @param path [String] The relative path to the subdir within the base
|
|
218
315
|
# config directory.
|
|
219
316
|
# @return [String] The absolute path to the subdir.
|
|
220
|
-
# @raise [
|
|
317
|
+
# @raise [SystemCallError] If a non-directory already exists there. It is
|
|
318
|
+
# unspecified which specific error will be raised; it typically could
|
|
319
|
+
# be `Errno::EEXIST` or `Errno::ENOTDIR`.
|
|
221
320
|
#
|
|
222
321
|
def ensure_config_subdir(path)
|
|
223
322
|
# Source available in the toys-core gem
|
|
@@ -230,7 +329,9 @@ module Toys
|
|
|
230
329
|
# @param path [String] The relative path to the subdir within the base
|
|
231
330
|
# state directory.
|
|
232
331
|
# @return [String] The absolute path to the subdir.
|
|
233
|
-
# @raise [
|
|
332
|
+
# @raise [SystemCallError] If a non-directory already exists there. It is
|
|
333
|
+
# unspecified which specific error will be raised; it typically could
|
|
334
|
+
# be `Errno::EEXIST` or `Errno::ENOTDIR`.
|
|
234
335
|
#
|
|
235
336
|
def ensure_state_subdir(path)
|
|
236
337
|
# Source available in the toys-core gem
|
|
@@ -243,7 +344,9 @@ module Toys
|
|
|
243
344
|
# @param path [String] The relative path to the subdir within the base
|
|
244
345
|
# cache directory.
|
|
245
346
|
# @return [String] The absolute path to the subdir.
|
|
246
|
-
# @raise [
|
|
347
|
+
# @raise [SystemCallError] If a non-directory already exists there. It is
|
|
348
|
+
# unspecified which specific error will be raised; it typically could
|
|
349
|
+
# be `Errno::EEXIST` or `Errno::ENOTDIR`.
|
|
247
350
|
#
|
|
248
351
|
def ensure_cache_subdir(path)
|
|
249
352
|
# Source available in the toys-core gem
|
data/lib/toys/templates/clean.rb
CHANGED
data/lib/toys/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: toys
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.21.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Daniel Azuma
|
|
@@ -15,14 +15,14 @@ dependencies:
|
|
|
15
15
|
requirements:
|
|
16
16
|
- - '='
|
|
17
17
|
- !ruby/object:Gem::Version
|
|
18
|
-
version: 0.
|
|
18
|
+
version: 0.21.0
|
|
19
19
|
type: :runtime
|
|
20
20
|
prerelease: false
|
|
21
21
|
version_requirements: !ruby/object:Gem::Requirement
|
|
22
22
|
requirements:
|
|
23
23
|
- - '='
|
|
24
24
|
- !ruby/object:Gem::Version
|
|
25
|
-
version: 0.
|
|
25
|
+
version: 0.21.0
|
|
26
26
|
description: Toys is a configurable command line tool. Write commands in Ruby using
|
|
27
27
|
a simple DSL, and Toys will provide the command line executable and take care of
|
|
28
28
|
all the details such as argument parsing, online help, and error reporting. Toys
|
|
@@ -123,10 +123,10 @@ homepage: https://github.com/dazuma/toys
|
|
|
123
123
|
licenses:
|
|
124
124
|
- MIT
|
|
125
125
|
metadata:
|
|
126
|
-
changelog_uri: https://dazuma.github.io/toys/gems/toys/v0.
|
|
127
|
-
source_code_uri: https://github.com/dazuma/toys/tree/toys/v0.
|
|
126
|
+
changelog_uri: https://dazuma.github.io/toys/gems/toys/v0.21.0/file.CHANGELOG.html
|
|
127
|
+
source_code_uri: https://github.com/dazuma/toys/tree/toys/v0.21.0/toys
|
|
128
128
|
bug_tracker_uri: https://github.com/dazuma/toys/issues
|
|
129
|
-
documentation_uri: https://dazuma.github.io/toys/gems/toys/v0.
|
|
129
|
+
documentation_uri: https://dazuma.github.io/toys/gems/toys/v0.21.0
|
|
130
130
|
rdoc_options: []
|
|
131
131
|
require_paths:
|
|
132
132
|
- lib
|
|
@@ -141,7 +141,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
141
141
|
- !ruby/object:Gem::Version
|
|
142
142
|
version: '0'
|
|
143
143
|
requirements: []
|
|
144
|
-
rubygems_version: 4.0.
|
|
144
|
+
rubygems_version: 4.0.6
|
|
145
145
|
specification_version: 4
|
|
146
146
|
summary: A configurable command line tool
|
|
147
147
|
test_files: []
|