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,118 +0,0 @@
1
- module Toys
2
- module Utils
3
- ##
4
- # **_Defined in the toys-core gem_**
5
- #
6
- # A class that invokes an external pager.
7
- #
8
- # @example Using a pager for regular output
9
- #
10
- # Toys::Utils::Pager.start do |io|
11
- # io.puts "A long string\n"
12
- # end
13
- #
14
- # @example Piping output from a command
15
- #
16
- # exec_service = Toys::Utils::Exec.new
17
- # Toys::Utils::Pager.start(exec_service: exec_service) do |io|
18
- # exec_service.exec(["/bin/ls", "-alF"], out: io)
19
- # end
20
- #
21
- class Pager
22
- ##
23
- # Creates a new pager.
24
- #
25
- # @param command [String,Array<String>,boolean] The command to use to
26
- # invoke the pager. May be specified as a string to be passed to the
27
- # shell, an array of strings representing a posix command, the value
28
- # `true` to use the default (normally `less -FIRX`), or the value
29
- # `false` to disable the pager and write directly to the output
30
- # stream. Default is `true`.
31
- # @param exec_service [Toys::Utils::Exec] The service to use for
32
- # executing commands, or `nil` (the default) to use a default.
33
- # @param fallback_io [IO] An IO-like object to write to if the pager is
34
- # disabled. Defaults to `$stdout`.
35
- # @param rescue_broken_pipes [boolean] If `true` (the default), broken
36
- # pipes are silently rescued. This prevents the exception from
37
- # propagating out if the pager is interrupted. Set this parameter to
38
- # `false` to disable this behavior.
39
- #
40
- def initialize(command: true, exec_service: nil, fallback_io: nil,
41
- rescue_broken_pipes: true)
42
- # Source available in the toys-core gem
43
- end
44
-
45
- ##
46
- # Runs the pager. Takes a block and yields an IO-like object that passes
47
- # text to the pager. Can be called multiple times on the same pager.
48
- #
49
- # @yieldparam io [IO] An object that can be written to, to pass data to
50
- # the pager.
51
- # @return [Integer] The exit code of the pager process.
52
- #
53
- # @example
54
- #
55
- # pager = Toys::Utils::Pager.new
56
- # pager.start do |io|
57
- # io.puts "A long string\n"
58
- # end
59
- #
60
- def start
61
- # Source available in the toys-core gem
62
- end
63
-
64
- ##
65
- # The command for running the pager process. May be specified as a string
66
- # to be passed to the shell, an array of strings representing a posix
67
- # command, or `nil` to disable the pager and write directly to an output
68
- # stream.
69
- #
70
- # @return [String,Array<String>,nil]
71
- #
72
- attr_accessor :command
73
-
74
- ##
75
- # The IO stream used if the pager is disabled or could not be executed.
76
- #
77
- # @return [IO]
78
- #
79
- attr_accessor :fallback_io
80
-
81
- class << self
82
- ##
83
- # A convenience method that creates a pager and runs it once by calling
84
- # {Pager#start}.
85
- #
86
- # @param command [String,Array<String>,boolean] The command to use to
87
- # invoke the pager. May be specified as a string to be passed to the
88
- # shell, an array of strings representing a posix command, the value
89
- # `true` to use the default (normally `less -FIRX`), or the value
90
- # `false` to disable the pager and write directly to the output
91
- # stream. Default is `true`.
92
- # @param exec_service [Toys::Utils::Exec] The service to use for
93
- # executing commands, or `nil` (the default) to use a default.
94
- # @param fallback_io [IO] An IO-like object to write to if the pager is
95
- # disabled. Defaults to `$stdout`.
96
- # @param rescue_broken_pipes [boolean] If `true` (the default), broken
97
- # pipes are silently rescued. This prevents the exception from
98
- # propagating out if the pager is interrupted. Set this parameter to
99
- # `false` to disable this behavior.
100
- # @return [Integer] The exit code of the pager process.
101
- #
102
- # @example
103
- #
104
- # Toys::Utils::Pager.start do |io|
105
- # io.puts "A long string\n"
106
- # end
107
- #
108
- def start(command: true,
109
- exec_service: nil,
110
- fallback_io: nil,
111
- rescue_broken_pipes: true,
112
- &block)
113
- # Source available in the toys-core gem
114
- end
115
- end
116
- end
117
- end
118
- end
@@ -1,184 +0,0 @@
1
- module Toys
2
- module Utils
3
- ##
4
- # **_Defined in the toys-core gem_**
5
- #
6
- # An object that implements standard UI elements, such as error reports and
7
- # logging, as provided by the `toys` command line. Specifically, it
8
- # implements pretty formatting of log entries and stack traces, and renders
9
- # using ANSI coloring where available via {Toys::Utils::Terminal}.
10
- #
11
- # This object can be used to implement `toys`-style behavior when creating
12
- # a CLI object. For example:
13
- #
14
- # require "toys/utils/standard_ui"
15
- # ui = Toys::Utils::StandardUI.new
16
- # cli = Toys::CLI.new(**ui.cli_args)
17
- #
18
- class StandardUI
19
- ##
20
- # Create a Standard UI.
21
- #
22
- # By default, all output is written to `$stderr`, and will share a single
23
- # {Toys::Utils::Terminal} object, allowing multiple tools and/or threads
24
- # to interleave messages without interrupting one another.
25
- #
26
- # @param output [IO,Toys::Utils::Terminal] Where to write output. You can
27
- # pass a terminal object, or an IO stream that will be wrapped in a
28
- # terminal output. Default is `$stderr`.
29
- #
30
- def initialize(output: nil)
31
- # Source available in the toys-core gem
32
- end
33
-
34
- ##
35
- # The terminal underlying this UI
36
- #
37
- # @return [Toys::Utils::Terminal]
38
- #
39
- attr_reader :terminal
40
-
41
- ##
42
- # A hash that maps severities to styles recognized by
43
- # {Toys::Utils::Terminal}. Used to style the header for each log entry.
44
- # This hash can be modified in place to adjust the behavior of loggers
45
- # created by this UI.
46
- #
47
- # @return [Hash{String => Array<Symbol>}]
48
- #
49
- attr_reader :log_header_severity_styles
50
-
51
- ##
52
- # Convenience method that returns a hash of arguments that can be passed
53
- # to the {Toys::CLI} constructor. Includes the `:error_handler` and
54
- # `:logger_factory` arguments.
55
- #
56
- # @return [Hash]
57
- #
58
- def cli_args
59
- # Source available in the toys-core gem
60
- end
61
-
62
- ##
63
- # Returns an error handler conforming to the `:error_handler` argument to
64
- # the {Toys::CLI} constructor. Specifically, it returns the
65
- # {#error_handler_impl} method as a proc.
66
- #
67
- # @return [Proc]
68
- #
69
- def error_handler
70
- # Source available in the toys-core gem
71
- end
72
-
73
- ##
74
- # Returns a logger factory conforming to the `:logger_factory` argument
75
- # to the {Toys::CLI} constructor. Specifically, it returns the
76
- # {#logger_factory_impl} method as a proc.
77
- #
78
- # @return [Proc]
79
- #
80
- def logger_factory
81
- # Source available in the toys-core gem
82
- end
83
-
84
- ##
85
- # Implementation of the error handler. As dictated by the error handler
86
- # specification in {Toys::CLI}, this must take a {Toys::ContextualError}
87
- # as an argument, and return an exit code.
88
- #
89
- # The base implementation uses {#display_error_notice} and
90
- # {#display_signal_notice} to print an appropriate message to the UI's
91
- # terminal, and uses {#exit_code_for} to determine the correct exit code.
92
- # Any of those methods can be overridden by a subclass to alter their
93
- # behavior, or this main implementation method can be overridden to
94
- # change the overall behavior.
95
- #
96
- # @param error [Toys::ContextualError] The error received
97
- # @return [Integer] The exit code
98
- #
99
- def error_handler_impl(error)
100
- # Source available in the toys-core gem
101
- end
102
-
103
- ##
104
- # Implementation of the logger factory. As dictated by the logger factory
105
- # specification in {Toys::CLI}, this must take a {Toys::ToolDefinition}
106
- # as an argument, and return a `Logger`.
107
- #
108
- # The base implementation returns a logger that writes to the UI's
109
- # terminal, using {#logger_formatter_impl} as the formatter. It sets the
110
- # level to `Logger::WARN` by default. Either this method or the helper
111
- # methods can be overridden to change this behavior.
112
- #
113
- # @param _tool {Toys::ToolDefinition} The tool definition of the tool to
114
- # be executed
115
- # @return [Logger]
116
- #
117
- def logger_factory_impl(_tool)
118
- # Source available in the toys-core gem
119
- end
120
-
121
- ##
122
- # Returns an exit code appropriate for the given exception. Currently,
123
- # the logic interprets signals (returning the convention of 128 + signo),
124
- # usage errors (returning the conventional value of 2), and tool not
125
- # runnable errors (returning the conventional value of 126), and defaults
126
- # to 1 for all other error types.
127
- #
128
- # This method is used by {#error_handler_impl} and can be overridden to
129
- # change its behavior.
130
- #
131
- # @param error [Exception] The exception raised. This method expects the
132
- # original exception, rather than a ContextualError.
133
- # @return [Integer] The appropriate exit code
134
- #
135
- def exit_code_for(error)
136
- # Source available in the toys-core gem
137
- end
138
-
139
- ##
140
- # Displays a default output for a signal received.
141
- #
142
- # This method is used by {#error_handler_impl} and can be overridden to
143
- # change its behavior.
144
- #
145
- # @param error [SignalException]
146
- #
147
- def display_signal_notice(error)
148
- # Source available in the toys-core gem
149
- end
150
-
151
- ##
152
- # Displays a default output for an error. Displays the error, the
153
- # backtrace, and contextual information regarding what tool was run and
154
- # where in its code the error occurred.
155
- #
156
- # This method is used by {#error_handler_impl} and can be overridden to
157
- # change its behavior.
158
- #
159
- # @param error [Toys::ContextualError]
160
- #
161
- def display_error_notice(error)
162
- # Source available in the toys-core gem
163
- end
164
-
165
- ##
166
- # Implementation of the formatter used by loggers created by this UI's
167
- # logger factory. This interface is defined by the standard `Logger`
168
- # class.
169
- #
170
- # This method can be overridden to change the behavior of loggers created
171
- # by this UI.
172
- #
173
- # @param severity [String]
174
- # @param time [Time]
175
- # @param _progname [String]
176
- # @param msg [Object]
177
- # @return [String]
178
- #
179
- def logger_formatter_impl(severity, time, _progname, msg)
180
- # Source available in the toys-core gem
181
- end
182
- end
183
- end
184
- end
@@ -1,310 +0,0 @@
1
- begin
2
- require "io/console"
3
- rescue ::LoadError
4
- # TODO: alternate methods of getting terminal size
5
- end
6
-
7
- module Toys
8
- module Utils
9
- ##
10
- # **_Defined in the toys-core gem_**
11
- #
12
- # A simple terminal class.
13
- #
14
- # ### Styles
15
- #
16
- # This class supports ANSI styled output where supported.
17
- #
18
- # Styles may be specified in any of the following forms:
19
- # * A symbol indicating the name of a well-known style, or the name of
20
- # a defined style.
21
- # * An rgb string in hex "rgb" or "rrggbb" form.
22
- # * An ANSI code string in `\e[XXm` form.
23
- # * An array of ANSI codes as integers.
24
- #
25
- class Terminal
26
- ##
27
- # **_Defined in the toys-core gem_**
28
- #
29
- # Fatal terminal error.
30
- #
31
- class TerminalError < ::StandardError
32
- end
33
-
34
- ##
35
- # ANSI style code to clear styles
36
- # @return [String]
37
- #
38
- CLEAR_CODE = "\e[0m"
39
-
40
- ##
41
- # Standard ANSI style codes by name.
42
- # @return [Hash{Symbol => Array<Integer>}]
43
- #
44
- BUILTIN_STYLE_NAMES = {
45
- clear: [0],
46
- reset: [0],
47
- bold: [1],
48
- faint: [2],
49
- italic: [3],
50
- underline: [4],
51
- blink: [5],
52
- reverse: [7],
53
- black: [30],
54
- red: [31],
55
- green: [32],
56
- yellow: [33],
57
- blue: [34],
58
- magenta: [35],
59
- cyan: [36],
60
- white: [37],
61
- on_black: [30],
62
- on_red: [31],
63
- on_green: [32],
64
- on_yellow: [33],
65
- on_blue: [34],
66
- on_magenta: [35],
67
- on_cyan: [36],
68
- on_white: [37],
69
- bright_black: [90],
70
- bright_red: [91],
71
- bright_green: [92],
72
- bright_yellow: [93],
73
- bright_blue: [94],
74
- bright_magenta: [95],
75
- bright_cyan: [96],
76
- bright_white: [97],
77
- on_bright_black: [100],
78
- on_bright_red: [101],
79
- on_bright_green: [102],
80
- on_bright_yellow: [103],
81
- on_bright_blue: [104],
82
- on_bright_magenta: [105],
83
- on_bright_cyan: [106],
84
- on_bright_white: [107],
85
- }.freeze
86
-
87
- ##
88
- # Default length of a single spinner frame, in seconds.
89
- # @return [Float]
90
- #
91
- DEFAULT_SPINNER_FRAME_LENGTH = 0.1
92
-
93
- ##
94
- # Default set of spinner frames.
95
- # @return [Array<String>]
96
- #
97
- DEFAULT_SPINNER_FRAMES = ["-", "\\", "|", "/"].freeze
98
-
99
- ##
100
- # Returns a copy of the given string with all ANSI style codes removed.
101
- #
102
- # @param str [String] Input string
103
- # @return [String] String with styles removed
104
- #
105
- def self.remove_style_escapes(str)
106
- # Source available in the toys-core gem
107
- end
108
-
109
- ##
110
- # Create a terminal.
111
- #
112
- # @param input [IO,nil] Input stream.
113
- # @param output [IO,Logger,nil] Output stream or logger.
114
- # @param styled [Boolean,nil] Whether to output ansi styles. If `nil`, the
115
- # setting is inferred from whether the output has a tty.
116
- #
117
- def initialize(input: $stdin, output: $stdout, styled: nil)
118
- # Source available in the toys-core gem
119
- end
120
-
121
- ##
122
- # Output stream or logger
123
- # @return [IO,Logger,nil]
124
- #
125
- attr_reader :output
126
-
127
- ##
128
- # Input stream
129
- # @return [IO,nil]
130
- #
131
- attr_reader :input
132
-
133
- ##
134
- # Whether output is styled
135
- # @return [Boolean]
136
- #
137
- attr_reader :styled
138
-
139
- ##
140
- # Write a partial line without appending a newline.
141
- #
142
- # @param str [String] The line to write
143
- # @param styles [Symbol,String,Array<Integer>...] Styles to apply to the
144
- # partial line.
145
- # @return [self]
146
- #
147
- def write(str = "", *styles)
148
- # Source available in the toys-core gem
149
- end
150
-
151
- ##
152
- # Read a line, blocking until one is available.
153
- #
154
- # @return [String] the entire string including the temrinating newline
155
- # @return [nil] if the input is closed or at eof, or there is no input
156
- #
157
- def readline
158
- # Source available in the toys-core gem
159
- end
160
-
161
- ##
162
- # This method is defined so that `::Logger` will recognize a terminal as
163
- # a log device target, but it does not actually close anything.
164
- #
165
- def close
166
- # Source available in the toys-core gem
167
- end
168
-
169
- ##
170
- # Write a line, appending a newline if one is not already present.
171
- #
172
- # @param str [String] The line to write
173
- # @param styles [Symbol,String,Array<Integer>...] Styles to apply to the
174
- # entire line.
175
- # @return [self]
176
- #
177
- def puts(str = "", *styles)
178
- # Source available in the toys-core gem
179
- end
180
- alias say puts
181
-
182
- ##
183
- # Write a line, appending a newline if one is not already present.
184
- #
185
- # @param str [String] The line to write
186
- # @return [self]
187
- #
188
- def <<(str)
189
- # Source available in the toys-core gem
190
- end
191
-
192
- ##
193
- # Write a newline and flush the current line.
194
- # @return [self]
195
- #
196
- def newline
197
- # Source available in the toys-core gem
198
- end
199
-
200
- ##
201
- # Ask a question and get a response.
202
- #
203
- # @param prompt [String] Required prompt string.
204
- # @param styles [Symbol,String,Array<Integer>...] Styles to apply to the
205
- # prompt.
206
- # @param default [String,nil] Default value, or `nil` for no default.
207
- # Uses `nil` if not specified.
208
- # @param trailing_text [:default,String,nil] Trailing text appended to
209
- # the prompt, `nil` for none, or `:default` to show the default.
210
- # @return [String]
211
- #
212
- def ask(prompt, *styles, default: nil, trailing_text: :default)
213
- # Source available in the toys-core gem
214
- end
215
-
216
- ##
217
- # Confirm with the user.
218
- #
219
- # @param prompt [String] Prompt string. Defaults to `"Proceed?"`.
220
- # @param styles [Symbol,String,Array<Integer>...] Styles to apply to the
221
- # prompt.
222
- # @param default [Boolean,nil] Default value, or `nil` for no default.
223
- # Uses `nil` if not specified.
224
- # @return [Boolean]
225
- #
226
- def confirm(prompt = "Proceed? ", *styles, default: nil)
227
- # Source available in the toys-core gem
228
- end
229
-
230
- ##
231
- # Display a spinner during a task. You should provide a block that
232
- # performs the long-running task. While the block is executing, a
233
- # spinner will be displayed.
234
- #
235
- # @param leading_text [String] Optional leading string to display to the
236
- # left of the spinner. Default is the empty string.
237
- # @param frame_length [Float] Length of a single frame, in seconds.
238
- # Defaults to {DEFAULT_SPINNER_FRAME_LENGTH}.
239
- # @param frames [Array<String>] An array of frames. Defaults to
240
- # {DEFAULT_SPINNER_FRAMES}.
241
- # @param style [Symbol,Array<Symbol>] A terminal style or array of styles
242
- # to apply to all frames in the spinner. Defaults to empty,
243
- # @param final_text [String] Optional final string to display when the
244
- # spinner is complete. Default is the empty string. A common practice
245
- # is to set this to newline.
246
- # @return [Object] The return value of the block.
247
- #
248
- def spinner(leading_text: "", final_text: "",
249
- frame_length: nil, frames: nil, style: nil)
250
- # Source available in the toys-core gem
251
- end
252
-
253
- ##
254
- # Return the terminal size as an array of width, height.
255
- #
256
- # @return [Array(Integer,Integer)]
257
- #
258
- def size
259
- # Source available in the toys-core gem
260
- end
261
-
262
- ##
263
- # Return the terminal width
264
- #
265
- # @return [Integer]
266
- #
267
- def width
268
- # Source available in the toys-core gem
269
- end
270
-
271
- ##
272
- # Return the terminal height
273
- #
274
- # @return [Integer]
275
- #
276
- def height
277
- # Source available in the toys-core gem
278
- end
279
-
280
- ##
281
- # Define a named style.
282
- #
283
- # Style names must be symbols.
284
- # The definition of a style may include any valid style specification,
285
- # including the symbol names of existing defined styles.
286
- #
287
- # @param name [Symbol] The name for the style
288
- # @param styles [Symbol,String,Array<Integer>...]
289
- # @return [self]
290
- #
291
- def define_style(name, *styles)
292
- # Source available in the toys-core gem
293
- end
294
-
295
- ##
296
- # Apply the given styles to the given string, returning the styled
297
- # string. Honors the styled setting; if styling is disabled, does not
298
- # add any ANSI style codes and in fact removes any existing codes. If
299
- # styles were added, ensures that the string ends with a clear code.
300
- #
301
- # @param str [String] String to style
302
- # @param styles [Symbol,String,Array<Integer>...] Styles to apply
303
- # @return [String] The styled string
304
- #
305
- def apply_styles(str, *styles)
306
- # Source available in the toys-core gem
307
- end
308
- end
309
- end
310
- end