toys 0.10.4 → 0.11.3

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: 2df55870f3530617a4961bb0cfa09d0752bb13e99f7642a4156ab4b7ffea3a8c
4
- data.tar.gz: 74131a75411c11703347193f167c916e351fa3582401d0505036cd74dbb9911c
3
+ metadata.gz: b7352461981cbfeeba4271c71e58d864f210aab1e42ff572f94d15b56be16cbc
4
+ data.tar.gz: 22c10a76a8b53a8482b6b9b46650d005fb2c94a8c8f3d8be59d7e2f9720a243e
5
5
  SHA512:
6
- metadata.gz: ff5a5e3e2c2fea1bebdcfbeef064bd51d5a587a48077b7ee6c6b4befe926433d0318ce5c4b8c63a067e8b4e6dbd21f191c86b11844e8e1ff9d8c6096cffad996
7
- data.tar.gz: 464d5d87896965c77182d6f7f3793b23bbf9797439619c01b9142516bb71077f44a5c53e81492017890e8fd9db1cb7d5c9e83bed1ea68741f716d94833e7e3b6
6
+ metadata.gz: 4f2831bcebdf9606dba1d59dec4a8e1d3b997c03abaf54149c5e7f792e5aabca6e84d2f18af5aab2c88e6192645ffd3f2c954ab5913a6237368cd85c386e6b4b
7
+ data.tar.gz: b4f06825d9838ba0ddbafb607378b5a60996398f4a6efdce023169e07f7fb6f639e6d43f69edd3874b5e8af5364761e96c87048a0332226bb023dab04c2b35e6
@@ -1,23 +1,56 @@
1
1
  # Release History
2
2
 
3
- ### 0.10.4 / 2020-07-11
3
+ ### v0.11.3 / 2020-09-13
4
+
5
+ * FIXED: The Exec mixin recognizes the argv0 option, and logs it appropriately
6
+
7
+ ### v0.11.2 / 2020-09-06
8
+
9
+ * FIXED: Don't get confused when running toys from within a toys directory
10
+ * FIXED: Fix a JRuby-specific race condition when capturing exec streams
11
+
12
+ ### v0.11.1 / 2020-08-24
13
+
14
+ * FIXED: The `.lib` directory actually works as advertised.
15
+
16
+ ### v0.11.0 / 2020-08-21
17
+
18
+ * ADDED: The toys search path can be truncated using the `truncate_load_path!` directive.
19
+ * ADDED: The `:clean` template recognizes `:gitignore` as a path indicating all gitignored files.
20
+ * IMPROVED: Generated help for delegates now includes the information for the target tool, plus subtools of the delegate.
21
+ * IMPROVED: The `:bundler` mixin searches for `gems.rb` and `.gems.rb` in addition to `Gemfile`.
22
+ * IMPROVED: The `:budnler` mixin can load a specific Gemfile path.
23
+ * FIXED: The loader can now find `.data` and `.lib` directories at the root level of a `.toys` directory.
24
+ * FIXED: Exec::Result correctly reports processes that terminated due to signals.
25
+ * FIXED: Fixed a rare Exec capture failure that resulted from a race condition when closing streams.
26
+ * DOCS: The Toys user guide now covers static bundle loading and `truncate_load_path!`.
27
+
28
+ ### v0.10.5 / 2020-07-18
29
+
30
+ * IMPROVED: The bundler mixin silences bundler output during bundle setup.
31
+ * 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.
32
+ * IMPROVED: The bundler mixin automatically updates the bundle if install fails (typically because a transitive dependency has been explicitly updated.)
33
+ * FIXED: Some cases of transitive dependency handling by the bundler mixin.
34
+ * FIXED: Fixed a crash when computing suggestions, when running with a bundle on Ruby 2.6 or earlier.
35
+
36
+ ### v0.10.4 / 2020-07-11
4
37
 
5
38
  * IMPROVED: Bundler integration can now handle Toys itself being in the bundle, as long as the version requirements cover the running Toys version.
6
39
  * IMPROVED: Passing `static: true` to the `:bundler` mixin installs the bundle at definition rather than execution time.
7
40
 
8
- ### 0.10.3 / 2020-07-04
41
+ ### v0.10.3 / 2020-07-04
9
42
 
10
43
  * FIXED: The `exec_separate_tool` method in the `:exec` mixin no longer throws ENOEXEC on Windows.
11
44
 
12
- ### 0.10.2 / 2020-07-03
45
+ ### v0.10.2 / 2020-07-03
13
46
 
14
47
  * FIXED: The load path no longer loses the toys and toys-core directories after a bundle install.
15
48
 
16
- ### 0.10.1 / 2020-03-07
49
+ ### v0.10.1 / 2020-03-07
17
50
 
18
51
  * FIXED: Setting `:exit_on_nonzero_status` explicitly to false now works as expected.
19
52
 
20
- ### 0.10.0 / 2020-02-24
53
+ ### v0.10.0 / 2020-02-24
21
54
 
22
55
  * ADDED: `:bundler` mixin that installs and sets up a bundle for the tool
23
56
  * ADDED: `bundler` options in the standard templates, to run those tools in a bundle
@@ -33,26 +66,26 @@
33
66
  * FIXED: `rdoc` template crashed if any nonstandard options were given.
34
67
  * FIXED: `rubocop` template would abort prematurely if standard streams were redirected.
35
68
 
36
- ### 0.9.4 / 2020-01-26
69
+ ### v0.9.4 / 2020-01-26
37
70
 
38
71
  * FIXED: Crash in the loader when a non-ruby file appears in a toys directory
39
72
 
40
- ### 0.9.3 / 2020-01-05
73
+ ### v0.9.3 / 2020-01-05
41
74
 
42
75
  * FIXED: `delegate_to` directive could crash if an overriding tool has already been defined.
43
76
  * FIXED: A Ruby 2.7 warning when reporting a Toys file syntax error.
44
77
 
45
- ### 0.9.2 / 2020-01-03
78
+ ### v0.9.2 / 2020-01-03
46
79
 
47
80
  * IMPROVED: Mixins can now take real keyword arguments, and will pass them on properly to `on_initialize` and `on_include` blocks.
48
81
  * 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.
49
82
 
50
- ### 0.9.1 / 2019-12-22
83
+ ### v0.9.1 / 2019-12-22
51
84
 
52
85
  * IMPROVED: `delegate_to` and `alias_tool` can take symbols as well as strings.
53
86
  * DOCS: Fixed user guide internal links on rubydoc.info.
54
87
 
55
- ### 0.9.0 / 2019-12-02
88
+ ### v0.9.0 / 2019-12-02
56
89
 
57
90
  * 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.
58
91
  * 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.)
@@ -63,12 +96,12 @@
63
96
  * 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.
64
97
  * FIXED: The the `tool` directive no longer crashes if not passed a block.
65
98
 
66
- ### 0.8.1 / 2019-11-19
99
+ ### v0.8.1 / 2019-11-19
67
100
 
68
101
  * FIXED: Listing subtools would crash if a broken alias was present.
69
102
  * DOCUMENTATION: Switched from redcarpet to kramdown, and tried to make some structural fixes.
70
103
 
71
- ### 0.8.0 / 2019-06-20
104
+ ### v0.8.0 / 2019-06-20
72
105
 
73
106
  This is a major update with significant new features and a bunch of fixes.
74
107
  It does include a few minor backward-incompatible changes. All signifiant
@@ -122,18 +155,18 @@ Details:
122
155
 
123
156
  Additionally, a significant amount of internal reorganization and cleanup happened in the toys-core gem. See the changelog for toys-core for more details.
124
157
 
125
- ### 0.7.0 / 2019-01-23
158
+ ### v0.7.0 / 2019-01-23
126
159
 
127
160
  * ADDED: A template for creating tools that invoke RSpec.
128
161
  * ADDED: Flag groups, which enforce policies around which flags are required.
129
162
  * CHANGED: Flags within a group are sorted in the help screens.
130
163
  * IMPROVED: The minitest template now honors all standard minitest flags.
131
164
 
132
- ### 0.6.1 / 2019-01-07
165
+ ### v0.6.1 / 2019-01-07
133
166
 
134
167
  * FIXED: The presence of aliases caused subtool listing to crash.
135
168
 
136
- ### 0.6.0 / 2018-10-22
169
+ ### v0.6.0 / 2018-10-22
137
170
 
138
171
  * FIXED: Build tools cd into the context directory when running.
139
172
  * FIXED: Rakefiles are evaluated and tasks are run in the Rakefile's directory.
@@ -145,7 +178,7 @@ Additionally, a significant amount of internal reorganization and cleanup happen
145
178
  * IMPROVED: Non-runnable namespaces are no longer displayed in recursive subtool
146
179
  lists if their children are already displayed.
147
180
 
148
- ### 0.5.0 / 2018-10-07
181
+ ### v0.5.0 / 2018-10-07
149
182
 
150
183
  * ADDED: Period and colon are recognized as tool path delimiters.
151
184
  * ADDED: New rake template that supports loading rake tasks as tools.
@@ -156,31 +189,31 @@ Additionally, a significant amount of internal reorganization and cleanup happen
156
189
  * IMPROVED: The tool directive can now take an `if_defined` argument.
157
190
  * FIXED: Template instantiation was failing if the hosting tool was priority-masked.
158
191
 
159
- ### 0.4.5 / 2018-08-05
192
+ ### v0.4.5 / 2018-08-05
160
193
 
161
194
  * CHANGED: Dropped preload file feature
162
195
 
163
- ### 0.4.4 / 2018-07-21
196
+ ### v0.4.4 / 2018-07-21
164
197
 
165
198
  * FIXED: Utils::Exec wasn't closing streams after copying.
166
199
  * IMPROVED: Utils::Exec::Controller can capture or redirect the remainder of a controlled stream.
167
200
  * ADDED: Terminal#ask
168
201
 
169
- ### 0.4.3 / 2018-07-13
202
+ ### v0.4.3 / 2018-07-13
170
203
 
171
204
  * IMPROVED: Exec mixin methods can now spawn subprocesses in the background
172
205
  * IMPROVED: Exec mixin capture methods can now yield a controller
173
206
 
174
- ### 0.4.2 / 2018-07-08
207
+ ### v0.4.2 / 2018-07-08
175
208
 
176
209
  * FIXED: Raise an error rather than cause unexpected behavior if a mixin is included twice.
177
210
  * IMPROVED: The `include?` method extended to support mixin names in a tool dsl.
178
211
 
179
- ### 0.4.1 / 2018-07-03
212
+ ### v0.4.1 / 2018-07-03
180
213
 
181
214
  * FIXED: Terminal#confirm uppercased "N" for the wrong default.
182
215
 
183
- ### 0.4.0 / 2018-07-03
216
+ ### v0.4.0 / 2018-07-03
184
217
 
185
218
  Now declaring this alpha quality. Backward-incompatible changes are still
186
219
  possible from this point, but I'll try to avoid them.
@@ -190,24 +223,24 @@ possible from this point, but I'll try to avoid them.
190
223
  * IMPROVED: Toys::Utils::Gems can suppress the confirmation prompt
191
224
  * IMPROVED: Magic comments are now honored in toys files.
192
225
 
193
- ### 0.3.11 / 2018-07-02
226
+ ### v0.3.11 / 2018-07-02
194
227
 
195
228
  * CHANGED: Require Ruby 2.3 or later
196
229
  * CHANGED: Renamed "set" directive to "static" to reduce confusion with Tool#set.
197
230
  * ADDED: Convenience methods for getting option values
198
231
 
199
- ### 0.3.10 / 2018-06-30
232
+ ### v0.3.10 / 2018-06-30
200
233
 
201
234
  * CHANGED: Dropped Tool#option. Use Tool#get instead.
202
235
  * CHANGED: "run" directive renamed to "to_run"
203
236
  * CHANGED: Highline mixin now uses Highline 2.0
204
237
  * ADDED: Mixins can provide initializers
205
238
 
206
- ### 0.3.9.1 / 2018-06-24
239
+ ### v0.3.9.1 / 2018-06-24
207
240
 
208
241
  * FIXED: Built-in flags were interfering with disable_argument_parsing
209
242
 
210
- ### 0.3.9 / 2018-06-24
243
+ ### v0.3.9 / 2018-06-24
211
244
 
212
245
  * CHANGED: Removed alias_as directive since it's incompatible with selective loading.
213
246
  * ADDED: Ability to define named templates in Toys files
@@ -217,18 +250,18 @@ possible from this point, but I'll try to avoid them.
217
250
  * IMPROVED: Acceptors can be looked up recursively in the same way as mixins and templates
218
251
  * FIXED: Templates were not activating needed gems
219
252
 
220
- ### 0.3.8 / 2018-06-10
253
+ ### v0.3.8 / 2018-06-10
221
254
 
222
255
  * CHANGED: Renamed helpers to mixins.
223
256
  * CHANGED: Renamed :in_from, :out_to, and :err_to exec options to :in, :out, :err
224
257
  * IMPROVED: Exec raises an error if passed an unknown option.
225
258
  * IMPROVED: Exec now accepts nearly all the same stream specifications as Process#spawn.
226
259
 
227
- ### 0.3.7.1 / 2018-05-30
260
+ ### v0.3.7.1 / 2018-05-30
228
261
 
229
262
  * FIXED: Fix crash in system update.
230
263
 
231
- ### 0.3.7 / 2018-05-30
264
+ ### v0.3.7 / 2018-05-30
232
265
 
233
266
  * CHANGED: Execution runs in the same scope as the DSL, which lets us use normal methods instead of helper-blocks.
234
267
  * CHANGED: Renamed "script" to "run", and allow setting of runnable by defining a "run" method
@@ -237,7 +270,7 @@ possible from this point, but I'll try to avoid them.
237
270
  * CHANGED: Removed spinner helper and added terminal helper.
238
271
  * ADDED: Helper modules scoped to the tool hierarchy
239
272
 
240
- ### 0.3.6 / 2018-05-21
273
+ ### v0.3.6 / 2018-05-21
241
274
 
242
275
  * CHANGED: Removed Context#new_cli and exposed Context#cli instead.
243
276
  * CHANGED: Raises ToolDefinitionError if you declare a duplicate flag.
@@ -246,13 +279,13 @@ possible from this point, but I'll try to avoid them.
246
279
  * IMPROVED: Support custom acceptors.
247
280
  * IMPROVED: Highline helper automatically sets use_color based on the type of stdout.
248
281
 
249
- ### 0.3.5 / 2018-05-15
282
+ ### v0.3.5 / 2018-05-15
250
283
 
251
284
  * CHANGED: Flag and arg blocks in the DSL have an interface more similar to the rest of the DSL.
252
285
  * CHANGED: Renamed `execute do` to `script do`.
253
286
  * IMPROVED: Help display uses `less` if available.
254
287
 
255
- ### 0.3.4 / 2018-05-14
288
+ ### v0.3.4 / 2018-05-14
256
289
 
257
290
  * CHANGED: Renamed switch to flag
258
291
  * CHANGED: Renamed docs: parameter again, to desc: and long_desc: to match tool desc.
@@ -269,7 +302,7 @@ possible from this point, but I'll try to avoid them.
269
302
  * FIXED: Subtools with no desc now properly pick up the default
270
303
  * FIXED: Usage errors and show-help now interact in the right way
271
304
 
272
- ### 0.3.3 / 2018-05-09
305
+ ### v0.3.3 / 2018-05-09
273
306
 
274
307
  * CHANGED: Renamed file_utils helper to fileutils.
275
308
  * CHANGED: Renamed doc: parameter to docs:
@@ -279,7 +312,7 @@ possible from this point, but I'll try to avoid them.
279
312
  * ADDED: WrappableString for descriptions and docs
280
313
  * IMPROVED: Descriptions can have multiple lines
281
314
 
282
- ### 0.3.2 / 2018-05-07
315
+ ### v0.3.2 / 2018-05-07
283
316
 
284
317
  * CHANGED: Split core engine out into separate "toys-core" gem. See the
285
318
  toys-core changelog for additional changes in core.
@@ -290,7 +323,7 @@ possible from this point, but I'll try to avoid them.
290
323
  * IMPROVED: Help shows the config file path on "--verbose".
291
324
  * IMPROVED: You can now run a sub-instance of toys from an executor.
292
325
 
293
- ### 0.3.1 / 2018-05-02
326
+ ### v0.3.1 / 2018-05-02
294
327
 
295
328
  * CHANGED: Subcommand display is now recursive by default.
296
329
  * IMPROVED: Improved error messaging for bad switch syntax.
@@ -299,6 +332,6 @@ possible from this point, but I'll try to avoid them.
299
332
  * DOCS: Completed a first pass on class and method documentation.
300
333
  * INTERNAL: Adjusted naming of switch-related methods.
301
334
 
302
- ### 0.3.0 / 2018-04-30
335
+ ### v0.3.0 / 2018-04-30
303
336
 
304
337
  * 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.4"
8
+ VERSION = "0.11.3"
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.4
4
+ version: 0.11.3
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-11 00:00:00.000000000 Z
11
+ date: 2020-09-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: toys-core
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 0.10.4
19
+ version: 0.11.3
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.4
26
+ version: 0.11.3
27
27
  description: Toys is a configurable command line tool. Write commands in Ruby using
28
28
  a simple DSL, and Toys will provide the command line executable and take care of
29
29
  all the details such as argument parsing, online help, and error reporting. Toys
@@ -63,10 +63,10 @@ homepage: https://github.com/dazuma/toys
63
63
  licenses:
64
64
  - MIT
65
65
  metadata:
66
- changelog_uri: https://github.com/dazuma/toys/blob/master/toys/CHANGELOG.md
66
+ changelog_uri: https://dazuma.github.io/toys/gems/toys/v0.11.3/file.CHANGELOG.html
67
67
  source_code_uri: https://github.com/dazuma/toys
68
68
  bug_tracker_uri: https://github.com/dazuma/toys/issues
69
- documentation_uri: https://dazuma.github.io/toys/gems/toys/v0.10.4
69
+ documentation_uri: https://dazuma.github.io/toys/gems/toys/v0.11.3
70
70
  post_install_message:
71
71
  rdoc_options: []
72
72
  require_paths: