toys-core 0.4.1 → 0.4.2
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 +5 -0
- data/lib/toys/core_version.rb +1 -1
- data/lib/toys/dsl/arg.rb +8 -0
- data/lib/toys/dsl/flag.rb +10 -0
- data/lib/toys/dsl/tool.rb +60 -12
- data/lib/toys/standard_mixins/terminal.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 55fb96e74b22786912b754dbd969e5ead0825afe8ac8182f3a0b06520a46b867
|
4
|
+
data.tar.gz: e85f258b34362a5ab66f47115805898807432560680bd6bde074b25979caa9cd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 408586c952bc613bed26f549883e39fecc49cca4c298bdd22b40fe44a365c2fe23bae0016622a54ddfeb69cf7b72357310183fc8bd56e4614e476480de9527a6
|
7
|
+
data.tar.gz: 0afaf0c2a723277074e0b772b8166db55b5bc2d8f86150bd2a9367f5254ee770f9c82d09ef98d38c444b269ade5a59857b145f086609efb5bdc4176457ccc5c7
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
# Release History
|
2
2
|
|
3
|
+
### 0.4.2 / 2018-07-08
|
4
|
+
|
5
|
+
* FIXED: Raise an error rather than cause unexpected behavior if a mixin is included twice.
|
6
|
+
* IMPROVED: The `include?` method extended to support mixin names in a tool dsl.
|
7
|
+
|
3
8
|
### 0.4.1 / 2018-07-03
|
4
9
|
|
5
10
|
* FIXED: Terminal#confirm uppercased "N" for the wrong default.
|
data/lib/toys/core_version.rb
CHANGED
data/lib/toys/dsl/arg.rb
CHANGED
@@ -51,7 +51,9 @@ module Toys
|
|
51
51
|
|
52
52
|
##
|
53
53
|
# Set the OptionParser acceptor.
|
54
|
+
#
|
54
55
|
# @param [Object] accept
|
56
|
+
# @return [Toys::DSL::Tool] self, for chaining.
|
55
57
|
#
|
56
58
|
def accept(accept)
|
57
59
|
@accept = accept
|
@@ -60,7 +62,9 @@ module Toys
|
|
60
62
|
|
61
63
|
##
|
62
64
|
# Set the default value.
|
65
|
+
#
|
63
66
|
# @param [Object] default
|
67
|
+
# @return [Toys::DSL::Tool] self, for chaining.
|
64
68
|
#
|
65
69
|
def default(default)
|
66
70
|
@default = default
|
@@ -69,7 +73,9 @@ module Toys
|
|
69
73
|
|
70
74
|
##
|
71
75
|
# Set the name of this arg as it appears in help screens.
|
76
|
+
#
|
72
77
|
# @param [String] display_name
|
78
|
+
# @return [Toys::DSL::Tool] self, for chaining.
|
73
79
|
#
|
74
80
|
def display_name(display_name)
|
75
81
|
@display_name = display_name
|
@@ -81,6 +87,7 @@ module Toys
|
|
81
87
|
# formats.
|
82
88
|
#
|
83
89
|
# @param [String,Array<String>,Toys::Utils::WrappableString] desc
|
90
|
+
# @return [Toys::DSL::Tool] self, for chaining.
|
84
91
|
#
|
85
92
|
def desc(desc)
|
86
93
|
@desc = desc
|
@@ -93,6 +100,7 @@ module Toys
|
|
93
100
|
# allowed formats.
|
94
101
|
#
|
95
102
|
# @param [String,Array<String>,Toys::Utils::WrappableString...] long_desc
|
103
|
+
# @return [Toys::DSL::Tool] self, for chaining.
|
96
104
|
#
|
97
105
|
def long_desc(*long_desc)
|
98
106
|
@long_desc += long_desc
|
data/lib/toys/dsl/flag.rb
CHANGED
@@ -53,7 +53,9 @@ module Toys
|
|
53
53
|
##
|
54
54
|
# Add flags in OptionParser format. This may be called multiple times,
|
55
55
|
# and the results are cumulative.
|
56
|
+
#
|
56
57
|
# @param [String...] flags
|
58
|
+
# @return [Toys::DSL::Tool] self, for chaining.
|
57
59
|
#
|
58
60
|
def flags(*flags)
|
59
61
|
@flags += flags
|
@@ -62,7 +64,9 @@ module Toys
|
|
62
64
|
|
63
65
|
##
|
64
66
|
# Set the OptionParser acceptor.
|
67
|
+
#
|
65
68
|
# @param [Object] accept
|
69
|
+
# @return [Toys::DSL::Tool] self, for chaining.
|
66
70
|
#
|
67
71
|
def accept(accept)
|
68
72
|
@accept = accept
|
@@ -71,7 +75,9 @@ module Toys
|
|
71
75
|
|
72
76
|
##
|
73
77
|
# Set the default value.
|
78
|
+
#
|
74
79
|
# @param [Object] default
|
80
|
+
# @return [Toys::DSL::Tool] self, for chaining.
|
75
81
|
#
|
76
82
|
def default(default)
|
77
83
|
@default = default
|
@@ -86,6 +92,7 @@ module Toys
|
|
86
92
|
# responding to the `call` method) or you may pass a block.
|
87
93
|
#
|
88
94
|
# @param [Proc] handler
|
95
|
+
# @return [Toys::DSL::Tool] self, for chaining.
|
89
96
|
#
|
90
97
|
def handler(handler = nil, &block)
|
91
98
|
@handler = handler || block
|
@@ -97,6 +104,7 @@ module Toys
|
|
97
104
|
# already in use or marked as disabled.
|
98
105
|
#
|
99
106
|
# @param [Boolean] setting
|
107
|
+
# @return [Toys::DSL::Tool] self, for chaining.
|
100
108
|
#
|
101
109
|
def report_collisions(setting)
|
102
110
|
@report_collisions = setting
|
@@ -108,6 +116,7 @@ module Toys
|
|
108
116
|
# formats.
|
109
117
|
#
|
110
118
|
# @param [String,Array<String>,Toys::Utils::WrappableString] desc
|
119
|
+
# @return [Toys::DSL::Tool] self, for chaining.
|
111
120
|
#
|
112
121
|
def desc(desc)
|
113
122
|
@desc = desc
|
@@ -120,6 +129,7 @@ module Toys
|
|
120
129
|
# allowed formats.
|
121
130
|
#
|
122
131
|
# @param [String,Array<String>,Toys::Utils::WrappableString...] long_desc
|
132
|
+
# @return [Toys::DSL::Tool] self, for chaining.
|
123
133
|
#
|
124
134
|
def long_desc(*long_desc)
|
125
135
|
@long_desc += long_desc
|
data/lib/toys/dsl/tool.rb
CHANGED
@@ -108,6 +108,7 @@ module Toys
|
|
108
108
|
# @param [String] name The acceptor name.
|
109
109
|
# @param [Regexp,Array,nil] validator The validator.
|
110
110
|
# @param [Proc,nil] converter The validator.
|
111
|
+
# @return [Toys::DSL::Tool] self, for chaining.
|
111
112
|
#
|
112
113
|
def acceptor(name, validator = nil, converter = nil, &block)
|
113
114
|
cur_tool = DSL::Tool.current_tool(self, false)
|
@@ -134,6 +135,7 @@ module Toys
|
|
134
135
|
# You should pass a block and define methods in that block.
|
135
136
|
#
|
136
137
|
# @param [String] name Name of the mixin
|
138
|
+
# @return [Toys::DSL::Tool] self, for chaining.
|
137
139
|
#
|
138
140
|
def mixin(name, &block)
|
139
141
|
cur_tool = DSL::Tool.current_tool(self, false)
|
@@ -158,6 +160,7 @@ module Toys
|
|
158
160
|
# define how to expand the template.
|
159
161
|
#
|
160
162
|
# @param [String] name Name of the template
|
163
|
+
# @return [Toys::DSL::Tool] self, for chaining.
|
161
164
|
#
|
162
165
|
def template(name, &block)
|
163
166
|
cur_tool = DSL::Tool.current_tool(self, false)
|
@@ -178,6 +181,7 @@ module Toys
|
|
178
181
|
# old definition is discarded and replaced with the new definition.
|
179
182
|
#
|
180
183
|
# @param [String] word The name of the subtool
|
184
|
+
# @return [Toys::DSL::Tool] self, for chaining.
|
181
185
|
#
|
182
186
|
def tool(word, &block)
|
183
187
|
word = word.to_s
|
@@ -196,6 +200,7 @@ module Toys
|
|
196
200
|
#
|
197
201
|
# @param [String] word The name of the alias
|
198
202
|
# @param [String] target The target of the alias
|
203
|
+
# @return [Toys::DSL::Tool] self, for chaining.
|
199
204
|
#
|
200
205
|
def alias_tool(word, target)
|
201
206
|
@__loader.make_alias(@__words + [word.to_s], @__words + [target.to_s], @__priority)
|
@@ -203,9 +208,11 @@ module Toys
|
|
203
208
|
end
|
204
209
|
|
205
210
|
##
|
206
|
-
#
|
211
|
+
# Load another config file or directory, as if its contents were inserted
|
212
|
+
# at the current location.
|
207
213
|
#
|
208
|
-
# @param [String] path The file or directory to
|
214
|
+
# @param [String] path The file or directory to load.
|
215
|
+
# @return [Toys::DSL::Tool] self, for chaining.
|
209
216
|
#
|
210
217
|
def load(path)
|
211
218
|
@__loader.load_path(path, @__words, @__remaining_words, @__priority)
|
@@ -221,6 +228,7 @@ module Toys
|
|
221
228
|
# @param [Class,String,Symbol] template_class The template, either as a
|
222
229
|
# class or a well-known name.
|
223
230
|
# @param [Object...] args Template arguments
|
231
|
+
# @return [Toys::DSL::Tool] self, for chaining.
|
224
232
|
#
|
225
233
|
def expand(template_class, *args)
|
226
234
|
cur_tool = DSL::Tool.current_tool(self, true)
|
@@ -268,6 +276,7 @@ module Toys
|
|
268
276
|
# desc ["This sentence will not be wrapped."]
|
269
277
|
#
|
270
278
|
# @param [Toys::Utils::WrappableString,String,Array<String>] str
|
279
|
+
# @return [Toys::DSL::Tool] self, for chaining.
|
271
280
|
#
|
272
281
|
def desc(str)
|
273
282
|
cur_tool = DSL::Tool.current_tool(self, true)
|
@@ -294,6 +303,7 @@ module Toys
|
|
294
303
|
# ["This line will not be wrapped."]
|
295
304
|
#
|
296
305
|
# @param [Toys::Utils::WrappableString,String,Array<String>...] strs
|
306
|
+
# @return [Toys::DSL::Tool] self, for chaining.
|
297
307
|
#
|
298
308
|
def long_desc(*strs)
|
299
309
|
DSL::Tool.current_tool(self, true)&.append_long_desc(strs)
|
@@ -342,6 +352,7 @@ module Toys
|
|
342
352
|
# arguments.) Defaults to the empty array.
|
343
353
|
# @yieldparam flag_dsl [Toys::DSL::Flag] An object that lets you
|
344
354
|
# configure this flag in a block.
|
355
|
+
# @return [Toys::DSL::Tool] self, for chaining.
|
345
356
|
#
|
346
357
|
def flag(key, *flags,
|
347
358
|
accept: nil, default: nil, handler: nil,
|
@@ -390,6 +401,7 @@ module Toys
|
|
390
401
|
# arguments.) Defaults to the empty array.
|
391
402
|
# @yieldparam arg_dsl [Toys::DSL::Arg] An object that lets you configure
|
392
403
|
# this argument in a block.
|
404
|
+
# @return [Toys::DSL::Tool] self, for chaining.
|
393
405
|
#
|
394
406
|
def required_arg(key,
|
395
407
|
accept: nil, display_name: nil,
|
@@ -441,6 +453,7 @@ module Toys
|
|
441
453
|
# arguments.) Defaults to the empty array.
|
442
454
|
# @yieldparam arg_dsl [Toys::DSL::Arg] An object that lets you configure
|
443
455
|
# this argument in a block.
|
456
|
+
# @return [Toys::DSL::Tool] self, for chaining.
|
444
457
|
#
|
445
458
|
def optional_arg(key,
|
446
459
|
default: nil, accept: nil, display_name: nil,
|
@@ -491,6 +504,7 @@ module Toys
|
|
491
504
|
# arguments.) Defaults to the empty array.
|
492
505
|
# @yieldparam arg_dsl [Toys::DSL::Arg] An object that lets you configure
|
493
506
|
# this argument in a block.
|
507
|
+
# @return [Toys::DSL::Tool] self, for chaining.
|
494
508
|
#
|
495
509
|
def remaining_args(key,
|
496
510
|
default: [], accept: nil, display_name: nil,
|
@@ -517,6 +531,7 @@ module Toys
|
|
517
531
|
# @param [String,Symbol] key The key to use to retrieve the value from
|
518
532
|
# the execution context.
|
519
533
|
# @param [Object] value The value to set.
|
534
|
+
# @return [Toys::DSL::Tool] self, for chaining.
|
520
535
|
#
|
521
536
|
def static(key, value = nil)
|
522
537
|
cur_tool = DSL::Tool.current_tool(self, true)
|
@@ -541,6 +556,8 @@ module Toys
|
|
541
556
|
# This directive is mutually exclusive with any of the directives that
|
542
557
|
# declare arguments or flags.
|
543
558
|
#
|
559
|
+
# @return [Toys::DSL::Tool] self, for chaining.
|
560
|
+
#
|
544
561
|
def disable_argument_parsing
|
545
562
|
DSL::Tool.current_tool(self, true)&.disable_argument_parsing
|
546
563
|
self
|
@@ -552,6 +569,7 @@ module Toys
|
|
552
569
|
# defining a particular flag.
|
553
570
|
#
|
554
571
|
# @param [String...] flags The flags to disable
|
572
|
+
# @return [Toys::DSL::Tool] self, for chaining.
|
555
573
|
#
|
556
574
|
def disable_flag(*flags)
|
557
575
|
DSL::Tool.current_tool(self, true)&.disable_flag(*flags)
|
@@ -559,8 +577,12 @@ module Toys
|
|
559
577
|
end
|
560
578
|
|
561
579
|
##
|
562
|
-
# Specify how to run this tool.
|
563
|
-
#
|
580
|
+
# Specify how to run this tool. Typically you do this by defining a
|
581
|
+
# method namd `run`. Alternatively, you can pass a block to this method.
|
582
|
+
# You may want to do this if your method needs access to local variables
|
583
|
+
# in the lexical scope.
|
584
|
+
#
|
585
|
+
# @return [Toys::DSL::Tool] self, for chaining.
|
564
586
|
#
|
565
587
|
def to_run(&block)
|
566
588
|
define_method(:run, &block)
|
@@ -581,14 +603,9 @@ module Toys
|
|
581
603
|
def include(mod, *args)
|
582
604
|
cur_tool = DSL::Tool.current_tool(self, true)
|
583
605
|
return if cur_tool.nil?
|
584
|
-
|
585
|
-
if
|
586
|
-
|
587
|
-
elsif mod.is_a?(::Symbol)
|
588
|
-
mod = @__loader.resolve_standard_mixin(name)
|
589
|
-
end
|
590
|
-
if mod.nil?
|
591
|
-
raise ToolDefinitionError, "Module not found: #{name.inspect}"
|
606
|
+
mod = DSL::Tool.resolve_mixin(mod, cur_tool, @__loader)
|
607
|
+
if included_modules.include?(mod)
|
608
|
+
raise ToolDefinitionError, "Mixin already included: #{mod.name}"
|
592
609
|
end
|
593
610
|
if mod.respond_to?(:initialization_callback) && mod.initialization_callback
|
594
611
|
cur_tool.add_initializer(mod.initialization_callback, *args)
|
@@ -599,6 +616,23 @@ module Toys
|
|
599
616
|
super(mod)
|
600
617
|
end
|
601
618
|
|
619
|
+
##
|
620
|
+
# Determine if the given module/mixin has already been included.
|
621
|
+
#
|
622
|
+
# You may provide either a module, the string name of a mixin that you
|
623
|
+
# have defined in this tool or one of its ancestors, or the symbol name
|
624
|
+
# of a well-known mixin.
|
625
|
+
#
|
626
|
+
# @param [Module,Symbol,String] mod Module or module name.
|
627
|
+
# @return [Boolean,nil] A boolean value, or `nil` if the current tool
|
628
|
+
# is not active.
|
629
|
+
#
|
630
|
+
def include?(mod)
|
631
|
+
cur_tool = DSL::Tool.current_tool(self, false)
|
632
|
+
return if cur_tool.nil?
|
633
|
+
super(DSL::Tool.resolve_mixin(mod, cur_tool, @__loader))
|
634
|
+
end
|
635
|
+
|
602
636
|
## @private
|
603
637
|
def self.new_class(words, priority, loader)
|
604
638
|
tool_class = ::Class.new(::Toys::Tool)
|
@@ -657,6 +691,20 @@ module Toys
|
|
657
691
|
end
|
658
692
|
end
|
659
693
|
end
|
694
|
+
|
695
|
+
## @private
|
696
|
+
def self.resolve_mixin(mod, cur_tool, loader)
|
697
|
+
name = mod.to_s
|
698
|
+
if mod.is_a?(::String)
|
699
|
+
mod = cur_tool.resolve_mixin(mod)
|
700
|
+
elsif mod.is_a?(::Symbol)
|
701
|
+
mod = loader.resolve_standard_mixin(name)
|
702
|
+
end
|
703
|
+
unless mod.is_a?(::Module)
|
704
|
+
raise ToolDefinitionError, "Module not found: #{name.inspect}"
|
705
|
+
end
|
706
|
+
mod
|
707
|
+
end
|
660
708
|
end
|
661
709
|
end
|
662
710
|
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.
|
4
|
+
version: 0.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Azuma
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-07-
|
11
|
+
date: 2018-07-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: highline
|