toys 0.10.3 → 0.11.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e5d3f58c40a7994b81b623f7b68af7aba8f41413ac2f55767079c07edcd5f1b0
4
- data.tar.gz: 4118e056d30446da0ca5f01ac35e940409bb4e77362c9c34e1526e6e78e38f5c
3
+ metadata.gz: c52b606c7f0bd27e709c7e019bfb89e1b8772fdb0c112e80dc6e4a4f5ffc50bc
4
+ data.tar.gz: 2b2c90a882e812500c98bf89d3b13d90430e98acfcbedc2a60ef1bdc50a1ad20
5
5
  SHA512:
6
- metadata.gz: 1b35eb3fc351b5f0046f31a8e6dfe3c5391ddb5673d722e49b6927d88dbb9c5fcaef7e5061b4ed7c9128d4fc04453cfbd203add11fecb59d01e59ed7d2e17c5b
7
- data.tar.gz: 170995f640d31ec55db72581d3d4da1ae48976576f3d1d92a9777987a41ae90002f968c875da3c91324848dc9382a0379422d7be6a678449750ed5c76c1251be
6
+ metadata.gz: 5e9ba6c9e241f6eace1ff585e0cd4968b81ecef04934c08aab5af5273c06b314e9d8314a293b462b5dfd3aaf467d567af024622035a98b49703bcbd473705023
7
+ data.tar.gz: 156b3848c0946853378c04e9aef6f0ecf434d9c5f978441c9a20b3d4311c973b6c5409600aad6d92aba9c74b55c2554c279405602c81023ef900bcd9aca0f8be
@@ -1,18 +1,52 @@
1
1
  # Release History
2
2
 
3
- ### 0.10.3 / 2020-07-04
3
+ ### v0.11.2 / 2020-09-06
4
+
5
+ * FIXED: Don't get confused when running toys from within a toys directory
6
+ * FIXED: Fix a JRuby-specific race condition when capturing exec streams
7
+
8
+ ### v0.11.1 / 2020-08-24
9
+
10
+ * FIXED: The `.lib` directory actually works as advertised.
11
+
12
+ ### v0.11.0 / 2020-08-21
13
+
14
+ * ADDED: The toys search path can be truncated using the `truncate_load_path!` directive.
15
+ * ADDED: The `:clean` template recognizes `:gitignore` as a path indicating all gitignored files.
16
+ * IMPROVED: Generated help for delegates now includes the information for the target tool, plus subtools of the delegate.
17
+ * IMPROVED: The `:bundler` mixin searches for `gems.rb` and `.gems.rb` in addition to `Gemfile`.
18
+ * IMPROVED: The `:budnler` mixin can load a specific Gemfile path.
19
+ * FIXED: The loader can now find `.data` and `.lib` directories at the root level of a `.toys` directory.
20
+ * FIXED: Exec::Result correctly reports processes that terminated due to signals.
21
+ * FIXED: Fixed a rare Exec capture failure that resulted from a race condition when closing streams.
22
+ * DOCS: The Toys user guide now covers static bundle loading and `truncate_load_path!`.
23
+
24
+ ### v0.10.5 / 2020-07-18
25
+
26
+ * IMPROVED: The bundler mixin silences bundler output during bundle setup.
27
+ * IMPROVED: The bundler mixin allows toys and toys-core to be in the Gemfile. It checks their version requirements against the running Toys version, and either adds the corret version to the bundle or raises IncompatibleToysError.
28
+ * IMPROVED: The bundler mixin automatically updates the bundle if install fails (typically because a transitive dependency has been explicitly updated.)
29
+ * FIXED: Some cases of transitive dependency handling by the bundler mixin.
30
+ * FIXED: Fixed a crash when computing suggestions, when running with a bundle on Ruby 2.6 or earlier.
31
+
32
+ ### v0.10.4 / 2020-07-11
33
+
34
+ * IMPROVED: Bundler integration can now handle Toys itself being in the bundle, as long as the version requirements cover the running Toys version.
35
+ * IMPROVED: Passing `static: true` to the `:bundler` mixin installs the bundle at definition rather than execution time.
36
+
37
+ ### v0.10.3 / 2020-07-04
4
38
 
5
39
  * FIXED: The `exec_separate_tool` method in the `:exec` mixin no longer throws ENOEXEC on Windows.
6
40
 
7
- ### 0.10.2 / 2020-07-03
41
+ ### v0.10.2 / 2020-07-03
8
42
 
9
43
  * FIXED: The load path no longer loses the toys and toys-core directories after a bundle install.
10
44
 
11
- ### 0.10.1 / 2020-03-07
45
+ ### v0.10.1 / 2020-03-07
12
46
 
13
47
  * FIXED: Setting `:exit_on_nonzero_status` explicitly to false now works as expected.
14
48
 
15
- ### 0.10.0 / 2020-02-24
49
+ ### v0.10.0 / 2020-02-24
16
50
 
17
51
  * ADDED: `:bundler` mixin that installs and sets up a bundle for the tool
18
52
  * ADDED: `bundler` options in the standard templates, to run those tools in a bundle
@@ -28,26 +62,26 @@
28
62
  * FIXED: `rdoc` template crashed if any nonstandard options were given.
29
63
  * FIXED: `rubocop` template would abort prematurely if standard streams were redirected.
30
64
 
31
- ### 0.9.4 / 2020-01-26
65
+ ### v0.9.4 / 2020-01-26
32
66
 
33
67
  * FIXED: Crash in the loader when a non-ruby file appears in a toys directory
