toys 0.21.0 → 0.22.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 +56 -0
- data/LICENSE.md +1 -1
- data/README.md +101 -67
- data/builtins/system/zsh-completion.rb +22 -22
- data/core-docs/toys/acceptor.rb +7 -16
- data/core-docs/toys/arg_parser.rb +31 -19
- data/core-docs/toys/cli.rb +13 -10
- data/core-docs/toys/completion.rb +21 -21
- data/core-docs/toys/context.rb +4 -0
- data/core-docs/toys/core.rb +1 -1
- data/core-docs/toys/dsl/flag.rb +2 -1
- data/core-docs/toys/dsl/flag_group.rb +1 -1
- data/core-docs/toys/dsl/tool.rb +99 -56
- data/core-docs/toys/errors.rb +2 -43
- data/core-docs/toys/flag.rb +16 -16
- data/core-docs/toys/flag_group.rb +1 -5
- data/core-docs/toys/input_file.rb +10 -1
- data/core-docs/toys/loader.rb +30 -15
- data/core-docs/toys/middleware.rb +4 -4
- data/core-docs/toys/mixin.rb +14 -3
- data/core-docs/toys/module_lookup.rb +1 -1
- data/core-docs/toys/positional_arg.rb +11 -8
- data/core-docs/toys/source_info.rb +6 -3
- data/core-docs/toys/standard_middleware/add_verbosity_flags.rb +2 -2
- data/core-docs/toys/standard_middleware/handle_usage_errors.rb +1 -1
- data/core-docs/toys/standard_middleware/show_help.rb +46 -46
- data/core-docs/toys/standard_mixins/bundler.rb +1 -1
- data/core-docs/toys/standard_mixins/exec.rb +8 -8
- data/core-docs/toys/standard_mixins/gems.rb +53 -2
- data/core-docs/toys/standard_mixins/terminal.rb +2 -2
- data/core-docs/toys/template.rb +17 -2
- data/core-docs/toys/tool_definition.rb +30 -24
- data/core-docs/toys/utils/exec.rb +24 -6
- data/core-docs/toys/utils/gems.rb +21 -9
- data/core-docs/toys/utils/git_cache.rb +152 -152
- data/core-docs/toys/utils/help_text.rb +21 -12
- data/core-docs/toys/utils/standard_ui.rb +23 -23
- data/core-docs/toys/utils/terminal.rb +4 -4
- data/core-docs/toys/utils/xdg.rb +21 -12
- data/core-docs/toys/wrappable_string.rb +2 -2
- data/core-docs/toys-core.rb +0 -1
- data/docs/guide.md +1775 -1329
- data/lib/toys/standard_cli.rb +1 -1
- data/lib/toys/templates/gem_build.rb +45 -30
- data/lib/toys/templates/minitest.rb +9 -9
- data/lib/toys/templates/rake.rb +9 -9
- data/lib/toys/templates/rdoc.rb +3 -3
- data/lib/toys/templates/rspec.rb +9 -9
- data/lib/toys/templates/rubocop.rb +7 -7
- data/lib/toys/templates/yardoc.rb +27 -27
- data/lib/toys/version.rb +1 -1
- metadata +6 -7
- data/core-docs/toys/settings.rb +0 -543
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7c91d8f8914503e8d8baf7eae17725fa3eee2470273311917561c0c1dfa9b341
|
|
4
|
+
data.tar.gz: 01a7b93c64123371a1f82afbb708c15377efc9b63b0bd2c52fd5dd0e9acee8c7
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f888f8e2b005d13c943a7856add1ae37d56739dc0553612fa09b13472a4b43b002a594b11b8d77723f4ddafdf05170a99c2ade023ed247136cd946d7345784fa
|
|
7
|
+
data.tar.gz: a8e90f01ab91878bf4175bde290c39d1d126985a77d23779134aa008ba217801f1f2b2e876733b4bf1ef61336506758b7fb4f9dab0bd3a5da7c03ae9aba9d141
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,61 @@
|
|
|
1
1
|
# Release History
|
|
2
2
|
|
|
3
|
+
### v0.22.0 / 2026-05-05
|
|
4
|
+
|
|
5
|
+
Toys 0.22 is a major release focused on polish and cleanup in preparation for version 1.0. It includes a number of small breaking changes where needed to clean up the interfaces. (Note that many of the changes listed below are actually in the `toys-core` gem.)
|
|
6
|
+
|
|
7
|
+
Breaking interface changes:
|
|
8
|
+
|
|
9
|
+
* The `static` directive no longer "forces" creating of helper methods, instead using the same logic as the flag and argument directives. In particular, by default it will not create a method starting with underscore.
|
|
10
|
+
* Removed `Toys::Settings` and moved inheritable_helper_methods to a dedicated tool attribute. Use the `basic_settings` gem if you need the old settings class.
|
|
11
|
+
* `Toys::Acceptor#create` no longer takes a hash as the spec. (This was undocumented but worked previously.) To construct an object, pass the class as the main spec object, and the keyword arguments in the options.
|
|
12
|
+
* `Toys::Acceptor::Enum#values` now returns the values themselves instead of a zipped array that includes strings.
|
|
13
|
+
* `Toys::FlagGroup::Base` is no longer instantiable; use `Toys::FlagGroup::Optional` instead.
|
|
14
|
+
* The `acceptor` and `display_name` attributes of `Toys::PositionalArg` are no longer writable and must be set in the constructor.
|
|
15
|
+
* `Toys::Completion#create` no longer takes a hash as the spec. (This was undocumented but worked previously.) To construct an object, pass the class as the main spec object, and the keyword arguments in the options.
|
|
16
|
+
* The `delegation_target` attribute of `Toys::ToolDefinition::DefaultCompletion` is no longer writable and must be set in the constructor.
|
|
17
|
+
* You can no longer override a completion class using the `:""` key. (This was undocumented but worked previously.) Just pass a fully constructed completion object if you need a custom object.
|
|
18
|
+
* The original `Module#include` method is now available in the DSL as `include_module` instead of `super_include`.
|
|
19
|
+
* Template classes no longer automatically include `Toys::Context::Key`. This behavior was undocumented and inconsistent between different ways of defining templates.
|
|
20
|
+
* Made `Toys::CLI#load_tool` return the block value rather than the exit_code.
|
|
21
|
+
* Made `Toys::Testing#toys_load_tool` return the block value rather than the exit_code
|
|
22
|
+
* Dropped undocumented `Loader#add_path_set` option to include individual source names in the relative_paths argument.
|
|
23
|
+
* Renamed `use_less` in the `Toys::StandardMiddleware::ShowHelp` constructor to `use_pager`, and added support for custom pagers.
|
|
24
|
+
* Renamed many of the methods in `StandardUI` to reduce confusion.
|
|
25
|
+
* Removed `LoaderError` and used `ToolDefinitionError` for those cases, as it was decided that the distinction was ambiguous and dependent on internal details.
|
|
26
|
+
* Removed `ContextualError#underlying_error` as it was synonymous with `cause`.
|
|
27
|
+
* Consolidated `ContextualError` public interface into a single `capture` method.
|
|
28
|
+
* `ArgParser::ExtraArgumentsError` now takes `:arguments` instead of `:values`, and provides an accessor for the same.
|
|
29
|
+
* `ArgParser::ToolUnrecognizedError` now takes `:full_name` instead of `:values`, and provides an accessor for the same.
|
|
30
|
+
* Renamed `ArgParser::UsageError#full_message` to `message_with_suggestions` to avoid overriding `Exception#full_message`.
|
|
31
|
+
|
|
32
|
+
New features:
|
|
33
|
+
|
|
34
|
+
* The range acceptor supports beginless and endless ranges.
|
|
35
|
+
* A custom source_name can be provided to `Loader#add_path_set`, `Loader#add_git`, and `Loader#add_gem`.
|
|
36
|
+
* The `:gems` mixin provides a context key for retrieving the underlying `Toys::Utils::Gems` service object.
|
|
37
|
+
* The `:gems` mixin provides an explicit `Toys::Utils::Gems::ClassMethods` module defining the directives added to the tool class.
|
|
38
|
+
* The `activate` and `bundle` methods in the Gems utility now return useful results.
|
|
39
|
+
|
|
40
|
+
Other fixes:
|
|
41
|
+
|
|
42
|
+
* The `:update` argument to the `load_git` directive had no effect if the `:as` argument was provided.
|
|
43
|
+
* `FlagValueUnacceptableError` and `ArgValueUnacceptableError` have their value set correctly.
|
|
44
|
+
* If a CLI has a static (shared) logger, creating a child with `logger: nil` actually clears it.
|
|
45
|
+
* Removed unused `Toys::StandardMiddleware::ShowHelp::TOOL_NAME_KEY`.
|
|
46
|
+
* ShowHelp middleware displays an error message instead of raising an exception when help cannot be generated due to a bad search regex.
|
|
47
|
+
* `ArgParser::UsageError` is now a proper exception.
|
|
48
|
+
* `ContextualError` does a better job of capturing relevant syntax errors.
|
|
49
|
+
* Various minor completion system fixes.
|
|
50
|
+
|
|
51
|
+
Several libraries under `toys/utils` were extracted into their own gems. The current code remains under `Toys::Utils` as a vendored copy of the external gem, so the extracted gems are not actually dependencies of Toys. The affected libraries are:
|
|
52
|
+
|
|
53
|
+
* `Toys::Utils::Exec` which was extracted to the gem `exec_service`.
|
|
54
|
+
* `Toys::Utils::XDG` which was extracted to the gem `simple_xdg`.
|
|
55
|
+
* `Toys::Utils::GitCache` which was extracted to the gem `git_cache`.
|
|
56
|
+
|
|
57
|
+
Finally, a variety of clarifications and fixes were made to the reference documentation, readme, and user's guide.
|
|
58
|
+
|
|
3
59
|
### v0.21.0 / 2026-03-23
|
|
4
60
|
|
|
5
61
|
This release includes a variety of small fixes and updates toward improving product polish in preparation for a 1.0 release. It focuses on the following areas:
|
data/LICENSE.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# License
|
|
2
2
|
|
|
3
|
-
Copyright 2019-
|
|
3
|
+
Copyright 2019-2026 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
|
@@ -23,12 +23,16 @@ Here's a tutorial to help you get a feel of what Toys can do.
|
|
|
23
23
|
|
|
24
24
|
Install the **toys** gem using:
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
```
|
|
27
|
+
$ gem install toys
|
|
28
|
+
```
|
|
27
29
|
|
|
28
30
|
This installs the `toys` executable, along with some built-in tools and
|
|
29
31
|
libraries. You can run the executable immediately:
|
|
30
32
|
|
|
31
|
-
|
|
33
|
+
```
|
|
34
|
+
$ toys
|
|
35
|
+
```
|
|
32
36
|
|
|
33
37
|
This displays overall help for Toys. If you have `less` installed, Toys will
|
|
34
38
|
use it to display the help screen. Press `q` to exit.
|
|
@@ -36,19 +40,25 @@ use it to display the help screen. Press `q` to exit.
|
|
|
36
40
|
You may notice that the help screen lists some tools that are pre-installed.
|
|
37
41
|
Let's run one of them:
|
|
38
42
|
|
|
39
|
-
|
|
43
|
+
```
|
|
44
|
+
$ toys system version
|
|
45
|
+
```
|
|
40
46
|
|
|
41
47
|
The `system version` tool displays the current version of the toys gem.
|
|
42
48
|
|
|
43
|
-
Toys also provides optional tab completion for bash. To install
|
|
44
|
-
following command in your shell, or add it to your bash
|
|
45
|
-
(e.g. `~/.bashrc`).
|
|
49
|
+
Toys also provides optional tab completion for bash and zsh. To install for
|
|
50
|
+
bash, execute the following command in your shell, or add it to your bash
|
|
51
|
+
configuration file (e.g. `~/.bashrc`).
|
|
46
52
|
|
|
47
|
-
|
|
53
|
+
```
|
|
54
|
+
$(toys system bash-completion install)
|
|
55
|
+
```
|
|
48
56
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
57
|
+
To install for zsh, execute this or add to your `~/.zshrc`.
|
|
58
|
+
|
|
59
|
+
```
|
|
60
|
+
$(toys system zsh-completion install)
|
|
61
|
+
```
|
|
52
62
|
|
|
53
63
|
### Write your first tool
|
|
54
64
|
|
|
@@ -56,32 +66,42 @@ You can define tools by creating a *Toys file*. Go into any directory, and,
|
|
|
56
66
|
using your favorite editor, create a new file called `.toys.rb` (note the
|
|
57
67
|
leading period). Copy the following text into the file, and save it:
|
|
58
68
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
69
|
+
```ruby
|
|
70
|
+
tool "greet" do
|
|
71
|
+
desc "My first tool!"
|
|
72
|
+
flag :whom, default: "world"
|
|
73
|
+
def run
|
|
74
|
+
puts "Hello, #{whom}!"
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
```
|
|
66
78
|
|
|
67
79
|
This defines a tool named "greet". Try running it:
|
|
68
80
|
|
|
69
|
-
|
|
81
|
+
```
|
|
82
|
+
$ toys greet
|
|
83
|
+
```
|
|
70
84
|
|
|
71
85
|
The tool also recognizes a flag on the command line. Try this:
|
|
72
86
|
|
|
73
|
-
|
|
87
|
+
```
|
|
88
|
+
$ toys greet --whom=ruby
|
|
89
|
+
```
|
|
74
90
|
|
|
75
91
|
Toys provides a rich set of features for defining command line arguments and
|
|
76
92
|
flags. It can also validate arguments. Try this:
|
|
77
93
|
|
|
78
|
-
|
|
94
|
+
```
|
|
95
|
+
$ toys greet --bye
|
|
96
|
+
```
|
|
79
97
|
|
|
80
98
|
Notice that Toys automatically generated a usage summary for your tool. It also
|
|
81
99
|
automatically generates a full help screen, which you can view using the
|
|
82
100
|
`--help` flag:
|
|
83
101
|
|
|
84
|
-
|
|
102
|
+
```
|
|
103
|
+
$ toys greet --help
|
|
104
|
+
```
|
|
85
105
|
|
|
86
106
|
Toys searches up the directory hierarchy for Toys files. So it will find this
|
|
87
107
|
`.toys.rb` if you are located in this directory or any subdirectory. It will
|
|
@@ -99,53 +119,59 @@ likely to see in real-world usage. Add the following to your `.toys.rb` file.
|
|
|
99
119
|
(You don't need to replace the greet tool you just wrote; just add this new
|
|
100
120
|
tool to the end of the file.)
|
|
101
121
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
puts "Created repo in #{name}", :green, :bold
|
|
126
|
-
end
|
|
127
|
-
|
|
128
|
-
def create_repo
|
|
129
|
-
exec "git init"
|
|
130
|
-
File.write ".gitignore", <<~CONTENT
|
|
131
|
-
tmp
|
|
132
|
-
.DS_Store
|
|
133
|
-
CONTENT
|
|
134
|
-
# You can add additional files here.
|
|
135
|
-
exec "git add ."
|
|
136
|
-
exec "git commit -m 'Initial commit'"
|
|
137
|
-
end
|
|
122
|
+
```ruby
|
|
123
|
+
tool "new-repo" do
|
|
124
|
+
desc "Create a new git repo"
|
|
125
|
+
|
|
126
|
+
optional_arg :name, desc: "Name of the directory to create"
|
|
127
|
+
|
|
128
|
+
include :exec, exit_on_nonzero_status: true
|
|
129
|
+
include :fileutils
|
|
130
|
+
include :terminal
|
|
131
|
+
|
|
132
|
+
def run
|
|
133
|
+
if name.nil?
|
|
134
|
+
response = ask "Please enter a directory name: "
|
|
135
|
+
set :name, response
|
|
136
|
+
end
|
|
137
|
+
if File.exist? name
|
|
138
|
+
puts "Aborting because #{name} already exists", :red, :bold
|
|
139
|
+
exit 1
|
|
140
|
+
end
|
|
141
|
+
logger.info "Creating new repo in directory #{name}..."
|
|
142
|
+
mkdir name
|
|
143
|
+
cd name do
|
|
144
|
+
create_repo
|
|
138
145
|
end
|
|
146
|
+
puts "Created repo in #{name}", :green, :bold
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
def create_repo
|
|
150
|
+
exec "git init"
|
|
151
|
+
File.write ".gitignore", <<~CONTENT
|
|
152
|
+
tmp
|
|
153
|
+
.DS_Store
|
|
154
|
+
CONTENT
|
|
155
|
+
# You can add additional files here.
|
|
156
|
+
exec "git add ."
|
|
157
|
+
exec "git commit -m 'Initial commit'"
|
|
158
|
+
end
|
|
159
|
+
end
|
|
160
|
+
```
|
|
139
161
|
|
|
140
162
|
Now you should have an additional tool called `new-repo` available. Type:
|
|
141
163
|
|
|
142
|
-
|
|
164
|
+
```
|
|
165
|
+
$ toys
|
|
166
|
+
```
|
|
143
167
|
|
|
144
168
|
The help screen lists both the `greet` tool we started with, and the new
|
|
145
169
|
`new-repo` tool. This new tool creates a directory containing a newly created
|
|
146
170
|
git repo. (It assumes you have `git` available on your path.) Try running it:
|
|
147
171
|
|
|
148
|
-
|
|
172
|
+
```
|
|
173
|
+
$ toys new-repo foo
|
|
174
|
+
```
|
|
149
175
|
|
|
150
176
|
That should create a directory `foo`, initialize a git repository within it,
|
|
151
177
|
and make a commit.
|
|
@@ -155,7 +181,9 @@ any combination of flags and required and optional arguments. This tool's
|
|
|
155
181
|
argument is declared with a description string, which you can see if you view
|
|
156
182
|
the tool's help:
|
|
157
183
|
|
|
158
|
-
|
|
184
|
+
```
|
|
185
|
+
$ toys new-repo --help
|
|
186
|
+
```
|
|
159
187
|
|
|
160
188
|
The argument is marked as "optional" which means you can omit it. Notice that
|
|
161
189
|
the tool's code detects that it has been omitted and responds by prompting you
|
|
@@ -172,7 +200,7 @@ than modules. These symbols are the names of some of Toys's built-in helper
|
|
|
172
200
|
*mixins*, which are configurable modules that enhance your tool. They may
|
|
173
201
|
provide methods your tool can call, or invoke other behavior. In our example:
|
|
174
202
|
|
|
175
|
-
*
|
|
203
|
+
* The `:exec` mixin provides a variety of methods for running external
|
|
176
204
|
commands. In this example, we use the `exec` method to run shell
|
|
177
205
|
commands, but you can also signal and control these commands, capture
|
|
178
206
|
and redirect streams, and so forth. Note that we pass the
|
|
@@ -181,10 +209,10 @@ provide methods your tool can call, or invoke other behavior. In our example:
|
|
|
181
209
|
to `set -e` in bash). This is a common pattern when writing tools that
|
|
182
210
|
invoke external commands. (If you want more control, the `:exec` mixin also
|
|
183
211
|
provides ways to respond to result codes individually.)
|
|
184
|
-
*
|
|
212
|
+
* The `:fileutils` mixin provides the methods of the Ruby `FileUtils`
|
|
185
213
|
library, such as `mkdir` and `cd` used in this example. It's effectively
|
|
186
214
|
shorthand for `require "fileutils"; include ::FileUtils`.
|
|
187
|
-
*
|
|
215
|
+
* The `:terminal` mixin provides styled output, as you can see with the style
|
|
188
216
|
codes being passed to `puts`. It also provides some user interaction
|
|
189
217
|
commands such as `ask`, as well as spinners and other controls. You can see
|
|
190
218
|
operation of the `:terminal` mixin in the tool's output, which is styled
|
|
@@ -193,7 +221,9 @@ provide methods your tool can call, or invoke other behavior. In our example:
|
|
|
193
221
|
|
|
194
222
|
Now try running this:
|
|
195
223
|
|
|
196
|
-
|
|
224
|
+
```
|
|
225
|
+
$ toys new-repo bar --verbose
|
|
226
|
+
```
|
|
197
227
|
|
|
198
228
|
You'll notice some diagnostic log output. Toys provides a standard Ruby Logger
|
|
199
229
|
for each tool, and you can use it to emit diagnostic logs directly as
|
|
@@ -219,14 +249,18 @@ If you have a project with a Rakefile, move into that directory and create a
|
|
|
219
249
|
new file called `.toys.rb` in that same directory (next to the Rakefile). Add
|
|
220
250
|
the following line to your `.toys.rb` file:
|
|
221
251
|
|
|
222
|
-
|
|
252
|
+
```ruby
|
|
253
|
+
expand :rake
|
|
254
|
+
```
|
|
223
255
|
|
|
224
256
|
This syntax is called a "template expansion." It's a way to generate tools
|
|
225
257
|
programmatically. In this case, Toys provides the `:rake` template, which reads
|
|
226
258
|
your Rakefile and generates Toys tools corresponding to all your Rake tasks!
|
|
227
259
|
Now if you run:
|
|
228
260
|
|
|
229
|
-
|
|
261
|
+
```
|
|
262
|
+
$ toys
|
|
263
|
+
```
|
|
230
264
|
|
|
231
265
|
You'll see that you now have tools associated with each of your Rake tasks. So
|
|
232
266
|
if you have a `rake test` task, you can run it using `toys test`.
|
|
@@ -326,7 +360,7 @@ because it has a few known bugs that affect Toys.
|
|
|
326
360
|
|
|
327
361
|
## License
|
|
328
362
|
|
|
329
|
-
Copyright 2019-
|
|
363
|
+
Copyright 2019-2026 Daniel Azuma and the Toys contributors
|
|
330
364
|
|
|
331
365
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
332
366
|
of this software and associated documentation files (the "Software"), to deal
|
|
@@ -18,6 +18,28 @@ long_desc \
|
|
|
18
18
|
"The \"eval\" tool is the actual completion command invoked by zsh when it needs to" \
|
|
19
19
|
" complete a toys command line. You shouldn't need to invoke it directly."
|
|
20
20
|
|
|
21
|
+
tool "eval" do
|
|
22
|
+
desc "Tab completion command (executed by zsh)"
|
|
23
|
+
|
|
24
|
+
long_desc \
|
|
25
|
+
"Completion command invoked by zsh to complete a toys command line. Generally you do not" \
|
|
26
|
+
" need to invoke this directly. It reads the command line context from the COMP_LINE" \
|
|
27
|
+
" and COMP_POINT environment variables, and outputs completion candidates to stdout in" \
|
|
28
|
+
" two sections separated by a blank line: final completions first, then partial" \
|
|
29
|
+
" completions (such as directory paths)."
|
|
30
|
+
|
|
31
|
+
disable_argument_parsing
|
|
32
|
+
|
|
33
|
+
def run
|
|
34
|
+
require "toys/utils/completion_engine"
|
|
35
|
+
result = ::Toys::Utils::CompletionEngine::Zsh.new(cli).run
|
|
36
|
+
if result > 1
|
|
37
|
+
logger.fatal("This tool must be invoked as a zsh completion command.")
|
|
38
|
+
end
|
|
39
|
+
exit(result)
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
21
43
|
tool "install" do
|
|
22
44
|
desc "Install zsh tab completion"
|
|
23
45
|
|
|
@@ -67,25 +89,3 @@ tool "remove" do
|
|
|
67
89
|
puts ::Shellwords.join(["source", path] + exes)
|
|
68
90
|
end
|
|
69
91
|
end
|
|
70
|
-
|
|
71
|
-
tool "eval" do
|
|
72
|
-
desc "Tab completion command (executed by zsh)"
|
|
73
|
-
|
|
74
|
-
long_desc \
|
|
75
|
-
"Completion command invoked by zsh to complete a toys command line. Generally you do not" \
|
|
76
|
-
" need to invoke this directly. It reads the command line context from the COMP_LINE" \
|
|
77
|
-
" and COMP_POINT environment variables, and outputs completion candidates to stdout in" \
|
|
78
|
-
" two sections separated by a blank line: final completions first, then partial" \
|
|
79
|
-
" completions (such as directory paths)."
|
|
80
|
-
|
|
81
|
-
disable_argument_parsing
|
|
82
|
-
|
|
83
|
-
def run
|
|
84
|
-
require "toys/utils/completion_engine"
|
|
85
|
-
result = ::Toys::Utils::CompletionEngine::Zsh.new(cli).run
|
|
86
|
-
if result > 1
|
|
87
|
-
logger.fatal("This tool must be invoked as a zsh completion command.")
|
|
88
|
-
end
|
|
89
|
-
exit(result)
|
|
90
|
-
end
|
|
91
|
-
end
|
data/core-docs/toys/acceptor.rb
CHANGED
|
@@ -248,7 +248,9 @@ module Toys
|
|
|
248
248
|
# The array of enum values.
|
|
249
249
|
# @return [Array<Object>]
|
|
250
250
|
#
|
|
251
|
-
|
|
251
|
+
def values
|
|
252
|
+
# Source available in the toys-core gem
|
|
253
|
+
end
|
|
252
254
|
end
|
|
253
255
|
|
|
254
256
|
##
|
|
@@ -312,21 +314,21 @@ module Toys
|
|
|
312
314
|
# acceptors.
|
|
313
315
|
# @return [Proc]
|
|
314
316
|
#
|
|
315
|
-
INTEGER_CONVERTER = proc { |s|
|
|
317
|
+
INTEGER_CONVERTER = proc { |s| Integer(s) }
|
|
316
318
|
|
|
317
319
|
##
|
|
318
320
|
# A converter proc that handles floats. Useful in Simple and Range
|
|
319
321
|
# acceptors.
|
|
320
322
|
# @return [Proc]
|
|
321
323
|
#
|
|
322
|
-
FLOAT_CONVERTER = proc { |s|
|
|
324
|
+
FLOAT_CONVERTER = proc { |s| Float(s) }
|
|
323
325
|
|
|
324
326
|
##
|
|
325
327
|
# A converter proc that handles rationals. Useful in Simple and Range
|
|
326
328
|
# acceptors.
|
|
327
329
|
# @return [Proc]
|
|
328
330
|
#
|
|
329
|
-
RATIONAL_CONVERTER = proc { |s|
|
|
331
|
+
RATIONAL_CONVERTER = proc { |s| Rational(s) }
|
|
330
332
|
|
|
331
333
|
##
|
|
332
334
|
# A converter proc that handles any numeric value. Useful in Simple and
|
|
@@ -405,7 +407,7 @@ module Toys
|
|
|
405
407
|
# and type description you provide are ignored.
|
|
406
408
|
#
|
|
407
409
|
# * Any **regular expression**. The returned acceptor validates only if
|
|
408
|
-
# the regex matches the
|
|
410
|
+
# the regex matches the string parameter.
|
|
409
411
|
#
|
|
410
412
|
# You can also provide an optional conversion function as a block. If
|
|
411
413
|
# provided, the block must take a variable number of arguments, the
|
|
@@ -458,17 +460,6 @@ module Toys
|
|
|
458
460
|
def create(spec = nil, **options, &block)
|
|
459
461
|
# Source available in the toys-core gem
|
|
460
462
|
end
|
|
461
|
-
|
|
462
|
-
##
|
|
463
|
-
# Take the various ways to express an acceptor spec, and convert them to
|
|
464
|
-
# a canonical form expressed as a single object. This is called from the
|
|
465
|
-
# DSL to generate a spec object that can be stored.
|
|
466
|
-
#
|
|
467
|
-
# @private This interface is internal and subject to change without warning.
|
|
468
|
-
#
|
|
469
|
-
def scalarize_spec(spec, options, block)
|
|
470
|
-
# Source available in the toys-core gem
|
|
471
|
-
end
|
|
472
463
|
end
|
|
473
464
|
end
|
|
474
465
|
end
|
|
@@ -13,10 +13,12 @@ module Toys
|
|
|
13
13
|
#
|
|
14
14
|
# Base representation of a usage error reported by the ArgParser.
|
|
15
15
|
#
|
|
16
|
-
# This
|
|
17
|
-
#
|
|
16
|
+
# This is normally not raised directly, but returned as an element in the
|
|
17
|
+
# {Toys::ArgParser#errors} array. It will, however, have the normal
|
|
18
|
+
# message and backtrace attributes, along with additional fields as defined
|
|
19
|
+
# in this class, and it can be raised later if desired.
|
|
18
20
|
#
|
|
19
|
-
class UsageError
|
|
21
|
+
class UsageError < ::StandardError
|
|
20
22
|
##
|
|
21
23
|
# Create a UsageError given a message and common data
|
|
22
24
|
#
|
|
@@ -28,15 +30,17 @@ module Toys
|
|
|
28
30
|
# applicable.
|
|
29
31
|
# @param suggestions [Array<String>,nil] An array of suggestions from
|
|
30
32
|
# DidYouMean, or nil if not applicable.
|
|
33
|
+
# @param skip_frames [Integer] Number of call frames to skip when
|
|
34
|
+
# constructing a backtrace, in addition to this initialize call
|
|
35
|
+
# itself. Subclasses calling super from their constructor should set
|
|
36
|
+
# this to 1 to skip their own initialize frame.
|
|
31
37
|
#
|
|
32
|
-
def initialize(message, name: nil, value: nil, suggestions: nil)
|
|
38
|
+
def initialize(message, name: nil, value: nil, suggestions: nil, skip_frames: 0)
|
|
33
39
|
# Source available in the toys-core gem
|
|
34
40
|
end
|
|
35
41
|
|
|
36
42
|
##
|
|
37
|
-
# The
|
|
38
|
-
#
|
|
39
|
-
# @return [String]
|
|
43
|
+
# @return [String] The error message, not including any suggestions.
|
|
40
44
|
#
|
|
41
45
|
attr_reader :message
|
|
42
46
|
|
|
@@ -70,10 +74,10 @@ module Toys
|
|
|
70
74
|
#
|
|
71
75
|
# @return [String]
|
|
72
76
|
#
|
|
73
|
-
def
|
|
77
|
+
def message_with_suggestions
|
|
74
78
|
# Source available in the toys-core gem
|
|
75
79
|
end
|
|
76
|
-
alias to_s
|
|
80
|
+
alias to_s message_with_suggestions
|
|
77
81
|
end
|
|
78
82
|
|
|
79
83
|
##
|
|
@@ -227,12 +231,16 @@ module Toys
|
|
|
227
231
|
#
|
|
228
232
|
# @param message [String,nil] A custom message. Normally omitted, in
|
|
229
233
|
# which case an appropriate default is supplied.
|
|
230
|
-
# @param
|
|
231
|
-
# @param values [Array<String>] All extra arguments. Normally required.
|
|
234
|
+
# @param arguments [Array<String>] All extra arguments. Normally required.
|
|
232
235
|
#
|
|
233
|
-
def initialize(message = nil,
|
|
236
|
+
def initialize(message = nil, arguments: nil)
|
|
234
237
|
# Source available in the toys-core gem
|
|
235
238
|
end
|
|
239
|
+
|
|
240
|
+
##
|
|
241
|
+
# @return [Array<String>] All extra arguments
|
|
242
|
+
#
|
|
243
|
+
attr_reader :arguments
|
|
236
244
|
end
|
|
237
245
|
|
|
238
246
|
##
|
|
@@ -246,15 +254,19 @@ module Toys
|
|
|
246
254
|
#
|
|
247
255
|
# @param message [String,nil] A custom message. Normally omitted, in
|
|
248
256
|
# which case an appropriate default is supplied.
|
|
249
|
-
# @param
|
|
250
|
-
# @param values [Array<String>] The full path of the requested tool.
|
|
257
|
+
# @param full_name [Array<String>] The full path of the requested tool.
|
|
251
258
|
# Normally required.
|
|
252
259
|
# @param suggestions [Array<String>] An array of suggestions to present
|
|
253
260
|
# to the user. Optional.
|
|
254
261
|
#
|
|
255
|
-
def initialize(message = nil,
|
|
262
|
+
def initialize(message = nil, full_name: nil, suggestions: nil)
|
|
256
263
|
# Source available in the toys-core gem
|
|
257
264
|
end
|
|
265
|
+
|
|
266
|
+
##
|
|
267
|
+
# @return [Array<String>] The full name of the tool
|
|
268
|
+
#
|
|
269
|
+
attr_reader :full_name
|
|
258
270
|
end
|
|
259
271
|
|
|
260
272
|
##
|
|
@@ -268,7 +280,7 @@ module Toys
|
|
|
268
280
|
#
|
|
269
281
|
# @param message [String] The message. Required.
|
|
270
282
|
#
|
|
271
|
-
def initialize(message)
|
|
283
|
+
def initialize(message = nil)
|
|
272
284
|
# Source available in the toys-core gem
|
|
273
285
|
end
|
|
274
286
|
end
|
|
@@ -279,7 +291,7 @@ module Toys
|
|
|
279
291
|
# @param cli [Toys::CLI] The CLI in effect.
|
|
280
292
|
# @param tool [Toys::ToolDefinition] The tool defining the argument format.
|
|
281
293
|
# @param default_data [Hash] Additional initial data (such as verbosity).
|
|
282
|
-
# @param require_exact_flag_match [
|
|
294
|
+
# @param require_exact_flag_match [boolean] Whether to require flag matches
|
|
283
295
|
# be exact (not partial). Default is false.
|
|
284
296
|
#
|
|
285
297
|
def initialize(cli, tool, default_data: {}, require_exact_flag_match: false)
|
|
@@ -338,7 +350,7 @@ module Toys
|
|
|
338
350
|
|
|
339
351
|
##
|
|
340
352
|
# Whether flags are currently allowed. Returns false after `--` is received.
|
|
341
|
-
# @return [
|
|
353
|
+
# @return [boolean]
|
|
342
354
|
#
|
|
343
355
|
def flags_allowed?
|
|
344
356
|
# Source available in the toys-core gem
|
|
@@ -346,7 +358,7 @@ module Toys
|
|
|
346
358
|
|
|
347
359
|
##
|
|
348
360
|
# Determine if this parser is finished
|
|
349
|
-
# @return [
|
|
361
|
+
# @return [boolean]
|
|
350
362
|
#
|
|
351
363
|
def finished?
|
|
352
364
|
# Source available in the toys-core gem
|