toys 0.10.5 → 0.11.0

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: d4d27fd4743feddadec86f143f5d0a9d5afff98cf3b10afd18732d29f495db38
4
- data.tar.gz: bdc935b5876b1a1c7779a3fefc59ea9b6c506cf1f0eba67c54ff05a5e1e46013
3
+ metadata.gz: 93df1335be3b4e82bc30602ed8e78d8a04e99e1df6eecadb1a13430107c761c0
4
+ data.tar.gz: 448add98c695e182efcd00dd3995f4c62a8533f47dc8d80a915399a17ec584d5
5
5
  SHA512:
6
- metadata.gz: 9e8bcf630b41f3fe9a3c906460e5f40008b1a9190becf38ce3700308193240a9f5ec60c6ecec2dfd03bcf6eb8dafd77171c5039fa9dd239770d7f7251a6cf90f
7
- data.tar.gz: a5d4cc200823a52c4586d2109fb89e1ebd17737d191cea509b53e344a9868fddc1ccb05cb735b796c662fd297bb75a7d7078d2065df9ffb7799d78d122c6de3b
6
+ metadata.gz: '014558969bf84b3f37a8e1948eaeaa7a4acfc0a07b4cfda1a0ec50f1fc11691219fa659a81ed73a0470e1f04ba85311810a3a151d2f5422042c983e969560584'
7
+ data.tar.gz: 5fdb203c6b967e554bc16aeadd4d5e8dcccc931f11d04bca0e22d9b635727f7891b4a80363f4ac60b4e0d80ebdc39188595b3dce6e6a3dce72d9e27c83c14e86
@@ -1,10 +1,22 @@
1
1
  # Release History
2
2
 
3
+ ### 0.11.0 / 2020-08-21
4
+
5
+ * ADDED: The toys search path can be truncated using the `truncate_load_path!` directive.
6
+ * ADDED: The `:clean` template recognizes `:gitignore` as a path indicating all gitignored files.
7
+ * IMPROVED: Generated help for delegates now includes the information for the target tool, plus subtools of the delegate.
8
+ * IMPROVED: The `:bundler` mixin searches for `gems.rb` and `.gems.rb` in addition to `Gemfile`.
9
+ * IMPROVED: The `:budnler` mixin can load a specific Gemfile path.
10
+ * FIXED: The loader can now find `.data` and `.lib` directories at the root level of a `.toys` directory.
11
+ * FIXED: Exec::Result correctly reports processes that terminated due to signals.
12
+ * FIXED: Fixed a rare Exec capture failure that resulted from a race condition when closing streams.
13
+ * DOCS: The Toys user guide now covers static bundle loading and `truncate_load_path!`.
14
+
3
15
  ### 0.10.5 / 2020-07-18
4
16
 
5
17
  * IMPROVED: The bundler mixin silences bundler output during bundle setup.
6
18
  * 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.
7
- * IMPROVED: The bundler mixin utomatically updates the bundle if install fails (typically because a transitive dependency has been explicitly updated.)
19
+ * IMPROVED: The bundler mixin automatically updates the bundle if install fails (typically because a transitive dependency has been explicitly updated.)
8
20
  * FIXED: Some cases of transitive dependency handling by the bundler mixin.
9
21
  * FIXED: Fixed a crash when computing suggestions, when running with a bundle on Ruby 2.6 or earlier.
10
22
 
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
@@ -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
@@ -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.5"
8
+ VERSION = "0.11.0"
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.5
4
+ version: 0.11.0
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-19 00:00:00.000000000 Z
11
+ date: 2020-08-21 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.5
19
+ version: 0.11.0
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.5
26
+ version: 0.11.0
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://dazuma.github.io/toys/gems/toys/v0.10.5/file.CHANGELOG.html
66
+ changelog_uri: https://dazuma.github.io/toys/gems/toys/v0.11.0/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.5
69
+ documentation_uri: https://dazuma.github.io/toys/gems/toys/v0.11.0
70
70
  post_install_message:
71
71
  rdoc_options: []
72
72
  require_paths: