toys-core 0.7.0 → 0.8.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 +98 -0
- data/LICENSE.md +16 -24
- data/README.md +307 -59
- data/docs/guide.md +44 -4
- data/lib/toys-core.rb +58 -49
- data/lib/toys/acceptor.rb +672 -0
- data/lib/toys/alias.rb +106 -0
- data/lib/toys/arg_parser.rb +624 -0
- data/lib/toys/cli.rb +422 -181
- data/lib/toys/compat.rb +83 -0
- data/lib/toys/completion.rb +442 -0
- data/lib/toys/context.rb +354 -0
- data/lib/toys/core_version.rb +18 -26
- data/lib/toys/dsl/flag.rb +213 -56
- data/lib/toys/dsl/flag_group.rb +237 -51
- data/lib/toys/dsl/positional_arg.rb +210 -0
- data/lib/toys/dsl/tool.rb +968 -317
- data/lib/toys/errors.rb +46 -28
- data/lib/toys/flag.rb +821 -0
- data/lib/toys/flag_group.rb +282 -0
- data/lib/toys/input_file.rb +18 -26
- data/lib/toys/loader.rb +110 -100
- data/lib/toys/middleware.rb +24 -31
- data/lib/toys/mixin.rb +90 -59
- data/lib/toys/module_lookup.rb +125 -0
- data/lib/toys/positional_arg.rb +184 -0
- data/lib/toys/source_info.rb +192 -0
- data/lib/toys/standard_middleware/add_verbosity_flags.rb +38 -43
- data/lib/toys/standard_middleware/handle_usage_errors.rb +39 -40
- data/lib/toys/standard_middleware/set_default_descriptions.rb +111 -89
- data/lib/toys/standard_middleware/show_help.rb +130 -113
- data/lib/toys/standard_middleware/show_root_version.rb +29 -35
- data/lib/toys/standard_mixins/exec.rb +116 -78
- data/lib/toys/standard_mixins/fileutils.rb +16 -24
- data/lib/toys/standard_mixins/gems.rb +29 -30
- data/lib/toys/standard_mixins/highline.rb +34 -41
- data/lib/toys/standard_mixins/terminal.rb +72 -26
- data/lib/toys/template.rb +51 -35
- data/lib/toys/tool.rb +1161 -206
- data/lib/toys/utils/completion_engine.rb +171 -0
- data/lib/toys/utils/exec.rb +279 -182
- data/lib/toys/utils/gems.rb +58 -49
- data/lib/toys/utils/help_text.rb +117 -111
- data/lib/toys/utils/terminal.rb +69 -62
- data/lib/toys/wrappable_string.rb +162 -0
- metadata +24 -22
- data/lib/toys/definition/acceptor.rb +0 -191
- data/lib/toys/definition/alias.rb +0 -112
- data/lib/toys/definition/arg.rb +0 -140
- data/lib/toys/definition/flag.rb +0 -370
- data/lib/toys/definition/flag_group.rb +0 -205
- data/lib/toys/definition/source_info.rb +0 -190
- data/lib/toys/definition/tool.rb +0 -842
- data/lib/toys/dsl/arg.rb +0 -132
- data/lib/toys/runner.rb +0 -188
- data/lib/toys/standard_middleware.rb +0 -47
- data/lib/toys/utils/module_lookup.rb +0 -135
- data/lib/toys/utils/wrappable_string.rb +0 -165
data/lib/toys/utils/terminal.rb
CHANGED
@@ -1,32 +1,24 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright
|
3
|
+
# Copyright 2019 Daniel Azuma
|
4
4
|
#
|
5
|
-
#
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
# of this software and associated documentation files (the "Software"), to deal
|
7
|
+
# in the Software without restriction, including without limitation the rights
|
8
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
# copies of the Software, and to permit persons to whom the Software is
|
10
|
+
# furnished to do so, subject to the following conditions:
|
6
11
|
#
|
7
|
-
#
|
8
|
-
#
|
12
|
+
# The above copyright notice and this permission notice shall be included in
|
13
|
+
# all copies or substantial portions of the Software.
|
9
14
|
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
#
|
15
|
-
#
|
16
|
-
#
|
17
|
-
# derived from this software without specific prior written permission.
|
18
|
-
#
|
19
|
-
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
20
|
-
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
21
|
-
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
22
|
-
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
23
|
-
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
24
|
-
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
25
|
-
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
26
|
-
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
27
|
-
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
28
|
-
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
29
|
-
# POSSIBILITY OF SUCH DAMAGE.
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
20
|
+
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
21
|
+
# IN THE SOFTWARE.
|
30
22
|
;
|
31
23
|
|
32
24
|
require "stringio"
|
@@ -48,11 +40,11 @@ module Toys
|
|
48
40
|
# This class supports ANSI styled output where supported.
|
49
41
|
#
|
50
42
|
# Styles may be specified in any of the following forms:
|
51
|
-
#
|
43
|
+
# * A symbol indicating the name of a well-known style, or the name of
|
52
44
|
# a defined style.
|
53
|
-
#
|
54
|
-
#
|
55
|
-
#
|
45
|
+
# * An rgb string in hex "rgb" or "rrggbb" form.
|
46
|
+
# * An ANSI code string in `\e[XXm` form.
|
47
|
+
# * An array of ANSI codes as integers.
|
56
48
|
#
|
57
49
|
class Terminal
|
58
50
|
##
|
@@ -61,10 +53,16 @@ module Toys
|
|
61
53
|
class TerminalError < ::StandardError
|
62
54
|
end
|
63
55
|
|
64
|
-
##
|
56
|
+
##
|
57
|
+
# ANSI style code to clear styles
|
58
|
+
# @return [String]
|
59
|
+
#
|
65
60
|
CLEAR_CODE = "\e[0m"
|
66
61
|
|
67
|
-
##
|
62
|
+
##
|
63
|
+
# Standard ANSI style codes by name.
|
64
|
+
# @return [Hash{Symbol => Array<Integer>}]
|
65
|
+
#
|
68
66
|
BUILTIN_STYLE_NAMES = {
|
69
67
|
clear: [0],
|
70
68
|
reset: [0],
|
@@ -105,7 +103,7 @@ module Toys
|
|
105
103
|
on_bright_blue: [104],
|
106
104
|
on_bright_magenta: [105],
|
107
105
|
on_bright_cyan: [106],
|
108
|
-
on_bright_white: [107]
|
106
|
+
on_bright_white: [107],
|
109
107
|
}.freeze
|
110
108
|
|
111
109
|
##
|
@@ -123,7 +121,7 @@ module Toys
|
|
123
121
|
##
|
124
122
|
# Returns a copy of the given string with all ANSI style codes removed.
|
125
123
|
#
|
126
|
-
# @param [String]
|
124
|
+
# @param str [String] Input string
|
127
125
|
# @return [String] String with styles removed
|
128
126
|
#
|
129
127
|
def self.remove_style_escapes(str)
|
@@ -133,12 +131,12 @@ module Toys
|
|
133
131
|
##
|
134
132
|
# Create a terminal.
|
135
133
|
#
|
136
|
-
# @param [IO,
|
137
|
-
# @param [IO,nil]
|
134
|
+
# @param input [IO,nil] Input stream.
|
135
|
+
# @param output [IO,Logger,nil] Output stream or logger.
|
136
|
+
# @param styled [Boolean,nil] Whether to output ansi styles. If `nil`, the
|
137
|
+
# setting is inferred from whether the output has a tty.
|
138
138
|
#
|
139
|
-
def initialize(input: $stdin,
|
140
|
-
output: $stdout,
|
141
|
-
styled: nil)
|
139
|
+
def initialize(input: $stdin, output: $stdout, styled: nil)
|
142
140
|
@input = input
|
143
141
|
@output = output
|
144
142
|
@styled =
|
@@ -171,22 +169,24 @@ module Toys
|
|
171
169
|
##
|
172
170
|
# Write a partial line without appending a newline.
|
173
171
|
#
|
174
|
-
# @param [String]
|
175
|
-
# @param [Symbol,String,Array<Integer>...]
|
172
|
+
# @param str [String] The line to write
|
173
|
+
# @param styles [Symbol,String,Array<Integer>...] Styles to apply to the
|
176
174
|
# partial line.
|
175
|
+
# @return [self]
|
177
176
|
#
|
178
177
|
def write(str = "", *styles)
|
179
|
-
output
|
180
|
-
output
|
178
|
+
output&.write(apply_styles(str, *styles))
|
179
|
+
output&.flush
|
181
180
|
self
|
182
181
|
end
|
183
182
|
|
184
183
|
##
|
185
184
|
# Write a line, appending a newline if one is not already present.
|
186
185
|
#
|
187
|
-
# @param [String]
|
188
|
-
# @param [Symbol,String,Array<Integer>...]
|
186
|
+
# @param str [String] The line to write
|
187
|
+
# @param styles [Symbol,String,Array<Integer>...] Styles to apply to the
|
189
188
|
# entire line.
|
189
|
+
# @return [self]
|
190
190
|
#
|
191
191
|
def puts(str = "", *styles)
|
192
192
|
str = "#{str}\n" unless str.end_with?("\n")
|
@@ -197,7 +197,8 @@ module Toys
|
|
197
197
|
##
|
198
198
|
# Write a line, appending a newline if one is not already present.
|
199
199
|
#
|
200
|
-
# @param [String]
|
200
|
+
# @param str [String] The line to write
|
201
|
+
# @return [self]
|
201
202
|
#
|
202
203
|
def <<(str)
|
203
204
|
puts(str)
|
@@ -205,6 +206,7 @@ module Toys
|
|
205
206
|
|
206
207
|
##
|
207
208
|
# Write a newline and flush the current line.
|
209
|
+
# @return [self]
|
208
210
|
#
|
209
211
|
def newline
|
210
212
|
puts
|
@@ -213,12 +215,12 @@ module Toys
|
|
213
215
|
##
|
214
216
|
# Ask a question and get a response.
|
215
217
|
#
|
216
|
-
# @param [String]
|
217
|
-
# @param [Symbol,String,Array<Integer>...]
|
218
|
+
# @param prompt [String] Required prompt string.
|
219
|
+
# @param styles [Symbol,String,Array<Integer>...] Styles to apply to the
|
218
220
|
# prompt.
|
219
|
-
# @param [String,nil]
|
221
|
+
# @param default [String,nil] Default value, or `nil` for no default.
|
220
222
|
# Uses `nil` if not specified.
|
221
|
-
# @param [:default,String,nil]
|
223
|
+
# @param trailing_text [:default,String,nil] Trailing text appended to
|
222
224
|
# the prompt, `nil` for none, or `:default` to show the default.
|
223
225
|
# @return [String]
|
224
226
|
#
|
@@ -231,17 +233,17 @@ module Toys
|
|
231
233
|
prompt = "#{ptext} #{trailing_text}#{pspaces}"
|
232
234
|
end
|
233
235
|
write(prompt, *styles)
|
234
|
-
resp = input
|
236
|
+
resp = input&.gets.to_s.chomp
|
235
237
|
resp.empty? ? default.to_s : resp
|
236
238
|
end
|
237
239
|
|
238
240
|
##
|
239
241
|
# Confirm with the user.
|
240
242
|
#
|
241
|
-
# @param [String]
|
242
|
-
# @param [Symbol,String,Array<Integer>...]
|
243
|
+
# @param prompt [String] Prompt string. Defaults to `"Proceed?"`.
|
244
|
+
# @param styles [Symbol,String,Array<Integer>...] Styles to apply to the
|
243
245
|
# prompt.
|
244
|
-
# @param [Boolean,nil]
|
246
|
+
# @param default [Boolean,nil] Default value, or `nil` for no default.
|
245
247
|
# Uses `nil` if not specified.
|
246
248
|
# @return [Boolean]
|
247
249
|
#
|
@@ -262,6 +264,9 @@ module Toys
|
|
262
264
|
raise TerminalError, "Cannot confirm because the input stream is at eof."
|
263
265
|
end
|
264
266
|
if !resp.strip.empty? || default.nil?
|
267
|
+
if input.nil?
|
268
|
+
raise TerminalError, "Cannot confirm because there is no input stream."
|
269
|
+
end
|
265
270
|
confirm('Please answer "y" or "n"', default: default)
|
266
271
|
else
|
267
272
|
default
|
@@ -273,17 +278,18 @@ module Toys
|
|
273
278
|
# performs the long-running task. While the block is executing, a
|
274
279
|
# spinner will be displayed.
|
275
280
|
#
|
276
|
-
# @param [String]
|
281
|
+
# @param leading_text [String] Optional leading string to display to the
|
277
282
|
# left of the spinner. Default is the empty string.
|
278
|
-
# @param [Float]
|
283
|
+
# @param frame_length [Float] Length of a single frame, in seconds.
|
279
284
|
# Defaults to {DEFAULT_SPINNER_FRAME_LENGTH}.
|
280
|
-
# @param [Array<String>]
|
285
|
+
# @param frames [Array<String>] An array of frames. Defaults to
|
281
286
|
# {DEFAULT_SPINNER_FRAMES}.
|
282
|
-
# @param [Symbol,Array<Symbol>]
|
287
|
+
# @param style [Symbol,Array<Symbol>] A terminal style or array of styles
|
283
288
|
# to apply to all frames in the spinner. Defaults to empty,
|
284
|
-
# @param [String]
|
289
|
+
# @param final_text [String] Optional final string to display when the
|
285
290
|
# spinner is complete. Default is the empty string. A common practice
|
286
291
|
# is to set this to newline.
|
292
|
+
# @return [Object] The return value of the block.
|
287
293
|
#
|
288
294
|
def spinner(leading_text: "", final_text: "",
|
289
295
|
frame_length: nil, frames: nil, style: nil)
|
@@ -338,8 +344,9 @@ module Toys
|
|
338
344
|
# The definition of a style may include any valid style specification,
|
339
345
|
# including the symbol names of existing defined styles.
|
340
346
|
#
|
341
|
-
# @param [Symbol]
|
342
|
-
# @param [Symbol,String,Array<Integer>...]
|
347
|
+
# @param name [Symbol] The name for the style
|
348
|
+
# @param styles [Symbol,String,Array<Integer>...]
|
349
|
+
# @return [self]
|
343
350
|
#
|
344
351
|
def define_style(name, *styles)
|
345
352
|
@named_styles[name] = resolve_styles(*styles)
|
@@ -352,8 +359,8 @@ module Toys
|
|
352
359
|
# add any ANSI style codes and in fact removes any existing codes. If
|
353
360
|
# styles were added, ensures that the string ends with a clear code.
|
354
361
|
#
|
355
|
-
# @param [String]
|
356
|
-
# @param [Symbol,String,Array<Integer>...]
|
362
|
+
# @param str [String] String to style
|
363
|
+
# @param styles [Symbol,String,Array<Integer>...] Styles to apply
|
357
364
|
# @return [String] The styled string
|
358
365
|
#
|
359
366
|
def apply_styles(str, *styles)
|
@@ -409,7 +416,7 @@ module Toys
|
|
409
416
|
rgb = style.to_i(16)
|
410
417
|
[38, 2, (rgb >> 8) * 0x11, ((rgb & 0xf0) >> 4) * 0x11, (rgb & 0xf) * 0x11]
|
411
418
|
when /^\e\[([\d;]+)m$/
|
412
|
-
|
419
|
+
::Regexp.last_match(1).split(";").map(&:to_i)
|
413
420
|
end
|
414
421
|
end
|
415
422
|
|
@@ -0,0 +1,162 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright 2019 Daniel Azuma
|
4
|
+
#
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
# of this software and associated documentation files (the "Software"), to deal
|
7
|
+
# in the Software without restriction, including without limitation the rights
|
8
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
# copies of the Software, and to permit persons to whom the Software is
|
10
|
+
# furnished to do so, subject to the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be included in
|
13
|
+
# all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
20
|
+
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
21
|
+
# IN THE SOFTWARE.
|
22
|
+
;
|
23
|
+
|
24
|
+
module Toys
|
25
|
+
##
|
26
|
+
# A string intended for word-wrapped display.
|
27
|
+
#
|
28
|
+
class WrappableString
|
29
|
+
##
|
30
|
+
# Create a wrapped string.
|
31
|
+
# @param string [String,Array<String>] The string or array of string
|
32
|
+
# fragments
|
33
|
+
#
|
34
|
+
def initialize(string = "")
|
35
|
+
@fragments = string.is_a?(::Array) ? string.map(&:to_s) : string.to_s.split
|
36
|
+
end
|
37
|
+
|
38
|
+
##
|
39
|
+
# Returns the string fragments, i.e. the individual "words" for wrapping.
|
40
|
+
#
|
41
|
+
# @return [Array<String>]
|
42
|
+
#
|
43
|
+
attr_reader :fragments
|
44
|
+
|
45
|
+
##
|
46
|
+
# Returns a new WrappaableString whose content is the concatenation of this
|
47
|
+
# WrappableString with another WrappableString.
|
48
|
+
#
|
49
|
+
# @param other [WrappableString]
|
50
|
+
# @return [WrappableString]
|
51
|
+
#
|
52
|
+
def +(other)
|
53
|
+
other = WrappableString.new(other) unless other.is_a?(WrappableString)
|
54
|
+
WrappableString.new(fragments + other.fragments)
|
55
|
+
end
|
56
|
+
|
57
|
+
##
|
58
|
+
# Returns true if the string is empty (i.e. has no fragments)
|
59
|
+
# @return [Boolean]
|
60
|
+
#
|
61
|
+
def empty?
|
62
|
+
@fragments.empty?
|
63
|
+
end
|
64
|
+
|
65
|
+
##
|
66
|
+
# Returns the string without any wrapping
|
67
|
+
# @return [String]
|
68
|
+
#
|
69
|
+
def string
|
70
|
+
@fragments.join(" ")
|
71
|
+
end
|
72
|
+
alias to_s string
|
73
|
+
|
74
|
+
## @private
|
75
|
+
def ==(other)
|
76
|
+
return false unless other.is_a?(WrappableString)
|
77
|
+
other.fragments == fragments
|
78
|
+
end
|
79
|
+
alias eql? ==
|
80
|
+
|
81
|
+
## @private
|
82
|
+
def hash
|
83
|
+
fragments.hash
|
84
|
+
end
|
85
|
+
|
86
|
+
##
|
87
|
+
# Wraps the string to the given width.
|
88
|
+
#
|
89
|
+
# @param width [Integer,nil] Width in characters, or `nil` for infinite.
|
90
|
+
# @param width2 [Integer,nil] Width in characters for the second and
|
91
|
+
# subsequent lines, or `nil` to use the same as width.
|
92
|
+
#
|
93
|
+
# @return [Array<String>] Wrapped lines
|
94
|
+
#
|
95
|
+
def wrap(width, width2 = nil)
|
96
|
+
lines = []
|
97
|
+
line = ""
|
98
|
+
line_len = 0
|
99
|
+
fragments.each do |frag|
|
100
|
+
frag_len = frag.gsub(/\e\[\d+(;\d+)*m/, "").size
|
101
|
+
if line_len.zero?
|
102
|
+
line = frag
|
103
|
+
line_len = frag_len
|
104
|
+
elsif width && line_len + 1 + frag_len > width
|
105
|
+
lines << line
|
106
|
+
line = frag
|
107
|
+
line_len = frag_len
|
108
|
+
width = width2 if width2
|
109
|
+
else
|
110
|
+
line_len += frag_len + 1
|
111
|
+
line = "#{line} #{frag}"
|
112
|
+
end
|
113
|
+
end
|
114
|
+
lines << line if line_len.positive?
|
115
|
+
lines
|
116
|
+
end
|
117
|
+
|
118
|
+
##
|
119
|
+
# Wraps an array of lines to the given width.
|
120
|
+
#
|
121
|
+
# @param strs [Array<WrappableString>] Array of strings to wrap.
|
122
|
+
# @param width [Integer,nil] Width in characters, or `nil` for infinite.
|
123
|
+
# @param width2 [Integer,nil] Width in characters for the second and
|
124
|
+
# subsequent lines, or `nil` to use the same as width.
|
125
|
+
#
|
126
|
+
# @return [Array<String>] Wrapped lines
|
127
|
+
#
|
128
|
+
def self.wrap_lines(strs, width, width2 = nil)
|
129
|
+
result = Array(strs).map do |s|
|
130
|
+
s = make(s)
|
131
|
+
lines = s.empty? ? [""] : s.wrap(width, width2)
|
132
|
+
width = width2 if width2
|
133
|
+
lines
|
134
|
+
end.flatten
|
135
|
+
result = [] if result.all?(&:empty?)
|
136
|
+
result
|
137
|
+
end
|
138
|
+
|
139
|
+
##
|
140
|
+
# Make the given object a WrappableString.
|
141
|
+
# If the object is already a WrappableString, return it. Otherwise,
|
142
|
+
# treat it as a string or an array of strings and wrap it in a
|
143
|
+
# WrappableString.
|
144
|
+
#
|
145
|
+
# @param obj [Toys::WrappableString,String,Array<String>]
|
146
|
+
# @return [Toys::WrappableString]
|
147
|
+
#
|
148
|
+
def self.make(obj)
|
149
|
+
obj.is_a?(WrappableString) ? obj : WrappableString.new(obj)
|
150
|
+
end
|
151
|
+
|
152
|
+
##
|
153
|
+
# Make the given object an array of WrappableString.
|
154
|
+
#
|
155
|
+
# @param objs [Array<Toys::WrappableString,String,Array<String>>]
|
156
|
+
# @return [Array<Toys::WrappableString>]
|
157
|
+
#
|
158
|
+
def self.make_array(objs)
|
159
|
+
Array(objs).map { |obj| make(obj) }
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: toys-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Azuma
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-06-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: highline
|
@@ -86,30 +86,30 @@ dependencies:
|
|
86
86
|
requirements:
|
87
87
|
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: 0.
|
89
|
+
version: 0.71.0
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: 0.
|
96
|
+
version: 0.71.0
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: yard
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
101
|
- - "~>"
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: 0.9.
|
103
|
+
version: 0.9.19
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: 0.9.
|
110
|
+
version: 0.9.19
|
111
111
|
description: Toys-Core is the command line tool framework underlying Toys. It can
|
112
|
-
be used to create command line
|
112
|
+
be used to create command line executables using the internal Toys APIs.
|
113
113
|
email:
|
114
114
|
- dazuma@gmail.com
|
115
115
|
executables: []
|
@@ -122,26 +122,28 @@ files:
|
|
122
122
|
- README.md
|
123
123
|
- docs/guide.md
|
124
124
|
- lib/toys-core.rb
|
125
|
+
- lib/toys/acceptor.rb
|
126
|
+
- lib/toys/alias.rb
|
127
|
+
- lib/toys/arg_parser.rb
|
125
128
|
- lib/toys/cli.rb
|
129
|
+
- lib/toys/compat.rb
|
130
|
+
- lib/toys/completion.rb
|
131
|
+
- lib/toys/context.rb
|
126
132
|
- lib/toys/core_version.rb
|
127
|
-
- lib/toys/definition/acceptor.rb
|
128
|
-
- lib/toys/definition/alias.rb
|
129
|
-
- lib/toys/definition/arg.rb
|
130
|
-
- lib/toys/definition/flag.rb
|
131
|
-
- lib/toys/definition/flag_group.rb
|
132
|
-
- lib/toys/definition/source_info.rb
|
133
|
-
- lib/toys/definition/tool.rb
|
134
|
-
- lib/toys/dsl/arg.rb
|
135
133
|
- lib/toys/dsl/flag.rb
|
136
134
|
- lib/toys/dsl/flag_group.rb
|
135
|
+
- lib/toys/dsl/positional_arg.rb
|
137
136
|
- lib/toys/dsl/tool.rb
|
138
137
|
- lib/toys/errors.rb
|
138
|
+
- lib/toys/flag.rb
|
139
|
+
- lib/toys/flag_group.rb
|
139
140
|
- lib/toys/input_file.rb
|
140
141
|
- lib/toys/loader.rb
|
141
142
|
- lib/toys/middleware.rb
|
142
143
|
- lib/toys/mixin.rb
|
143
|
-
- lib/toys/
|
144
|
-
- lib/toys/
|
144
|
+
- lib/toys/module_lookup.rb
|
145
|
+
- lib/toys/positional_arg.rb
|
146
|
+
- lib/toys/source_info.rb
|
145
147
|
- lib/toys/standard_middleware/add_verbosity_flags.rb
|
146
148
|
- lib/toys/standard_middleware/handle_usage_errors.rb
|
147
149
|
- lib/toys/standard_middleware/set_default_descriptions.rb
|
@@ -154,15 +156,15 @@ files:
|
|
154
156
|
- lib/toys/standard_mixins/terminal.rb
|
155
157
|
- lib/toys/template.rb
|
156
158
|
- lib/toys/tool.rb
|
159
|
+
- lib/toys/utils/completion_engine.rb
|
157
160
|
- lib/toys/utils/exec.rb
|
158
161
|
- lib/toys/utils/gems.rb
|
159
162
|
- lib/toys/utils/help_text.rb
|
160
|
-
- lib/toys/utils/module_lookup.rb
|
161
163
|
- lib/toys/utils/terminal.rb
|
162
|
-
- lib/toys/
|
164
|
+
- lib/toys/wrappable_string.rb
|
163
165
|
homepage: https://github.com/dazuma/toys
|
164
166
|
licenses:
|
165
|
-
-
|
167
|
+
- MIT
|
166
168
|
metadata:
|
167
169
|
changelog_uri: https://github.com/dazuma/toys/blob/master/toys-core/CHANGELOG.md
|
168
170
|
source_code_uri: https://github.com/dazuma/toys
|
@@ -183,8 +185,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
183
185
|
- !ruby/object:Gem::Version
|
184
186
|
version: '0'
|
185
187
|
requirements: []
|
186
|
-
rubygems_version: 3.0.
|
188
|
+
rubygems_version: 3.0.3
|
187
189
|
signing_key:
|
188
190
|
specification_version: 4
|
189
|
-
summary: Framework for creating command line
|
191
|
+
summary: Framework for creating command line executables
|
190
192
|
test_files: []
|