toys 0.15.6 → 0.16.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.
Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +6 -1
  3. data/README.md +2 -2
  4. data/builtins/system/tools.rb +1 -1
  5. data/lib/toys/templates/clean.rb +1 -1
  6. data/lib/toys/templates/gem_build.rb +1 -1
  7. data/lib/toys/templates/rubocop.rb +4 -1
  8. data/lib/toys/version.rb +1 -1
  9. metadata +8 -63
  10. data/core-docs/toys/acceptor.rb +0 -474
  11. data/core-docs/toys/arg_parser.rb +0 -397
  12. data/core-docs/toys/cli.rb +0 -466
  13. data/core-docs/toys/compat.rb +0 -2
  14. data/core-docs/toys/completion.rb +0 -340
  15. data/core-docs/toys/context.rb +0 -386
  16. data/core-docs/toys/core.rb +0 -14
  17. data/core-docs/toys/dsl/base.rb +0 -56
  18. data/core-docs/toys/dsl/flag.rb +0 -284
  19. data/core-docs/toys/dsl/flag_group.rb +0 -267
  20. data/core-docs/toys/dsl/internal.rb +0 -4
  21. data/core-docs/toys/dsl/positional_arg.rb +0 -155
  22. data/core-docs/toys/dsl/tool.rb +0 -1639
  23. data/core-docs/toys/errors.rb +0 -126
  24. data/core-docs/toys/flag.rb +0 -560
  25. data/core-docs/toys/flag_group.rb +0 -186
  26. data/core-docs/toys/input_file.rb +0 -17
  27. data/core-docs/toys/loader.rb +0 -363
  28. data/core-docs/toys/middleware.rb +0 -336
  29. data/core-docs/toys/mixin.rb +0 -142
  30. data/core-docs/toys/module_lookup.rb +0 -75
  31. data/core-docs/toys/positional_arg.rb +0 -145
  32. data/core-docs/toys/settings.rb +0 -524
  33. data/core-docs/toys/source_info.rb +0 -271
  34. data/core-docs/toys/standard_middleware/add_verbosity_flags.rb +0 -49
  35. data/core-docs/toys/standard_middleware/apply_config.rb +0 -24
  36. data/core-docs/toys/standard_middleware/handle_usage_errors.rb +0 -33
  37. data/core-docs/toys/standard_middleware/set_default_descriptions.rb +0 -222
  38. data/core-docs/toys/standard_middleware/show_help.rb +0 -190
  39. data/core-docs/toys/standard_middleware/show_root_version.rb +0 -45
  40. data/core-docs/toys/standard_mixins/bundler.rb +0 -98
  41. data/core-docs/toys/standard_mixins/exec.rb +0 -711
  42. data/core-docs/toys/standard_mixins/fileutils.rb +0 -18
  43. data/core-docs/toys/standard_mixins/gems.rb +0 -62
  44. data/core-docs/toys/standard_mixins/git_cache.rb +0 -41
  45. data/core-docs/toys/standard_mixins/highline.rb +0 -133
  46. data/core-docs/toys/standard_mixins/pager.rb +0 -50
  47. data/core-docs/toys/standard_mixins/terminal.rb +0 -135
  48. data/core-docs/toys/standard_mixins/xdg.rb +0 -49
  49. data/core-docs/toys/template.rb +0 -112
  50. data/core-docs/toys/tool_definition.rb +0 -1079
  51. data/core-docs/toys/utils/completion_engine.rb +0 -49
  52. data/core-docs/toys/utils/exec.rb +0 -776
  53. data/core-docs/toys/utils/gems.rb +0 -185
  54. data/core-docs/toys/utils/git_cache.rb +0 -353
  55. data/core-docs/toys/utils/help_text.rb +0 -134
  56. data/core-docs/toys/utils/pager.rb +0 -118
  57. data/core-docs/toys/utils/standard_ui.rb +0 -184
  58. data/core-docs/toys/utils/terminal.rb +0 -310
  59. data/core-docs/toys/utils/xdg.rb +0 -253
  60. data/core-docs/toys/wrappable_string.rb +0 -132
  61. data/core-docs/toys-core.rb +0 -111
@@ -1,466 +0,0 @@
1
- module Toys
2
- ##
3
- # **_Defined in the toys-core gem_**
4
- #
5
- # A Toys-based CLI.
6
- #
7
- # This is the entry point for command line execution. It includes the set of
8
- # tool definitions (and/or information on how to load them from the file
9
- # system), configuration parameters such as logging and error handling, and a
10
- # method to call to invoke a command.
11
- #
12
- # This is the class to instantiate to create a Toys-based command line
13
- # executable. For example:
14
- #
15
- # #!/usr/bin/env ruby
16
- # require "toys-core"
17
- # cli = Toys::CLI.new
18
- # cli.add_config_block do
19
- # def run
20
- # puts "Hello, world!"
21
- # end
22
- # end
23
- # exit(cli.run(*ARGV))
24
- #
25
- # The currently running CLI is also available at runtime, and can be used by
26
- # tools that want to invoke other tools. For example:
27
- #
28
- # # My .toys.rb
29
- # tool "foo" do
30
- # def run
31
- # puts "in foo"
32
- # end
33
- # end
34
- # tool "bar" do
35
- # def run
36
- # puts "in bar"
37
- # cli.run "foo"
38
- # end
39
- # end
40
- #
41
- class CLI
42
- ##
43
- # Create a CLI.
44
- #
45
- # Most configuration parameters (besides tool definitions and tool lookup
46
- # paths) are set as options passed to the constructor. These options fall
47
- # roughly into four categories:
48
- #
49
- # * Options affecting output behavior:
50
- # * `logger`: A global logger for all tools to use
51
- # * `logger_factory`: A proc that returns a logger to use
52
- # * `base_level`: The default log level
53
- # * `error_handler`: Callback for handling exceptions
54
- # * `executable_name`: The name of the executable
55
- # * Options affecting tool specification
56
- # * `extra_delimibers`: Tool name delimiters besides space
57
- # * `completion`: Tab completion handler
58
- # * Options affecting tool definition
59
- # * `middleware_stack`: The middleware applied to all tools
60
- # * `mixin_lookup`: Where to find well-known mixins
61
- # * `middleware_lookup`: Where to find well-known middleware
62
- # * `template_lookup`: Where to find well-known templates
63
- # * Options affecting tool files and directories
64
- # * `config_dir_name`: Directory name containing tool files
65
- # * `config_file_name`: File name for tools
66
- # * `index_file_name`: Name of index files in tool directories
67
- # * `preload_file_name`: Name of preload files in tool directories
68
- # * `preload_dir_name`: Name of preload directories in tool directories
69
- # * `data_dir_name`: Name of data directories in tool directories
70
- #
71
- # @param logger [Logger] A global logger to use for all tools. This can be
72
- # set if the CLI will call at most one tool at a time. However, it will
73
- # behave incorrectly if CLI might run multiple tools at the same time
74
- # with different verbosity settings (since the logger cannot have
75
- # multiple level settings simultaneously). In that case, do not set a
76
- # global logger, but use the `logger_factory` parameter instead.
77
- # @param logger_factory [Proc] A proc that takes a {Toys::ToolDefinition}
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
- # {Toys::CLI.default_logger_factory} is called to get a basic default.
81
- # @param base_level [Integer] The logger level that should correspond
82
- # to zero verbosity.
83
- # Optional. If not provided, defaults to the current level of the
84
- # logger (which is often `Logger::WARN`).
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.
94
- # @param executable_name [String] The executable name displayed in help
95
- # text. Optional. Defaults to the ruby program name.
96
- #
97
- # @param extra_delimiters [String] A string containing characters that can
98
- # function as delimiters in a tool name. Defaults to empty. Allowed
99
- # characters are period, colon, and slash.
100
- # @param completion [Toys::Completion::Base] A specifier for shell tab
101
- # completion for the CLI as a whole.
102
- # Optional. If not provided, {Toys::CLI.default_completion} is called
103
- # to get a default completion that delegates to the tool.
104
- #
105
- # @param middleware_stack [Array<Toys::Middleware::Spec>] An array of
106
- # middleware that will be used by default for all tools.
107
- # Optional. If not provided, uses a default set of middleware defined
108
- # in {Toys::CLI.default_middleware_stack}. To include no middleware,
109
- # pass the empty array explicitly.
110
- # @param mixin_lookup [Toys::ModuleLookup] A lookup for well-known mixin
111
- # modules (i.e. with symbol names).
112
- # Optional. If not provided, defaults to the set of standard mixins
113
- # provided by toys-core, as defined by
114
- # {Toys::CLI.default_mixin_lookup}. If you explicitly want no standard
115
- # mixins, pass an empty instance of {Toys::ModuleLookup}.
116
- # @param middleware_lookup [Toys::ModuleLookup] A lookup for well-known
117
- # middleware classes.
118
- # Optional. If not provided, defaults to the set of standard middleware
119
- # classes provided by toys-core, as defined by
120
- # {Toys::CLI.default_middleware_lookup}. If you explicitly want no
121
- # standard middleware, pass an empty instance of
122
- # {Toys::ModuleLookup}.
123
- # @param template_lookup [Toys::ModuleLookup] A lookup for well-known
124
- # template classes.
125
- # Optional. If not provided, defaults to the set of standard template
126
- # classes provided by toys core, as defined by
127
- # {Toys::CLI.default_template_lookup}. If you explicitly want no
128
- # standard tenokates, pass an empty instance of {Toys::ModuleLookup}.
129
- #
130
- # @param config_dir_name [String] A directory with this name that appears
131
- # in the loader path, is treated as a configuration directory whose
132
- # contents are loaded into the toys configuration.
133
- # Optional. If not provided, toplevel configuration directories are
134
- # disabled.
135
- # Note: the standard toys executable sets this to `".toys"`.
136
- # @param config_file_name [String] A file with this name that appears in
137
- # the loader path, is treated as a toplevel configuration file whose
138
- # contents are loaded into the toys configuration. This does not
139
- # include "index" configuration files located within a configuration
140
- # directory.
141
- # Optional. If not provided, toplevel configuration files are disabled.
142
- # Note: the standard toys executable sets this to `".toys.rb"`.
143
- # @param index_file_name [String] A file with this name that appears in any
144
- # configuration directory is loaded first as a standalone configuration
145
- # file. This does not include "toplevel" configuration files outside
146
- # configuration directories.
147
- # Optional. If not provided, index configuration files are disabled.
148
- # Note: the standard toys executable sets this to `".toys.rb"`.
149
- # @param preload_file_name [String] A file with this name that appears
150
- # in any configuration directory is preloaded using `require` before
151
- # any tools in that configuration directory are defined. A preload file
152
- # includes normal Ruby code, rather than Toys DSL definitions. The
153
- # preload file is loaded before any files in a preload directory.
154
- # Optional. If not provided, preload files are disabled.
155
- # Note: the standard toys executable sets this to `".preload.rb"`.
156
- # @param preload_dir_name [String] A directory with this name that appears
157
- # in any configuration directory is searched for Ruby files, which are
158
- # preloaded using `require` before any tools in that configuration
159
- # directory are defined. Files in a preload directory include normal
160
- # Ruby code, rather than Toys DSL definitions. Files in a preload
161
- # directory are loaded after any standalone preload file.
162
- # Optional. If not provided, preload directories are disabled.
163
- # Note: the standard toys executable sets this to `".preload"`.
164
- # @param data_dir_name [String] A directory with this name that appears in
165
- # any configuration directory is added to the data directory search
166
- # path for any tool file in that directory.
167
- # Optional. If not provided, data directories are disabled.
168
- # Note: the standard toys executable sets this to `".data"`.
169
- # @param lib_dir_name [String] A directory with this name that appears in
170
- # any configuration directory is added to the Ruby load path when
171
- # executing any tool file in that directory.
172
- # Optional. If not provided, lib directories are disabled.
173
- # Note: the standard toys executable sets this to `".lib"`.
174
- #
175
- def initialize(executable_name: nil, # rubocop:disable Metrics/MethodLength
176
- middleware_stack: nil,
177
- extra_delimiters: "",
178
- config_dir_name: nil,
179
- config_file_name: nil,
180
- index_file_name: nil,
181
- preload_file_name: nil,
182
- preload_dir_name: nil,
183
- data_dir_name: nil,
184
- lib_dir_name: nil,
185
- mixin_lookup: nil,
186
- middleware_lookup: nil,
187
- template_lookup: nil,
188
- logger_factory: nil,
189
- logger: nil,
190
- base_level: nil,
191
- error_handler: nil,
192
- completion: nil)
193
- # Source available in the toys-core gem
194
- end
195
-
196
- ##
197
- # Make a clone with the same settings but no config blocks and no paths in
198
- # the loader. This is sometimes useful for calling another tool that has to
199
- # be loaded from a different configuration.
200
- #
201
- # @param opts [keywords] Any configuration arguments that should be
202
- # modified from the original. See {#initialize} for a list of
203
- # recognized keywords.
204
- # @return [Toys::CLI]
205
- # @yieldparam cli [Toys::CLI] If you pass a block, the new CLI is yielded
206
- # to it so you can add paths and make other modifications.
207
- #
208
- def child(**opts)
209
- # Source available in the toys-core gem
210
- end
211
-
212
- ##
213
- # The current loader for this CLI.
214
- # @return [Toys::Loader]
215
- #
216
- attr_reader :loader
217
-
218
- ##
219
- # The effective executable name used for usage text in this CLI.
220
- # @return [String]
221
- #
222
- attr_reader :executable_name
223
-
224
- ##
225
- # The string of tool name delimiter characters (besides space).
226
- # @return [String]
227
- #
228
- attr_reader :extra_delimiters
229
-
230
- ##
231
- # The global logger, if any.
232
- # @return [Logger,nil]
233
- #
234
- attr_reader :logger
235
-
236
- ##
237
- # The logger factory.
238
- # @return [Proc]
239
- #
240
- attr_reader :logger_factory
241
-
242
- ##
243
- # The initial logger level in this CLI, used as the level for verbosity 0.
244
- # May be `nil`, indicating it will use the initial logger setting.
245
- # @return [Integer,nil]
246
- #
247
- attr_reader :base_level
248
-
249
- ##
250
- # The overall completion strategy for this CLI.
251
- # @return [Toys::Completion::Base,Proc]
252
- #
253
- attr_reader :completion
254
-
255
- ##
256
- # Add a specific configuration file or directory to the loader.
257
- #
258
- # This is generally used to load a static or "built-in" set of tools,
259
- # either for a standalone command line executable based on Toys, or to
260
- # provide a "default" set of tools for a dynamic executable. For example,
261
- # the main Toys executable uses this to load the builtin tools from its
262
- # "builtins" directory.
263
- #
264
- # @param path [String] A path to add. May reference a single Toys file or
265
- # a Toys directory.
266
- # @param high_priority [Boolean] Add the config at the head of the priority
267
- # list rather than the tail.
268
- # @param source_name [String] A custom name for the root source. Optional.
269
- # @param context_directory [String,nil,:path,:parent] The context directory
270
- # for tools loaded from this path. You can pass a directory path as a
271
- # string, `:path` to denote the given path, `:parent` to denote the
272
- # given path's parent directory, or `nil` to denote no context.
273
- # Defaults to `:parent`.
274
- # @return [self]
275
- #
276
- def add_config_path(path,
277
- high_priority: false,
278
- source_name: nil,
279
- context_directory: :parent)
280
- # Source available in the toys-core gem
281
- end
282
-
283
- ##
284
- # Add a configuration block to the loader.
285
- #
286
- # This is used to create tools "inline", and is useful for simple command
287
- # line executables based on Toys.
288
- #
289
- # @param high_priority [Boolean] Add the config at the head of the priority
290
- # list rather than the tail.
291
- # @param source_name [String] The source name that will be shown in
292
- # documentation for tools defined in this block. If omitted, a default
293
- # unique string will be generated.
294
- # @param block [Proc] The block of configuration, executed in the context
295
- # of the tool DSL {Toys::DSL::Tool}.
296
- # @param context_directory [String,nil] The context directory for tools
297
- # loaded from this block. You can pass a directory path as a string, or
298
- # `nil` to denote no context. Defaults to `nil`.
299
- # @return [self]
300
- #
301
- def add_config_block(high_priority: false,
302
- source_name: nil,
303
- context_directory: nil,
304
- &block)
305
- # Source available in the toys-core gem
306
- end
307
-
308
- ##
309
- # Checks the given directory path. If it contains a config file and/or
310
- # config directory, those are added to the loader.
311
- #
312
- # The main Toys executable uses this method to load tools from directories
313
- # in the `TOYS_PATH`.
314
- #
315
- # @param search_path [String] A path to search for configs.
316
- # @param high_priority [Boolean] Add the configs at the head of the
317
- # priority list rather than the tail.
318
- # @param context_directory [String,nil,:path,:parent] The context directory
319
- # for tools loaded from this path. You can pass a directory path as a
320
- # string, `:path` to denote the given path, `:parent` to denote the
321
- # given path's parent directory, or `nil` to denote no context.
322
- # Defaults to `:path`.
323
- # @return [self]
324
- #
325
- def add_search_path(search_path,
326
- high_priority: false,
327
- context_directory: :path)
328
- # Source available in the toys-core gem
329
- end
330
-
331
- ##
332
- # Walk up the directory hierarchy from the given start location, and add to
333
- # the loader any config files and directories found.
334
- #
335
- # The main Toys executable uses this method to load tools from the current
336
- # directory and its ancestors.
337
- #
338
- # @param start [String] The first directory to add. Defaults to the current
339
- # working directory.
340
- # @param terminate [Array<String>] Optional list of directories that should
341
- # terminate the search. If the walk up the directory tree encounters
342
- # one of these directories, the search is halted without checking the
343
- # terminating directory.
344
- # @param high_priority [Boolean] Add the configs at the head of the
345
- # priority list rather than the tail.
346
- # @return [self]
347
- #
348
- def add_search_path_hierarchy(start: nil, terminate: [], high_priority: false)
349
- # Source available in the toys-core gem
350
- end
351
-
352
- ##
353
- # Run the CLI with the given command line arguments.
354
- # Handles exceptions using the error handler.
355
- #
356
- # @param args [String...] Command line arguments specifying which tool to
357
- # run and what arguments to pass to it. You may pass either a single
358
- # array of strings, or a series of string arguments.
359
- # @param verbosity [Integer] Initial verbosity. Default is 0.
360
- # @param delegated_from [Toys::Context] The context from which this
361
- # execution is delegated. Optional. Should be set only if this is a
362
- # delegated execution.
363
- #
364
- # @return [Integer] The resulting process status code (i.e. 0 for success).
365
- #
366
- def run(*args, verbosity: 0, delegated_from: nil)
367
- # Source available in the toys-core gem
368
- end
369
-
370
- ##
371
- # Prepare a tool to be run, but just execute the given block rather than
372
- # performing a full run of the tool. This is intended for testing tools.
373
- # Unlike {#run}, this does not catch errors and perform error handling.
374
- #
375
- # @param args [String...] Command line arguments specifying which tool to
376
- # run and what arguments to pass to it. You may pass either a single
377
- # array of strings, or a series of string arguments.
378
- # @yieldparam context [Toys::Context] Yields the tool context.
379
- #
380
- # @return [Object] The value returned from the block.
381
- #
382
- def load_tool(*args)
383
- # Source available in the toys-core gem
384
- end
385
-
386
- class << self
387
- ##
388
- # Returns a default set of middleware that may be used as a starting
389
- # point for a typical CLI. This set includes the following in order:
390
- #
391
- # * {Toys::StandardMiddleware::SetDefaultDescriptions} providing
392
- # defaults for description fields.
393
- # * {Toys::StandardMiddleware::ShowHelp} adding the `--help` flag and
394
- # providing default behavior for namespaces.
395
- # * {Toys::StandardMiddleware::HandleUsageErrors}
396
- # * {Toys::StandardMiddleware::AddVerbosityFlags} adding the `--verbose`
397
- # and `--quiet` flags for managing the logger level.
398
- #
399
- # @return [Array<Toys::Middleware::Spec>]
400
- #
401
- def default_middleware_stack
402
- # Source available in the toys-core gem
403
- end
404
-
405
- ##
406
- # Returns a default ModuleLookup for mixins that points at the
407
- # StandardMixins module.
408
- #
409
- # @return [Toys::ModuleLookup]
410
- #
411
- def default_mixin_lookup
412
- # Source available in the toys-core gem
413
- end
414
-
415
- ##
416
- # Returns a default ModuleLookup for middleware that points at the
417
- # StandardMiddleware module.
418
- #
419
- # @return [Toys::ModuleLookup]
420
- #
421
- def default_middleware_lookup
422
- # Source available in the toys-core gem
423
- end
424
-
425
- ##
426
- # Returns a default empty ModuleLookup for templates.
427
- #
428
- # @return [Toys::ModuleLookup]
429
- #
430
- def default_template_lookup
431
- # Source available in the toys-core gem
432
- end
433
-
434
- ##
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.
451
- #
452
- # @return [Proc]
453
- #
454
- def default_logger_factory
455
- # Source available in the toys-core gem
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
464
- end
465
- end
466
- end
@@ -1,2 +0,0 @@
1
- module Toys
2
- end