toys 0.14.7 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +24 -0
- data/LICENSE.md +1 -1
- data/README.md +5 -2
- data/builtins/system/test.rb +53 -35
- data/core-docs/toys/cli.rb +37 -64
- data/core-docs/toys/context.rb +51 -0
- data/core-docs/toys/core.rb +1 -1
- data/core-docs/toys/dsl/flag.rb +24 -1
- data/core-docs/toys/dsl/flag_group.rb +10 -2
- data/core-docs/toys/dsl/positional_arg.rb +16 -0
- data/core-docs/toys/dsl/tool.rb +144 -43
- data/core-docs/toys/middleware.rb +3 -2
- data/core-docs/toys/settings.rb +1 -1
- data/core-docs/toys/standard_mixins/bundler.rb +16 -1
- data/core-docs/toys/standard_mixins/exec.rb +25 -6
- data/core-docs/toys/standard_mixins/gems.rb +17 -3
- data/core-docs/toys/tool_definition.rb +125 -41
- data/core-docs/toys/utils/exec.rb +22 -1
- data/core-docs/toys/utils/standard_ui.rb +184 -0
- data/core-docs/toys-core.rb +51 -3
- data/docs/guide.md +152 -63
- data/lib/toys/standard_cli.rb +17 -2
- data/lib/toys/templates/gem_build.rb +13 -7
- data/lib/toys/templates/minitest.rb +47 -17
- data/lib/toys/templates/rake.rb +18 -6
- data/lib/toys/templates/rdoc.rb +28 -17
- data/lib/toys/templates/rspec.rb +18 -11
- data/lib/toys/templates/rubocop.rb +14 -8
- data/lib/toys/templates/yardoc.rb +46 -29
- data/lib/toys/testing.rb +1 -1
- data/lib/toys/version.rb +1 -1
- data/lib/toys.rb +22 -0
- metadata +8 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4cb07f9df7100f093730bc4029f1ae244f4417a353af98afe09e00981778ae78
|
4
|
+
data.tar.gz: 87d3c3ca9a0062190abf4070e223db59bfd61a2124739dcdbd61bceece277acb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e35f19f001aa9148439f2b9584d8e83d6b745dcd81a674f8994a4384754c6dfd4345812857f9670884696de0e6394fe0cf60fc40c5c8ab1426fa321c39e46276
|
7
|
+
data.tar.gz: e10c2526cb2c4c600512db26c65befc65f41257d275d89fe5b620a3b985bc36cbad489ebe5cae77ea6efbe49f93a940e22b5313b3fe6e80b8fa214d01a179539
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,29 @@
|
|
1
1
|
# Release History
|
2
2
|
|
3
|
+
### v0.15.0 / 2023-10-12
|
4
|
+
|
5
|
+
Toys 0.15.0 is a major release that adds arbitrary signal handling, cleans up some warts around entrypoint and method definition, and fixes a few long-standing issues.
|
6
|
+
|
7
|
+
Breaking changes:
|
8
|
+
|
9
|
+
* If a missing delegate or a delegation loop is detected, ToolDefinitionError is raised instead of RuntimeError.
|
10
|
+
* Passing a block to the to_run directive no longer defines the "run" method, but simply uses the block as the run entrypoint.
|
11
|
+
* The default algorithm for determining whether flags and arguments add methods now allows overriding of methods of Toys::Context and any other included modules, but prevents collisions with private methods defined in the tool. (It continues to prevent overriding of public methods of Object and BasicObject.)
|
12
|
+
|
13
|
+
New functionality:
|
14
|
+
|
15
|
+
* New DSL directive on_signal lets tools provide signal handlers.
|
16
|
+
* You can pass a symbol to the to_run directive to set the entrypoint to a method other than "run".
|
17
|
+
* Flags and arguments can be configured explicitly to add methods or not add methods, overriding the default behavior.
|
18
|
+
* The minitest template has a configuration argument that defines MT_COMPAT.
|
19
|
+
|
20
|
+
Fixes and documentation:
|
21
|
+
|
22
|
+
* The Bundler integration prevents Bundler from attempting to self-update to the version specified in a lockfile (which would often cause problems when Bundler is called from Toys).
|
23
|
+
* Tools generated by the minitest and rspec standard templates can now interact properly with stdin (e.g. so you can invoke pry temporarily from a test.)
|
24
|
+
* Some cleanup of varioius mixins to prevent issues if their methods ever get overridden.
|
25
|
+
* Various improvements and clarifications in the reference documentation and user guide.
|
26
|
+
|
3
27
|
### v0.14.7 / 2023-07-19
|
4
28
|
|
5
29
|
* FIXED: Fixed an exception when passing a non-string to puts in the terminal mixin
|
data/LICENSE.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# License
|
2
2
|
|
3
|
-
Copyright 2019-
|
3
|
+
Copyright 2019-2023 Daniel Azuma and the Toys contributors
|
4
4
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
data/README.md
CHANGED
@@ -249,7 +249,7 @@ you can often rewrite an entire Rakefile as a Toys file and get quite a bit of
|
|
249
249
|
benefit in readability and maintainability. For an example, see the
|
250
250
|
[Toys file for the Toys gem itself](https://github.com/dazuma/toys/blob/main/toys/.toys/.toys.rb).
|
251
251
|
It contains Toys scripts that I use to develop, test, and release Toys itself.
|
252
|
-
Yes, Toys is self-hosted. You'll notice
|
252
|
+
Yes, Toys is self-hosted. You'll notice much of this Toys file consists of
|
253
253
|
template expansions. Toys provides templates for a lot of common build, test,
|
254
254
|
and release tasks for Ruby projects.
|
255
255
|
|
@@ -276,6 +276,9 @@ separate files. Such directories are versatile, letting you organize your tool
|
|
276
276
|
definitions, along with shared code, normal Ruby classes, tests, and even data
|
277
277
|
files for use by tools.
|
278
278
|
|
279
|
+
You can find detailed usage information, including the entire DSL, in the
|
280
|
+
[class reference documentation](https://dazuma.github.io/toys/gems/toys/latest/Toys.html)
|
281
|
+
|
279
282
|
Unlike most command line frameworks, Toys is *not primarily* designed to help
|
280
283
|
you build and ship a custom command line executable written in Ruby. However,
|
281
284
|
you *can* use it in that way with the "toys-core" API, available as a separate
|
@@ -323,7 +326,7 @@ because it has a few known bugs that affect Toys.
|
|
323
326
|
|
324
327
|
## License
|
325
328
|
|
326
|
-
Copyright 2019-
|
329
|
+
Copyright 2019-2023 Daniel Azuma and the Toys contributors
|
327
330
|
|
328
331
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
329
332
|
of this software and associated documentation files (the "Software"), to deal
|
data/builtins/system/test.rb
CHANGED
@@ -23,36 +23,18 @@ flag :minitest_focus, "--minitest-focus[=VERSION]",
|
|
23
23
|
desc: "Make minitest-focus available during the run"
|
24
24
|
flag :minitest_rg, "--minitest-rg[=VERSION]",
|
25
25
|
desc: "Make minitest-rg available during the run"
|
26
|
+
flag :minitest_compat, "--[no-]minitest-compat",
|
27
|
+
desc: "Set MT_COMPAT to retain compatibility with certain old plugins"
|
26
28
|
|
27
29
|
include :exec
|
28
30
|
include :gems
|
29
31
|
include :terminal
|
30
32
|
|
31
33
|
def run
|
34
|
+
env = ruby_env
|
35
|
+
ENV["MT_COMPAT"] = env["MT_COMPAT"] if env.key?("MT_COMPAT")
|
32
36
|
load_minitest_gems
|
33
|
-
|
34
|
-
result = exec_ruby(ruby_args, in: :controller, log_cmd: "Starting minitest...") do |controller|
|
35
|
-
controller.in.puts("gem 'minitest', '= #{::Minitest::VERSION}'")
|
36
|
-
controller.in.puts("require 'minitest/autorun'")
|
37
|
-
if minitest_focus
|
38
|
-
controller.in.puts("gem 'minitest-focus', '= #{::Minitest::Test::Focus::VERSION}'")
|
39
|
-
controller.in.puts("require 'minitest/focus'")
|
40
|
-
end
|
41
|
-
if minitest_rg
|
42
|
-
controller.in.puts("gem 'minitest-rg', '= #{::MiniTest::RG::VERSION}'")
|
43
|
-
controller.in.puts("require 'minitest/rg'")
|
44
|
-
end
|
45
|
-
controller.in.puts("require 'toys'")
|
46
|
-
controller.in.puts("require 'toys/testing'")
|
47
|
-
if directory
|
48
|
-
dir_str = ::File.absolute_path(directory).inspect
|
49
|
-
controller.in.puts("Toys::Testing.toys_custom_paths(#{dir_str})")
|
50
|
-
controller.in.puts("Toys::Testing.toys_include_builtins(false)")
|
51
|
-
end
|
52
|
-
test_files.each do |file|
|
53
|
-
controller.in.puts("load '#{file}'")
|
54
|
-
end
|
55
|
-
end
|
37
|
+
result = exec_ruby(ruby_args, log_cmd: "Starting minitest...", env: env)
|
56
38
|
if result.error?
|
57
39
|
logger.error("Minitest failed!")
|
58
40
|
exit(result.exit_code)
|
@@ -74,6 +56,54 @@ def load_minitest_gems
|
|
74
56
|
end
|
75
57
|
end
|
76
58
|
|
59
|
+
def ruby_env
|
60
|
+
case minitest_compat
|
61
|
+
when true
|
62
|
+
{ "MT_COMPAT" => "true" }
|
63
|
+
when false
|
64
|
+
{ "MT_COMPAT" => nil }
|
65
|
+
else
|
66
|
+
{}
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def ruby_args
|
71
|
+
args = []
|
72
|
+
args << "-w" if warnings
|
73
|
+
args << "-I#{::Toys::CORE_LIB_PATH}#{::File::PATH_SEPARATOR}#{::Toys::LIB_PATH}"
|
74
|
+
args << "-e" << ruby_code.join("\n")
|
75
|
+
args << "--"
|
76
|
+
args << "--seed" << seed if seed
|
77
|
+
args << "--verbose" if verbosity.positive?
|
78
|
+
args << "--name" << name if name
|
79
|
+
args << "--exclude" << exclude if exclude
|
80
|
+
args
|
81
|
+
end
|
82
|
+
|
83
|
+
def ruby_code
|
84
|
+
code = []
|
85
|
+
code << "gem 'minitest', '= #{::Minitest::VERSION}'"
|
86
|
+
code << "require 'minitest/autorun'"
|
87
|
+
if minitest_focus
|
88
|
+
code << "gem 'minitest-focus', '= #{::Minitest::Test::Focus::VERSION}'"
|
89
|
+
code << "require 'minitest/focus'"
|
90
|
+
end
|
91
|
+
if minitest_rg
|
92
|
+
code << "gem 'minitest-rg', '= #{::MiniTest::RG::VERSION}'"
|
93
|
+
code << "require 'minitest/rg'"
|
94
|
+
end
|
95
|
+
code << "require 'toys'"
|
96
|
+
code << "require 'toys/testing'"
|
97
|
+
if directory
|
98
|
+
code << "Toys::Testing.toys_custom_paths(#{::File.absolute_path(directory).inspect})"
|
99
|
+
code << "Toys::Testing.toys_include_builtins(false)"
|
100
|
+
end
|
101
|
+
find_test_files.each do |file|
|
102
|
+
code << "load '#{file}'"
|
103
|
+
end
|
104
|
+
code
|
105
|
+
end
|
106
|
+
|
77
107
|
def find_test_files
|
78
108
|
glob = ".test/**/test_*.rb"
|
79
109
|
glob = "**/#{glob}" if recursive
|
@@ -116,15 +146,3 @@ def base_dir
|
|
116
146
|
dir = parent
|
117
147
|
end
|
118
148
|
end
|
119
|
-
|
120
|
-
def ruby_args
|
121
|
-
args = []
|
122
|
-
args << "-w" if warnings
|
123
|
-
args << "-I#{::Toys::CORE_LIB_PATH}#{::File::PATH_SEPARATOR}#{::Toys::LIB_PATH}"
|
124
|
-
args << "-"
|
125
|
-
args << "--seed" << seed if seed
|
126
|
-
args << "--verbose" if verbosity.positive?
|
127
|
-
args << "--name" << name if name
|
128
|
-
args << "--exclude" << exclude if exclude
|
129
|
-
args
|
130
|
-
end
|
data/core-docs/toys/cli.rb
CHANGED
@@ -68,7 +68,7 @@ module Toys
|
|
68
68
|
# * `preload_dir_name`: Name of preload directories in tool directories
|
69
69
|
# * `data_dir_name`: Name of data directories in tool directories
|
70
70
|
#
|
71
|
-
# @param logger [Logger] A global logger to use for all tools. This
|
71
|
+
# @param logger [Logger] A global logger to use for all tools. This can be
|
72
72
|
# set if the CLI will call at most one tool at a time. However, it will
|
73
73
|
# behave incorrectly if CLI might run multiple tools at the same time
|
74
74
|
# with different verbosity settings (since the logger cannot have
|
@@ -76,19 +76,21 @@ module Toys
|
|
76
76
|
# global logger, but use the `logger_factory` parameter instead.
|
77
77
|
# @param logger_factory [Proc] A proc that takes a {Toys::ToolDefinition}
|
78
78
|
# as an argument, and returns a `Logger` to use when running that tool.
|
79
|
-
# Optional. If not provided (and no global logger is set),
|
80
|
-
#
|
81
|
-
# output to `STDERR`, as defined by {Toys::CLI.default_logger_factory}.
|
79
|
+
# Optional. If not provided (and no global logger is set),
|
80
|
+
# {Toys::CLI.default_logger_factory} is called to get a basic default.
|
82
81
|
# @param base_level [Integer] The logger level that should correspond
|
83
82
|
# to zero verbosity.
|
84
83
|
# Optional. If not provided, defaults to the current level of the
|
85
84
|
# logger (which is often `Logger::WARN`).
|
86
|
-
# @param error_handler [Proc,nil] A proc that is called when an
|
87
|
-
#
|
88
|
-
#
|
89
|
-
#
|
90
|
-
# {Toys::
|
91
|
-
#
|
85
|
+
# @param error_handler [Proc,nil] A proc that is called when an unhandled
|
86
|
+
# exception (a normal exception subclassing `StandardError`, an error
|
87
|
+
# loading a toys config file subclassing `SyntaxError`, or an unhandled
|
88
|
+
# signal subclassing `SignalException`) is detected. The proc should
|
89
|
+
# take a {Toys::ContextualError}, whose cause is the unhandled
|
90
|
+
# exception, as the sole argument, and report the error. It should
|
91
|
+
# return an exit code (normally nonzero) appropriate to the error.
|
92
|
+
# Optional. If not provided, {Toys::CLI.default_error_handler} is
|
93
|
+
# called to get a basic default handler.
|
92
94
|
# @param executable_name [String] The executable name displayed in help
|
93
95
|
# text. Optional. Defaults to the ruby program name.
|
94
96
|
#
|
@@ -97,9 +99,8 @@ module Toys
|
|
97
99
|
# characters are period, colon, and slash.
|
98
100
|
# @param completion [Toys::Completion::Base] A specifier for shell tab
|
99
101
|
# completion for the CLI as a whole.
|
100
|
-
# Optional. If not provided,
|
101
|
-
#
|
102
|
-
# relevant tool.
|
102
|
+
# Optional. If not provided, {Toys::CLI.default_completion} is called
|
103
|
+
# to get a default completion that delegates to the tool.
|
103
104
|
#
|
104
105
|
# @param middleware_stack [Array<Toys::Middleware::Spec>] An array of
|
105
106
|
# middleware that will be used by default for all tools.
|
@@ -382,53 +383,6 @@ module Toys
|
|
382
383
|
# Source available in the toys-core gem
|
383
384
|
end
|
384
385
|
|
385
|
-
##
|
386
|
-
# **_Defined in the toys-core gem_**
|
387
|
-
#
|
388
|
-
# A basic error handler that prints out captured errors to a stream or
|
389
|
-
# a logger.
|
390
|
-
#
|
391
|
-
class DefaultErrorHandler
|
392
|
-
##
|
393
|
-
# Create an error handler.
|
394
|
-
#
|
395
|
-
# @param output [IO,nil] Where to write errors. Default is `$stderr`.
|
396
|
-
#
|
397
|
-
def initialize(output: $stderr)
|
398
|
-
# Source available in the toys-core gem
|
399
|
-
end
|
400
|
-
|
401
|
-
##
|
402
|
-
# The error handler routine. Prints out the error message and backtrace,
|
403
|
-
# and returns the correct result code.
|
404
|
-
#
|
405
|
-
# @param error [Exception] The error that occurred.
|
406
|
-
# @return [Integer] The result code for the execution.
|
407
|
-
#
|
408
|
-
def call(error)
|
409
|
-
# Source available in the toys-core gem
|
410
|
-
end
|
411
|
-
end
|
412
|
-
|
413
|
-
##
|
414
|
-
# **_Defined in the toys-core gem_**
|
415
|
-
#
|
416
|
-
# A Completion that implements the default algorithm for a CLI. This
|
417
|
-
# algorithm simply determines the tool and uses its completion.
|
418
|
-
#
|
419
|
-
class DefaultCompletion < Completion::Base
|
420
|
-
##
|
421
|
-
# Returns candidates for the current completion.
|
422
|
-
#
|
423
|
-
# @param context [Toys::Completion::Context] the current completion
|
424
|
-
# context including the string fragment.
|
425
|
-
# @return [Array<Toys::Completion::Candidate>] an array of candidates
|
426
|
-
#
|
427
|
-
def call(context)
|
428
|
-
# Source available in the toys-core gem
|
429
|
-
end
|
430
|
-
end
|
431
|
-
|
432
386
|
class << self
|
433
387
|
##
|
434
388
|
# Returns a default set of middleware that may be used as a starting
|
@@ -478,16 +432,35 @@ module Toys
|
|
478
432
|
end
|
479
433
|
|
480
434
|
##
|
481
|
-
# Returns a
|
482
|
-
#
|
483
|
-
#
|
484
|
-
#
|
435
|
+
# Returns a bare-bones error handler that takes simply reraises the
|
436
|
+
# error. If the original error (the cause of the {Toys::ContextualError})
|
437
|
+
# was a `SignalException` (or a subclass such as `Interrupted`), that
|
438
|
+
# `SignalException` itself is reraised so that the Ruby VM has a chance
|
439
|
+
# to handle it. Otherwise, for any other error, the
|
440
|
+
# {Toys::ContextualError} is reraised.
|
441
|
+
#
|
442
|
+
# @return [Proc]
|
443
|
+
#
|
444
|
+
def default_error_handler
|
445
|
+
# Source available in the toys-core gem
|
446
|
+
end
|
447
|
+
|
448
|
+
##
|
449
|
+
# Returns a default logger factory that generates simple loggers that
|
450
|
+
# write to STDERR.
|
485
451
|
#
|
486
452
|
# @return [Proc]
|
487
453
|
#
|
488
454
|
def default_logger_factory
|
489
455
|
# Source available in the toys-core gem
|
490
456
|
end
|
457
|
+
|
458
|
+
##
|
459
|
+
# Returns a default Completion that simply uses the tool's completion.
|
460
|
+
#
|
461
|
+
def default_completion
|
462
|
+
# Source available in the toys-core gem
|
463
|
+
end
|
491
464
|
end
|
492
465
|
end
|
493
466
|
end
|
data/core-docs/toys/context.rb
CHANGED
@@ -141,22 +141,30 @@ module Toys
|
|
141
141
|
#
|
142
142
|
# This is a convenience getter for {Toys::Context::Key::ARGS}.
|
143
143
|
#
|
144
|
+
# If the `args` method is overridden by the tool, you can still access it
|
145
|
+
# using the name `__args`.
|
146
|
+
#
|
144
147
|
# @return [Array<String>]
|
145
148
|
#
|
146
149
|
def args
|
147
150
|
# Source available in the toys-core gem
|
148
151
|
end
|
152
|
+
alias __args args
|
149
153
|
|
150
154
|
##
|
151
155
|
# The currently running CLI.
|
152
156
|
#
|
153
157
|
# This is a convenience getter for {Toys::Context::Key::CLI}.
|
154
158
|
#
|
159
|
+
# If the `cli` method is overridden by the tool, you can still access it
|
160
|
+
# using the name `__cli`.
|
161
|
+
#
|
155
162
|
# @return [Toys::CLI]
|
156
163
|
#
|
157
164
|
def cli
|
158
165
|
# Source available in the toys-core gem
|
159
166
|
end
|
167
|
+
alias __cli cli
|
160
168
|
|
161
169
|
##
|
162
170
|
# Return the context directory for this tool. Generally, this defaults
|
@@ -166,71 +174,98 @@ module Toys
|
|
166
174
|
#
|
167
175
|
# This is a convenience getter for {Toys::Context::Key::CONTEXT_DIRECTORY}.
|
168
176
|
#
|
177
|
+
# If the `context_directory` method is overridden by the tool, you can
|
178
|
+
# still access it using the name `__context_directory`.
|
179
|
+
#
|
169
180
|
# @return [String] Context directory path
|
170
181
|
# @return [nil] if there is no context.
|
171
182
|
#
|
172
183
|
def context_directory
|
173
184
|
# Source available in the toys-core gem
|
174
185
|
end
|
186
|
+
alias __context_directory context_directory
|
175
187
|
|
176
188
|
##
|
177
189
|
# The logger for this execution.
|
178
190
|
#
|
179
191
|
# This is a convenience getter for {Toys::Context::Key::LOGGER}.
|
180
192
|
#
|
193
|
+
# If the `logger` method is overridden by the tool, you can still access it
|
194
|
+
# using the name `__logger`.
|
195
|
+
#
|
181
196
|
# @return [Logger]
|
182
197
|
#
|
183
198
|
def logger
|
184
199
|
# Source available in the toys-core gem
|
185
200
|
end
|
201
|
+
alias __logger logger
|
186
202
|
|
187
203
|
##
|
188
204
|
# The full name of the tool being executed, as an array of strings.
|
189
205
|
#
|
190
206
|
# This is a convenience getter for {Toys::Context::Key::TOOL_NAME}.
|
191
207
|
#
|
208
|
+
# If the `tool_name` method is overridden by the tool, you can still access
|
209
|
+
# it using the name `__tool_name`.
|
210
|
+
#
|
192
211
|
# @return [Array<String>]
|
193
212
|
#
|
194
213
|
def tool_name
|
195
214
|
# Source available in the toys-core gem
|
196
215
|
end
|
216
|
+
alias __tool_name tool_name
|
197
217
|
|
198
218
|
##
|
199
219
|
# The source of the tool being executed.
|
200
220
|
#
|
201
221
|
# This is a convenience getter for {Toys::Context::Key::TOOL_SOURCE}.
|
202
222
|
#
|
223
|
+
# If the `tool_source` method is overridden by the tool, you can still
|
224
|
+
# access it using the name `__tool_source`.
|
225
|
+
#
|
203
226
|
# @return [Toys::SourceInfo]
|
204
227
|
#
|
205
228
|
def tool_source
|
206
229
|
# Source available in the toys-core gem
|
207
230
|
end
|
231
|
+
alias __tool_source tool_source
|
208
232
|
|
209
233
|
##
|
210
234
|
# The (possibly empty) array of errors detected during argument parsing.
|
211
235
|
#
|
212
236
|
# This is a convenience getter for {Toys::Context::Key::USAGE_ERRORS}.
|
213
237
|
#
|
238
|
+
# If the `usage_errors` method is overridden by the tool, you can still
|
239
|
+
# access it using the name `__usage_errors`.
|
240
|
+
#
|
214
241
|
# @return [Array<Toys::ArgParser::UsageError>]
|
215
242
|
#
|
216
243
|
def usage_errors
|
217
244
|
# Source available in the toys-core gem
|
218
245
|
end
|
246
|
+
alias __usage_errors usage_errors
|
219
247
|
|
220
248
|
##
|
221
249
|
# The current verbosity setting as an integer.
|
222
250
|
#
|
223
251
|
# This is a convenience getter for {Toys::Context::Key::VERBOSITY}.
|
224
252
|
#
|
253
|
+
# If the `verbosity` method is overridden by the tool, you can still access
|
254
|
+
# it using the name `__verbosity`.
|
255
|
+
#
|
225
256
|
# @return [Integer]
|
226
257
|
#
|
227
258
|
def verbosity
|
228
259
|
# Source available in the toys-core gem
|
229
260
|
end
|
261
|
+
alias __verbosity verbosity
|
230
262
|
|
231
263
|
##
|
232
264
|
# Fetch an option or other piece of data by key.
|
233
265
|
#
|
266
|
+
# If the `get` method is overridden by the tool, you can still access it
|
267
|
+
# using the name `__get` or the `[]` operator.
|
268
|
+
#
|
234
269
|
# @param key [Symbol]
|
235
270
|
# @return [Object]
|
236
271
|
#
|
@@ -253,6 +288,9 @@ module Toys
|
|
253
288
|
##
|
254
289
|
# Set one or more options or other context data by key.
|
255
290
|
#
|
291
|
+
# If the `set` method is overridden by the tool, you can still access it
|
292
|
+
# using the name `__set`.
|
293
|
+
#
|
256
294
|
# @return [self]
|
257
295
|
#
|
258
296
|
# @overload set(key, value)
|
@@ -269,6 +307,7 @@ module Toys
|
|
269
307
|
def set(key, value = nil)
|
270
308
|
# Source available in the toys-core gem
|
271
309
|
end
|
310
|
+
alias __set set
|
272
311
|
|
273
312
|
##
|
274
313
|
# The subset of the context that uses string or symbol keys. By convention,
|
@@ -276,15 +315,22 @@ module Toys
|
|
276
315
|
# include well-known context values such as verbosity or private context
|
277
316
|
# values used by middleware or mixins.
|
278
317
|
#
|
318
|
+
# If the `options` method is overridden by the tool, you can still access
|
319
|
+
# it using the name `__options`.
|
320
|
+
#
|
279
321
|
# @return [Hash]
|
280
322
|
#
|
281
323
|
def options
|
282
324
|
# Source available in the toys-core gem
|
283
325
|
end
|
326
|
+
alias __options options
|
284
327
|
|
285
328
|
##
|
286
329
|
# Find the given data file or directory in this tool's search path.
|
287
330
|
#
|
331
|
+
# If the `find_data` method is overridden by the tool, you can still access
|
332
|
+
# it using the name `__find_data`.
|
333
|
+
#
|
288
334
|
# @param path [String] The path to find
|
289
335
|
# @param type [nil,:file,:directory] Type of file system object to find,
|
290
336
|
# or nil to return any type.
|
@@ -295,10 +341,14 @@ module Toys
|
|
295
341
|
def find_data(path, type: nil)
|
296
342
|
# Source available in the toys-core gem
|
297
343
|
end
|
344
|
+
alias __find_data find_data
|
298
345
|
|
299
346
|
##
|
300
347
|
# Exit immediately with the given status code.
|
301
348
|
#
|
349
|
+
# If the `exit` method is overridden by the tool, you can still access it
|
350
|
+
# using the name `__exit` or by calling {Context.exit}.
|
351
|
+
#
|
302
352
|
# @param code [Integer] The status code, which should be 0 for no error,
|
303
353
|
# or nonzero for an error condition. Default is 0.
|
304
354
|
# @return [void]
|
@@ -306,6 +356,7 @@ module Toys
|
|
306
356
|
def exit(code = 0)
|
307
357
|
# Source available in the toys-core gem
|
308
358
|
end
|
359
|
+
alias __exit exit
|
309
360
|
|
310
361
|
##
|
311
362
|
# Exit immediately with the given status code. This class method can be
|
data/core-docs/toys/core.rb
CHANGED
data/core-docs/toys/dsl/flag.rb
CHANGED
@@ -117,7 +117,14 @@ module Toys
|
|
117
117
|
# should be set. You may pass the handler as a Proc (or an object
|
118
118
|
# responding to the `call` method) or you may pass a block.
|
119
119
|
#
|
120
|
-
#
|
120
|
+
# You can also pass one of the special values `:set` or `:push` as the
|
121
|
+
# handler. The `:set` handler replaces the previous value (equivalent to
|
122
|
+
# `-> (val, _prev) { val }`.) The `:push` handler expects the previous
|
123
|
+
# value to be an array and pushes the given value onto it; it should be
|
124
|
+
# combined with setting the default value to `[]` and is intended for
|
125
|
+
# "multi-valued" flags.
|
126
|
+
#
|
127
|
+
# @param handler [Proc,:set,:push]
|
121
128
|
# @param block [Proc]
|
122
129
|
# @return [self]
|
123
130
|
#
|
@@ -256,6 +263,22 @@ module Toys
|
|
256
263
|
def display_name(display_name)
|
257
264
|
# Source available in the toys-core gem
|
258
265
|
end
|
266
|
+
|
267
|
+
##
|
268
|
+
# Specify whether to add a method for this flag.
|
269
|
+
#
|
270
|
+
# Recognized values are true to force creation of a method, false to
|
271
|
+
# disable method creation, and nil for the default behavior. The default
|
272
|
+
# checks the name and adds a method if the name is a symbol representing
|
273
|
+
# a legal method name that starts with a letter and does not override any
|
274
|
+
# public method in the Ruby Object class or collide with any method
|
275
|
+
# directly defined in the tool class.
|
276
|
+
#
|
277
|
+
# @param value [true,false,nil]
|
278
|
+
#
|
279
|
+
def add_method(value)
|
280
|
+
# Source available in the toys-core gem
|
281
|
+
end
|
259
282
|
end
|
260
283
|
end
|
261
284
|
end
|
@@ -181,13 +181,21 @@ module Toys
|
|
181
181
|
# arguments.) Defaults to the empty array.
|
182
182
|
# @param display_name [String] A display name for this flag, used in help
|
183
183
|
# text and error messages.
|
184
|
+
# @param add_method [true,false,nil] Whether to add a method for this
|
185
|
+
# flag. If omitted or set to nil, uses the default behavior, which
|
186
|
+
# adds the method if the key is a symbol representing a legal method
|
187
|
+
# name that starts with a letter and does not override any public
|
188
|
+
# method in the Ruby Object class or collide with any method directly
|
189
|
+
# defined in the tool class.
|
184
190
|
# @param block [Proc] Configures the flag. See {Toys::DSL::Flag} for the
|
185
191
|
# directives that can be called in this block.
|
186
192
|
# @return [self]
|
187
193
|
#
|
188
194
|
def flag(key, *flags,
|
189
|
-
accept: nil, default: nil, handler: nil,
|
190
|
-
|
195
|
+
accept: nil, default: nil, handler: nil,
|
196
|
+
complete_flags: nil, complete_values: nil,
|
197
|
+
report_collisions: true, desc: nil, long_desc: nil,
|
198
|
+
display_name: nil, add_method: nil,
|
191
199
|
&block)
|
192
200
|
# Source available in the toys-core gem
|
193
201
|
end
|
@@ -134,6 +134,22 @@ module Toys
|
|
134
134
|
def long_desc(*long_desc)
|
135
135
|
# Source available in the toys-core gem
|
136
136
|
end
|
137
|
+
|
138
|
+
##
|
139
|
+
# Specify whether to add a method for this argument.
|
140
|
+
#
|
141
|
+
# Recognized values are true to force creation of a method, false to
|
142
|
+
# disable method creation, and nil for the default behavior. The default
|
143
|
+
# checks the name and adds a method if the name is a symbol representing
|
144
|
+
# a legal method name that starts with a letter and does not override any
|
145
|
+
# public method in the Ruby Object class or collide with any method
|
146
|
+
# directly defined in the tool class.
|
147
|
+
#
|
148
|
+
# @param value [true,false,nil]
|
149
|
+
#
|
150
|
+
def add_method(value)
|
151
|
+
# Source available in the toys-core gem
|
152
|
+
end
|
137
153
|
end
|
138
154
|
end
|
139
155
|
end
|