34
68
 
35
- ### 0.9.3 / 2020-01-05
69
+ ### v0.9.3 / 2020-01-05
36
70
 
37
71
  * FIXED: `delegate_to` directive could crash if an overriding tool has already been defined.
38
72
  * FIXED: A Ruby 2.7 warning when reporting a Toys file syntax error.
39
73
 
40
- ### 0.9.2 / 2020-01-03
74
+ ### v0.9.2 / 2020-01-03
41
75
 
42
76
  * IMPROVED: Mixins can now take real keyword arguments, and will pass them on properly to `on_initialize` and `on_include` blocks.
43
77
  * CHANGED: `Toys::Utils::Exec` and the `:exec` mixin methods now take real keyword arguments rather than an `opts` hash. This means you should use keywords (or the double-splat operator) to avoid a deprecation warning on Ruby 2.7.
44
78
 
45
- ### 0.9.1 / 2019-12-22
79
+ ### v0.9.1 / 2019-12-22
46
80
 
47
81
  * IMPROVED: `delegate_to` and `alias_tool` can take symbols as well as strings.
48
82
  * DOCS: Fixed user guide internal links on rubydoc.info.
49
83
 
50
- ### 0.9.0 / 2019-12-02
84
+ ### v0.9.0 / 2019-12-02
51
85
 
52
86
  * ADDED: The `delegate_to` directive causes the tool to delegate execution to another tool. This means it takes the same arguments and has the same execution behavior.
53
87
  * ADDED: The `delegate_to` argument to the `tool` directive causes the tool to delegate to another tool. (Note: the `alias_tool` directive is now just shorthand for creating a tool with a delegate, and as such is mildly deprecated.)
@@ -58,12 +92,12 @@
58
92
  * IMPROVED: JRuby is now supported for most operations. However, JRuby is generally not recommended because of JVM boot latency, lack of Kernel#fork support, and other issues.
59
93
  * FIXED: The the `tool` directive no longer crashes if not passed a block.
60
94
 
61
- ### 0.8.1 / 2019-11-19
95
+ ### v0.8.1 / 2019-11-19
62
96
 
63
97
  * FIXED: Listing subtools would crash if a broken alias was present.
64
98
  * DOCUMENTATION: Switched from redcarpet to kramdown, and tried to make some structural fixes.
65
99
 
66
- ### 0.8.0 / 2019-06-20
100
+ ### v0.8.0 / 2019-06-20
67
101
 
68
102
  This is a major update with significant new features and a bunch of fixes.
69
103
  It does include a few minor backward-incompatible changes. All signifiant
@@ -117,18 +151,18 @@ Details:
117
151
 
118
152
  Additionally, a significant amount of internal reorganization and cleanup happened in the toys-core gem. See the changelog for toys-core for more details.
119
153
 
120
- ### 0.7.0 / 2019-01-23
154
+ ### v0.7.0 / 2019-01-23
121
155
 
122
156
  * ADDED: A template for creating tools that invoke RSpec.
123
157
  * ADDED: Flag groups, which enforce policies around which flags are required.
124
158
  * CHANGED: Flags within a group are sorted in the help screens.
125
159
  * IMPROVED: The minitest template now honors all standard minitest flags.
126
160
 
127
- ### 0.6.1 / 2019-01-07
161
+ ### v0.6.1 / 2019-01-07
128
162
 
129
163
  * FIXED: The presence of aliases caused subtool listing to crash.
130
164
 
131
- ### 0.6.0 / 2018-10-22
165
+ ### v0.6.0 / 2018-10-22
132
166
 
133
167
  * FIXED: Build tools cd into the context directory when running.
134
168
  * FIXED: Rakefiles are evaluated and tasks are run in the Rakefile's directory.
@@ -140,7 +174,7 @@ Additionally, a significant amount of internal reorganization and cleanup happen
140
174
  * IMPROVED: Non-runnable namespaces are no longer displayed in recursive subtool
141
175
  lists if their children are already displayed.
142
176
 
143
- ### 0.5.0 / 2018-10-07
177
+ ### v0.5.0 / 2018-10-07
144
178
 
145
179
  * ADDED: Period and colon are recognized as tool path delimiters.
146
180
  * ADDED: New rake template that supports loading rake tasks as tools.
@@ -151,31 +185,31 @@ Additionally, a significant amount of internal reorganization and cleanup happen
151
185
  * IMPROVED: The tool directive can now take an `if_defined` argument.
152
186
  * FIXED: Template instantiation was failing if the hosting tool was priority-masked.
153
187
 
154
- ### 0.4.5 / 2018-08-05
188
+ ### v0.4.5 / 2018-08-05
155
189
 
156
190
  * CHANGED: Dropped preload file feature
157
191
 
158
- ### 0.4.4 / 2018-07-21
192
+ ### v0.4.4 / 2018-07-21
159
193
 
160
194
  * FIXED: Utils::Exec wasn't closing streams after copying.
161
195
  * IMPROVED: Utils::Exec::Controller can capture or redirect the remainder of a controlled stream.
162
196
  * ADDED: Terminal#ask
163
197
 
164
- ### 0.4.3 / 2018-07-13
198
+ ### v0.4.3 / 2018-07-13
165
199
 
166
200
  * IMPROVED: Exec mixin methods can now spawn subprocesses in the background
167
201
  * IMPROVED: Exec mixin capture methods can now yield a controller
168
202
 
169
- ### 0.4.2 / 2018-07-08
203
+ ### v0.4.2 / 2018-07-08
170
204
 
171
205
  * FIXED: Raise an error rather than cause unexpected behavior if a mixin is included twice.
172
206
  * IMPROVED: The `include?` method extended to support mixin names in a tool dsl.
173
207
 
174
- ### 0.4.1 / 2018-07-03
208
+ ### v0.4.1 / 2018-07-03
175
209
 
176
210
  * FIXED: Terminal#confirm uppercased "N" for the wrong default.
177
211
 
178
- ### 0.4.0 / 2018-07-03
212
+ ### v0.4.0 / 2018-07-03
179
213
 
180
214
  Now declaring this alpha quality. Backward-incompatible changes are still
181
215
  possible from this point, but I'll try to avoid them.
@@ -185,24 +219,24 @@ possible from this point, but I'll try to avoid them.
185
219
  * IMPROVED: Toys::Utils::Gems can suppress the confirmation prompt
186
220
  * IMPROVED: Magic comments are now honored in toys files.
187
221
 
188
- ### 0.3.11 / 2018-07-02
222
+ ### v0.3.11 / 2018-07-02
189
223
 
190
224
  * CHANGED: Require Ruby 2.3 or later
191
225
  * CHANGED: Renamed "set" directive to "static" to reduce confusion with Tool#set.
192
226
  * ADDED: Convenience methods for getting option values
193
227
 
194
- ### 0.3.10 / 2018-06-30
228
+ ### v0.3.10 / 2018-06-30
195
229
 
196
230
  * CHANGED: Dropped Tool#option. Use Tool#get instead.
197
231
  * CHANGED: "run" directive renamed to "to_run"
198
232
  * CHANGED: Highline mixin now uses Highline 2.0
199
233
  * ADDED: Mixins can provide initializers
200
234
 
201
- ### 0.3.9.1 / 2018-06-24
235
+ ### v0.3.9.1 / 2018-06-24
202
236
 
203
237
  * FIXED: Built-in flags were interfering with disable_argument_parsing
204
238
 
205
- ### 0.3.9 / 2018-06-24
239
+ ### v0.3.9 / 2018-06-24
206
240
 
207
241
  * CHANGED: Removed alias_as directive since it's incompatible with selective loading.
208
242
  * ADDED: Ability to define named templates in Toys files
@@ -212,18 +246,18 @@ possible from this point, but I'll try to avoid them.
212
246
  * IMPROVED: Acceptors can be looked up recursively in the same way as mixins and templates
213
247
  * FIXED: Templates were not activating needed gems
214
248
 
215
- ### 0.3.8 / 2018-06-10
249
+ ### v0.3.8 / 2018-06-10
216
250
 
217
251
  * CHANGED: Renamed helpers to mixins.
218
252
  * CHANGED: Renamed :in_from, :out_to, and :err_to exec options to :in, :out, :err
219
253
  * IMPROVED: Exec raises an error if passed an unknown option.
220
254
  * IMPROVED: Exec now accepts nearly all the same stream specifications as Process#spawn.
221
255
 
222
- ### 0.3.7.1 / 2018-05-30
256
+ ### v0.3.7.1 / 2018-05-30
223
257
 
224
258
  * FIXED: Fix crash in system update.
225
259
 
226
- ### 0.3.7 / 2018-05-30
260
+ ### v0.3.7 / 2018-05-30
227
261
 
228
262
  * CHANGED: Execution runs in the same scope as the DSL, which lets us use normal methods instead of helper-blocks.
229
263
  * CHANGED: Renamed "script" to "run", and allow setting of runnable by defining a "run" method
@@ -232,7 +266,7 @@ possible from this point, but I'll try to avoid them.
232
266
  * CHANGED: Removed spinner helper and added terminal helper.
233
267
  * ADDED: Helper modules scoped to the tool hierarchy
234
268
 
235
- ### 0.3.6 / 2018-05-21
269
+ ### v0.3.6 / 2018-05-21
236
270
 
237
271
  * CHANGED: Removed Context#new_cli and exposed Context#cli instead.
238
272
  * CHANGED: Raises ToolDefinitionError if you declare a duplicate flag.
@@ -241,13 +275,13 @@ possible from this point, but I'll try to avoid them.
241
275
  * IMPROVED: Support custom acceptors.
242
276
  * IMPROVED: Highline helper automatically sets use_color based on the type of stdout.
243
277
 
244
- ### 0.3.5 / 2018-05-15
278
+ ### v0.3.5 / 2018-05-15
245
279
 
246
280
  * CHANGED: Flag and arg blocks in the DSL have an interface more similar to the rest of the DSL.
247
281
  * CHANGED: Renamed `execute do` to `script do`.
248
282
  * IMPROVED: Help display uses `less` if available.
249
283
 
250
- ### 0.3.4 / 2018-05-14
284
+ ### v0.3.4 / 2018-05-14
251
285
 
252
286
  * CHANGED: Renamed switch to flag
253
287
  * CHANGED: Renamed docs: parameter again, to desc: and long_desc: to match tool desc.
@@ -264,7 +298,7 @@ possible from this point, but I'll try to avoid them.
264
298
  * FIXED: Subtools with no desc now properly pick up the default
265
299
  * FIXED: Usage errors and show-help now interact in the right way
266
300
 
267
- ### 0.3.3 / 2018-05-09
301
+ ### v0.3.3 / 2018-05-09
268
302
 
269
303
  * CHANGED: Renamed file_utils helper to fileutils.
270
304
  * CHANGED: Renamed doc: parameter to docs:
@@ -274,7 +308,7 @@ possible from this point, but I'll try to avoid them.
274
308
  * ADDED: WrappableString for descriptions and docs
275
309
  * IMPROVED: Descriptions can have multiple lines
276
310
 
277
- ### 0.3.2 / 2018-05-07
311
+ ### v0.3.2 / 2018-05-07
278
312
 
279
313
  * CHANGED: Split core engine out into separate "toys-core" gem. See the
280
314
  toys-core changelog for additional changes in core.
@@ -285,7 +319,7 @@ possible from this point, but I'll try to avoid them.
285
319
  * IMPROVED: Help shows the config file path on "--verbose".
286
320
  * IMPROVED: You can now run a sub-instance of toys from an executor.
287
321
 
288
- ### 0.3.1 / 2018-05-02
322
+ ### v0.3.1 / 2018-05-02
289
323
 
290
324
  * CHANGED: Subcommand display is now recursive by default.
291
325
  * IMPROVED: Improved error messaging for bad switch syntax.
@@ -294,6 +328,6 @@ possible from this point, but I'll try to avoid them.
294
328
  * DOCS: Completed a first pass on class and method documentation.
295
329
  * INTERNAL: Adjusted naming of switch-related methods.
296
330
 
297
- ### 0.3.0 / 2018-04-30
331
+ ### v0.3.0 / 2018-04-30
298
332
 
299
333
  * Initial generally usable release
data/README.md CHANGED
@@ -240,8 +240,9 @@ Note that if you normally run Rake with Bundler (e.g. `bundle exec rake test`),
240
240
  you may need to add Toys to your Gemfile and use Bundler to invoke Toys (i.e.
241
241
  `bundle exec toys test`). This is because Toys is just calling the Rake API to
242
242
  run your task, and the Rake task might require the bundle. However, when Toys
243
- is not wrapping Rake, typical practice is actually *not* to use Bundler. Toys
244
- provides its own mechanisms to activate and even install needed gems for you.
243
+ is not wrapping Rake, typical practice is actually *not* to use `bundle exec`.
244
+ Toys provides its own mechanisms to setup a bundle, or to activate and even
245
+ install individual gems.
245
246
 
246
247
  So far, we've made Toys a front-end for your Rake tasks. This may be useful by
247
248
  itself. Toys lets you pass command line arguments "normally" to tools, whereas
@@ -252,7 +253,7 @@ than Rake does.
252
253
  But you also might find Toys a more natural way to *write* tasks, and indeed
253
254
  you can often rewrite an entire Rakefile as a Toys file and get quite a bit of
254
255
  benefit in readability and maintainability. For an example, see the
255
- [Toys file for the Toys repo itself](https://github.com/dazuma/toys/blob/master/toys/.toys.rb).
256
+ [Toys file for the Toys repo itself](https://github.com/dazuma/toys/blob/main/toys/.toys.rb).
256
257
  It contains the Toys scripts that I use to develop, test, and release Toys
257
258
  itself. Yes, Toys is self-hosted. You'll notice most of this Toys file consists
258
259
  of template expansions. Toys provides templates for a lot of common build,
@@ -1,4 +1,6 @@
1
+ <!--
1
2
  # @title Toys User Guide
3
+ -->
2
4
 
3
5
  # Toys User Guide
4
6
 
@@ -1300,7 +1302,29 @@ the same point (the current directory) in the search path.
1300
1302
  Note that in the search path above, steps (1) and (2) are *context-dependent*.
1301
1303
  That is, they may be different depending on what directory you are in. However,
1302
1304
  step (3) is *not* context-dependent, and is searched regardless of where you
1303
- are located. Tools defined here are **global**, available everywhere.
1305
+ are located. Tools defined here are *global*, available everywhere.
1306
+
1307
+ #### Stopping search
1308
+
1309
+ Though it is uncommon practice, it is possible to stop the search process and
1310
+ prevent Toys from loading tools further down in the search path (e.g. prevent
1311
+ tools from being defined from parent directories or global directories). To do
1312
+ so, use the directive
1313
+ [Toys::DSL::Tool#truncate_load_path!](https://dazuma.github.io/toys/gems/toys-core/latest/Toys/DSL/Tool#truncate_load_path!-instance_method). This directive removes all
1314
+ directories further down the search path. It can be used, for example, to
1315
+ disable global tools when you run Toys from the current directory. It can also
1316
+ be useful if you are using [Bundler integration](#Using_bundler_with_a_tool) to
1317
+ prevent bundle conflicts with parent directories, by disabling tools from
1318
+ parent directories.
1319
+
1320
+ The `truncate_load_path!` directive works only if no tools from further down
1321
+ the search path have been loaded yet. It will raise
1322
+ [Toys::ToolDefinitionError](https://dazuma.github.io/toys/gems/toys-core/latest/Toys/ToolDefinitionError)
1323
+ if it fails to truncate the load path. In most cases, Toys is very smart about
1324
+ loading tools only when needed, but there are exceptions. To minimize the
1325
+ chance of problems, if you need to use `truncate_load_path!`, locate it as
1326
+ early as possible in your Toys files, typically at the top of the
1327
+ [index file](#Index_files).
1304
1328
 
1305
1329
  ## The execution environment
1306
1330
 
@@ -1308,9 +1332,9 @@ This section describes the context and resources available to your tool when it
1308
1332
  is running; that is, what you can call from your tool's `run` method.
1309
1333
 
1310
1334
  Each tool is defined as a class that subclasses
1311
- [Toys::Context](https://dazuma.github.io/toys/gems/toys-core/latest/Toys/Context). The base
1312
- class defines a number of methods, and provides access to a variety of data and
1313
- objects relevant to your tool. We have already seen earlier how to use the
1335
+ [Toys::Context](https://dazuma.github.io/toys/gems/toys-core/latest/Toys/Context).
1336
+ The base class defines helper methods, and provides access to a variety of data
1337
+ and objects relevant to your tool. We have already seen earlier how to use the
1314
1338
  [Toys::Context#get](https://dazuma.github.io/toys/gems/toys-core/latest/Toys/Context#get-instance_method)
1315
1339
  method to retrieve option values, and how to use the
1316
1340
  [Toys::Context#exit](https://dazuma.github.io/toys/gems/toys-core/latest/Toys/Context#exit-instance_method)
@@ -1380,8 +1404,8 @@ A common operation a tool might want to do is "call" another tool. This can be
1380
1404
  done via the CLI object, which you can retrieve using the `CLI` key or the
1381
1405
  [Toys::Context#cli method](https://dazuma.github.io/toys/gems/toys-core/latest/Toys/Context#cli-instance_method).
1382
1406
  These return the current instance of
1383
- [Toys::CLI](https://dazuma.github.io/toys/gems/toys-core/latest/Toys/CLI) which is the
1384
- "main" interface to Toys. In particular, it provides the
1407
+ [Toys::CLI](https://dazuma.github.io/toys/gems/toys-core/latest/Toys/CLI) which
1408
+ is the "main" interface to Toys. In particular, it provides the
1385
1409
  [Toys::CLI#run method](https://dazuma.github.io/toys/gems/toys-core/latest/Toys/CLI#run-instance_method)
1386
1410
  which can be used to call another tool:
1387
1411
 
@@ -1799,8 +1823,8 @@ directive by setting properties on the template object.
1799
1823
 
1800
1824
  Finally, templates are classes, and you can create a template directly as a
1801
1825
  class by including the
1802
- [Toys::Template](https://dazuma.github.io/toys/gems/toys-core/latest/Toys/Template) module
1803
- in your class definition.
1826
+ [Toys::Template](https://dazuma.github.io/toys/gems/toys-core/latest/Toys/Template)
1827
+ module in your class definition.
1804
1828
 
1805
1829
  class GreetTemplate
1806
1830
  include Toys::Template
@@ -2060,6 +2084,8 @@ tool is *executed*. This assumes the bundle is already installed, and brings
2060
2084
  the appropriate gems into the Ruby load path. That is, it's basically the same
2061
2085
  as `bundle exec`, but it applies only to the running tool.
2062
2086
 
2087
+ #### Applying bundler to all subtools
2088
+
2063
2089
  In many cases, you might find that bundler is needed for many or most of the
2064
2090
  tools you write for a particular project. In this case, you might find it
2065
2091
  convenient to use
@@ -2090,7 +2116,7 @@ for more information on `subtool_apply`.
2090
2116
  By default, the `:bundler` mixin will look for a `Gemfile` within the `.toys`
2091
2117
  directory (if your tool is defined in one), and if one is not found there,
2092
2118
  within the [context directory](#The_context_directory) (the directory
2093
- containing your `.toys` directory or `.toys.rb`file), and if one still is not
2119
+ containing your `.toys` directory or `.toys.rb` file), and if one still is not
2094
2120
  found, in the current working directory. You can change this behavior by
2095
2121
  passing an option to the `:bundler` mixin. For example, you can search only the
2096
2122
  current working directory by passing `search_dirs: :current` as such:
@@ -2100,7 +2126,24 @@ current working directory by passing `search_dirs: :current` as such:
2100
2126
  # etc...
2101
2127
  end
2102
2128
 
2103
- You can also pass a specific directory path to this option.
2129
+ The `:search_dirs` option takes a either directory path (as a string) or a
2130
+ symbol indicating a "semantic" directory. You can also pass an array of
2131
+ directories that will be searched in order. For each directory, Toys will look
2132
+ for a file called `.gems.rb`, `gems.rb`, or `Gemfile` (in that order) and use
2133
+ the first one that it finds.
2134
+
2135
+ The supported "semantic directory" symbols are `:current` indicating the
2136
+ current working directory, `:context` indicating the context directory, and
2137
+ `:toys` indicating the Toys directory in which the tool is defined.
2138
+ Furthermore, the semantic directory `:toys` is treated specially in that it
2139
+ looks up the `.toys` directory hierarchy. So if your tool is defined in
2140
+ `.toys/foo/bar.rb`, it will look for a Gemfile first in `.toys/foo/` and then
2141
+ in `.toys/`. Additionally, when looking for a Gemfile in `:toys`, it searches
2142
+ only for `.gems.rb` and `Gemfile`. A file called `gems.rb` is not treated as a
2143
+ Gemfile under the `:toys` directory, because it could be a tool.
2144
+
2145
+ The default gemfile search path, if you do not provide the `search_dirs:`
2146
+ option, is equivalent to `[:toys, :context, :current]`.
2104
2147
 
2105
2148
  If the bundle is not installed, or is out of date, Toys will ask you whether
2106
2149
  you want it to install the bundle first before running the tool. A tool can
@@ -2143,6 +2186,48 @@ a different bundle. If you need to do this, use the
2143
2186
  method from the `:exec` mixin, to call the tool. This method spawns a separate
2144
2187
  process with a clean Bundler setup for running the tool.
2145
2188
 
2189
+ #### When a bundle is needed to define a tool
2190
+
2191
+ Usually, the `:bundler` mixin sets up your bundle when the tool is *executed*.
2192
+ However, occasionally, you need the gems in the bundle to *define* a tool. This
2193
+ might happen, for instance, if your bundle includes gesm that define mixins or
2194
+ templates used by your tool.
2195
+
2196
+ If you need the bundle set up immediately because its gems are needed by the
2197
+ tool definition, pass the `static: true` option when including the `:bundler`
2198
+ mixin. For example, if you are using the
2199
+ [flame_server_toys](https://github.com/AlexWayfer/flame_server_toys) gem, which
2200
+ provides a template that generates tools for the
2201
+ [Flame](https://github.com/AlexWayfer/flame) web framework, you could include
2202
+ the `flame_server_toys` gem in your Gemfile, and make it available for defining
2203
+ tools:
2204
+
2205
+ # Set up the bundle immediately.
2206
+ include :bundler, static: true
2207
+
2208
+ # Now you can use the gems in the bundle when defining tools.
2209
+ require "flame_server_toys"
2210
+ expand FlameServerToys::Template
2211
+
2212
+ There is a big caveat to using `static: true`, which is that you are setting up
2213
+ a bundle immediately, and as a result any subsequent attempt to set up or use a
2214
+ different bundle will fail. (See the section on
2215
+ [bundle conflicts](#Solving_bundle_conflicts) for a discussion of other reasons
2216
+ this can happen.) As a result, it's best not to use `static: true` unless you
2217
+ *really* need it to define tools. If you do run into this problem, here are two
2218
+ things you could try:
2219
+
2220
+ 1. "Scope" the bundle to the tool or the namespace where you need it. Toys
2221
+ makes an effort not to define a tool unless you actually need to execute it
2222
+ or one of its subtools, so if you can locate `include :bundler` inside just
2223
+ the tool or namespace that needs it, you might be able to avoid conflicts.
2224
+
2225
+ 2. Failing that, if you need a particular gem in order to define a tool, you
2226
+ could consider activating the gem directly rather than as part of a bundle.
2227
+ See the following section on
2228
+ [Activating gems directly](#Activating_gems_directly) for details on this
2229
+ technique.
2230
+
2146
2231
  ### Activating gems directly
2147
2232
 
2148
2233
  Although we recommend the `:bundler` mixin for most cases, it is also possible
@@ -2197,22 +2282,35 @@ to ensure highline is installed while the tool is being defined.
2197
2282
  end
2198
2283
  end
2199
2284
 
2200
- If you are not in the Toys DSL context—for example from a class-based
2201
- mixin—you should use
2202
- [Toys::Utils::Gems.activate](https://dazuma.github.io/toys/gems/toys-core/latest/Toys/Utils/Gems#activate-class_method)
2203
- instead. (Note that you must `require "toys/utils/gems"` explicitly before
2204
- invoking the
2285
+ Note these methods are a bit different from the
2286
+ [gem method](http://ruby-doc.org/stdlib/libdoc/rubygems/rdoc/Kernel.html)
2287
+ provided by Rubygems. The Toys version attempts to install a missing gem for
2288
+ you, whereas Rubygems will just throw an exception.
2289
+
2290
+ ### Activating gems outside the DSL
2291
+
2292
+ The above techniques for installing a bundle or activating a gem directly, are
2293
+ all part of the tool definition DSL. However, the functionality is also
2294
+ available outside the DSL---for example, from a class-based mixin.
2295
+
2296
+ To set up a bundle, call
2297
+ [Toys::Utils::Gems#bundle](https://dazuma.github.io/toys/gems/toys-core/latest/Toys/Utils/Gems#bundle-instance_method).
2298
+ (Note that you must `require "toys/utils/gems"` explicitly before invoking the
2205
2299
  [Toys::Utils::Gems](https://dazuma.github.io/toys/gems/toys-core/latest/Toys/Utils/Gems)
2206
2300
  class because, like all classes under `Toys::Utils`, Toys does not load it
2207
2301
  automatically.) For example:
2208
2302
 
2209
2303
  require "toys/utils/gems"
2210
- Toys::Utils::Gems.activate("highline", "~> 2.0")
2304
+ gem_utils = Toys::Utils::Gems.new
2305
+ gem_utils.bundle(search_dirs: Dir.getwd)
2211
2306
 
2212
- Note these methods are a bit different from the
2213
- [gem method](http://ruby-doc.org/stdlib/libdoc/rubygems/rdoc/Kernel.html)
2214
- provided by Rubygems. The Toys version attempts to install a missing gem for
2215
- you, whereas Rubygems will just throw an exception.
2307
+ To activate single gems explicitly, call
2308
+ [Toys::Utils::Gems#activate](https://dazuma.github.io/toys/gems/toys-core/latest/Toys/Utils/Gems#activate-instance_method).
2309
+ For example:
2310
+
2311
+ require "toys/utils/gems"
2312
+ gem_utils = Toys::Utils::Gems.new
2313
+ gem_utils.activate("highline", "~> 2.0")
2216
2314
 
2217
2315
  ### Useful gems
2218
2316
 
@@ -2319,7 +2417,7 @@ than declarative.
2319
2417
  The Toys approach to build tools simply embraces the fact that our build
2320
2418
  processes already tend to be imperative. So unlike Rake, Toys does not provide
2321
2419
  syntax for describing targets and dependencies, since we generally don't have
2322
- them in Ruby programs. Instead, it is optimized for writing tools.
2420
+ them in Ruby programs. Instead, it is optimized for writing imperative tools.
2323
2421
 
2324
2422
  For example, Rake provides a primitive mechanism for passing arguments to a
2325
2423
  task, but it is clumsy and quite different from most unix programs. However, to
@@ -42,6 +42,12 @@ module Toys
42
42
  #
43
43
  DATA_DIR_NAME = ".data"
44
44
 
45
+ ##
46
+ # Standard lib directory name in a toys configuration.
47
+ # @return [String]
48
+ #
49
+ LIB_DIR_NAME = ".lib"
50
+
45
51
  ##
46
52
  # Name of the standard toys executable.
47
53
  # @return [String]
@@ -99,11 +105,12 @@ module Toys
99
105
  preload_file_name: PRELOAD_FILE_NAME,
100
106
  preload_dir_name: PRELOAD_DIR_NAME,
101
107
  data_dir_name: DATA_DIR_NAME,
108
+ lib_dir_name: LIB_DIR_NAME,
102
109
  extra_delimiters: EXTRA_DELIMITERS,
103
110
  middleware_stack: default_middleware_stack,
104
111
  template_lookup: default_template_lookup
105
112
  )
106
- add_standard_paths(cur_dir: cur_dir)
113
+ add_standard_paths(cur_dir: cur_dir, toys_dir_name: CONFIG_DIR_NAME)
107
114
  end
108
115
 
109
116
  private
@@ -125,8 +132,9 @@ module Toys
125
132
  # directories, or `nil` to use the defaults.
126
133
  # @return [self]
127
134
  #
128
- def add_standard_paths(cur_dir: nil, global_dirs: nil)
135
+ def add_standard_paths(cur_dir: nil, global_dirs: nil, toys_dir_name: nil)
129
136
  cur_dir ||= ::Dir.pwd
137
+ cur_dir = skip_toys_dir(cur_dir, toys_dir_name) if toys_dir_name
130
138
  global_dirs ||= default_global_dirs
131
139
  add_search_path_hierarchy(start: cur_dir, terminate: global_dirs)
132
140
  global_dirs.each { |path| add_search_path(path) }
@@ -135,6 +143,20 @@ module Toys
135
143
  self
136
144
  end
137
145
 
146
+ # Step out of any toys dir
147
+ def skip_toys_dir(dir, toys_dir_name)
148
+ cur_dir = dir
149
+ loop do
150
+ parent = ::File.dirname(dir)
151
+ return cur_dir if parent == dir
152
+ if ::File.basename(dir) == toys_dir_name
153
+ cur_dir = dir = parent
154
+ else
155
+ dir = parent
156
+ end
157
+ end
158
+ end
159
+
138
160
  # rubocop:disable Metrics/MethodLength
139
161
 
140
162
  ##
@@ -20,7 +20,9 @@ module Toys
20
20
  # @param name [String] Name of the tool to create. Defaults to
21
21
  # {DEFAULT_TOOL_NAME}.
22
22
  # @param paths [Array<String>] An array of glob patterns indicating what
23
- # to clean.
23
+ # to clean. You can also include the symbol `:gitignore` which will
24
+ # clean all items covered by `.gitignore` files, if contained in a
25
+ # git working tree.
24
26
  #
25
27
  def initialize(name: nil, paths: [])
26
28
  @name = name
@@ -57,22 +59,69 @@ module Toys
57
59
  tool(template.name) do
58
60
  desc "Clean built files and directories."
59
61
 
62
+ static :template_paths, template.paths
63
+
60
64
  include :fileutils
65
+ include :exec
61
66
 
62
- to_run do
63
- ::Dir.chdir(context_directory || ::Dir.getwd) do
64
- files = []
65
- template.paths.each do |pattern|
66
- files.concat(::Dir.glob(pattern))
67
- end
68
- files.uniq.each do |file|
69
- if ::File.exist?(file)
70
- rm_rf(file)
71
- puts "Cleaned: #{file}"
67
+ # @private
68
+ def run
69
+ cd(context_directory || ::Dir.getwd) do
70
+ template_paths.each do |elem|
71
+ case elem
72
+ when :gitignore
73
+ clean_gitignore
74
+ when ::String
75
+ clean_pattern(elem)
76
+ else
77
+ raise "Unknown path in clean: #{elem.inspect}"
72
78
  end
73
79
  end
74
80
  end
75
81
  end
82
+
83
+ # @private
84
+ def clean_gitignore
85
+ result = exec(["git", "rev-parse", "--is-inside-work-tree"], out: :null, err: :null)
86
+ unless result.success?
87
+ logger.error("Skipping :gitignore because we don't seem to be in a git directory")
88
+ return
89
+ end
90
+ clean_gitignore_dir(".")
91
+ end
92
+
93
+ # @private
94
+ def clean_gitignore_dir(dir)
95
+ children = dir_children(dir)
96
+ result = exec(["git", "check-ignore", "--stdin"],
97
+ in: :controller, out: :capture) do |controller|
98
+ children.each { |child| controller.in.puts(child) }
99
+ end
100
+ result.captured_out.split("\n").each { |path| clean_path(path) }
101
+ children = dir_children(dir) if result.success?
102
+ children.each { |child| clean_gitignore_dir(child) if ::File.directory?(child) }
103
+ end
104
+
105
+ # @private
106
+ def dir_children(dir)
107
+ ::Dir.entries(dir)
108
+ .reject { |entry| entry =~ /^\.\.?$/ }
109
+ .sort
110
+ .map { |entry| ::File.join(dir, entry) }
111
+ end
112
+
113
+ # @private
114
+ def clean_pattern(pattern)
115
+ ::Dir.glob(pattern) { |path| clean_path(path) }
116
+ end
117
+
118
+ # @private
119
+ def clean_path(path)
120
+ if ::File.exist?(path)
121
+ rm_rf(path)
122
+ puts "Cleaned: #{path}"
123
+ end
124
+ end
76
125
  end
77
126
  end
78
127
  end
@@ -5,5 +5,5 @@ module Toys
5
5
  # Current version of the Toys command line executable.
6
6
  # @return [String]
7
7
  #
8
- VERSION = "0.10.3"
8
+ VERSION = "0.11.2"
9
9
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: toys
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.3
4
+ version: 0.11.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Azuma
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-04 00:00:00.000000000 Z
11
+ date: 2020-09-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: toys-core
@@ -16,168 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 0.10.3
19
+ version: 0.11.2
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 0.10.3
27
- - !ruby/object:Gem::Dependency
28
- name: did_you_mean
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '1.0'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: '1.0'
41
- - !ruby/object:Gem::Dependency
42
- name: highline
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '2.0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '2.0'
55
- - !ruby/object:Gem::Dependency
56
- name: minitest
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: '5.14'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: '5.14'
69
- - !ruby/object:Gem::Dependency
70
- name: minitest-focus
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - "~>"
74
- - !ruby/object:Gem::Version
75
- version: '1.1'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - "~>"
81
- - !ruby/object:Gem::Version
82
- version: '1.1'
83
- - !ruby/object:Gem::Dependency
84
- name: minitest-rg
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - "~>"
88
- - !ruby/object:Gem::Version
89
- version: '5.2'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - "~>"
95
- - !ruby/object:Gem::Version
96
- version: '5.2'
97
- - !ruby/object:Gem::Dependency
98
- name: rake
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - "~>"
102
- - !ruby/object:Gem::Version
103
- version: '13.0'
104
- type: :development
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - "~>"
109
- - !ruby/object:Gem::Version
110
- version: '13.0'
111
- - !ruby/object:Gem::Dependency
112
- name: rdoc
113
- requirement: !ruby/object:Gem::Requirement
114
- requirements:
115
- - - "~>"
116
- - !ruby/object:Gem::Version
117
- version: 6.1.2
118
- type: :development
119
- prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- requirements:
122
- - - "~>"
123
- - !ruby/object:Gem::Version
124
- version: 6.1.2
125
- - !ruby/object:Gem::Dependency
126
- name: redcarpet
127
- requirement: !ruby/object:Gem::Requirement
128
- requirements:
129
- - - "~>"
130
- - !ruby/object:Gem::Version
131
- version: '3.5'
132
- type: :development
133
- prerelease: false
134
- version_requirements: !ruby/object:Gem::Requirement
135
- requirements:
136
- - - "~>"
137
- - !ruby/object:Gem::Version
138
- version: '3.5'
139
- - !ruby/object:Gem::Dependency
140
- name: rspec
141
- requirement: !ruby/object:Gem::Requirement
142
- requirements:
143
- - - "~>"
144
- - !ruby/object:Gem::Version
145
- version: '3.9'
146
- type: :development
147
- prerelease: false
148
- version_requirements: !ruby/object:Gem::Requirement
149
- requirements:
150
- - - "~>"
151
- - !ruby/object:Gem::Version
152
- version: '3.9'
153
- - !ruby/object:Gem::Dependency
154
- name: rubocop
155
- requirement: !ruby/object:Gem::Requirement
156
- requirements:
157
- - - "~>"
158
- - !ruby/object:Gem::Version
159
- version: 0.79.0
160
- type: :development
161
- prerelease: false
162
- version_requirements: !ruby/object:Gem::Requirement
163
- requirements:
164
- - - "~>"
165
- - !ruby/object:Gem::Version
166
- version: 0.79.0
167
- - !ruby/object:Gem::Dependency
168
- name: yard
169
- requirement: !ruby/object:Gem::Requirement
170
- requirements:
171
- - - "~>"
172
- - !ruby/object:Gem::Version
173
- version: 0.9.24
174
- type: :development
175
- prerelease: false
176
- version_requirements: !ruby/object:Gem::Requirement
177
- requirements:
178
- - - "~>"
179
- - !ruby/object:Gem::Version
180
- version: 0.9.24
26
+ version: 0.11.2
181
27
  description: Toys is a configurable command line tool. Write commands in Ruby using
182
28
  a simple DSL, and Toys will provide the command line executable and take care of
183
29
  all the details such as argument parsing, online help, and error reporting. Toys
@@ -217,10 +63,10 @@ homepage: https://github.com/dazuma/toys
217
63
  licenses:
218
64
  - MIT
219
65
  metadata:
220
- changelog_uri: https://github.com/dazuma/toys/blob/master/toys/CHANGELOG.md
66
+ changelog_uri: https://dazuma.github.io/toys/gems/toys/v0.11.2/file.CHANGELOG.html
221
67
  source_code_uri: https://github.com/dazuma/toys
222
68
  bug_tracker_uri: https://github.com/dazuma/toys/issues
223
- documentation_uri: https://dazuma.github.io/toys/gems/toys/v0.10.3
69
+ documentation_uri: https://dazuma.github.io/toys/gems/toys/v0.11.2
224
70
  post_install_message:
225
71
  rdoc_options: []
226
72
  require_paths: