everyday_thor_util 1.5.3 → 2.0.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/everyday_thor_util.gemspec +2 -2
- data/lib/everyday_thor_util/builder.rb +289 -0
- data/lib/everyday_thor_util/version.rb +1 -1
- metadata +8 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8a69cb484c769ea7cb788e188a59bb7f2ba91d7f
|
4
|
+
data.tar.gz: fb3f7d13eebee965f138a8d2993181e9b61102e9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0c9a7017f4f78ac7558c79f378a434450b00dbbeaf58d766b70ff29fdd7c0bf029a9c4ff055b670fa6fed1314dbe220a481a8a2f506dea98ab72f3e26efd6fed
|
7
|
+
data.tar.gz: 7004a9d355ee3c1e7e5602ca698d779a3395965db5f8c4c166e16b57372a23dd73ef92b8703a15ae0fda935e3822e65848d5d91d750e02ba63b7f1325abae34a
|
data/everyday_thor_util.gemspec
CHANGED
@@ -20,8 +20,8 @@ Gem::Specification.new do |spec|
|
|
20
20
|
|
21
21
|
spec.required_ruby_version = '>= 1.9.3'
|
22
22
|
|
23
|
-
spec.add_development_dependency 'bundler', '~> 1.
|
24
|
-
spec.add_development_dependency 'rake', '~> 10.
|
23
|
+
spec.add_development_dependency 'bundler', '~> 1.7'
|
24
|
+
spec.add_development_dependency 'rake', '~> 10.4'
|
25
25
|
|
26
26
|
spec.add_dependency 'everyday-plugins', '~> 1.2'
|
27
27
|
spec.add_dependency 'thor', '~> 0.19'
|
@@ -0,0 +1,289 @@
|
|
1
|
+
require 'everyday_thor_util/thor-fix'
|
2
|
+
|
3
|
+
class Module
|
4
|
+
def create_method(name, &block)
|
5
|
+
self.send(:define_method, name, &block)
|
6
|
+
end
|
7
|
+
|
8
|
+
def dup_method(new_name, old_name)
|
9
|
+
self.send(:alias_method, new_name, old_name)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
module EverydayThorUtil
|
14
|
+
module BuilderBuildItems
|
15
|
+
class BuilderCommand
|
16
|
+
def initialize(parent = nil, options = {}, &block)
|
17
|
+
@aliases = options.delete(:aliases) if options.has_key?(:aliases) && !parent.nil?
|
18
|
+
@parent = parent
|
19
|
+
@options = options
|
20
|
+
@body = block
|
21
|
+
end
|
22
|
+
|
23
|
+
def parent
|
24
|
+
@parent
|
25
|
+
end
|
26
|
+
|
27
|
+
def body
|
28
|
+
@body
|
29
|
+
end
|
30
|
+
|
31
|
+
def options
|
32
|
+
@options
|
33
|
+
end
|
34
|
+
|
35
|
+
def define(&block)
|
36
|
+
block.call(self.commands, self.flags, self.helpers)
|
37
|
+
end
|
38
|
+
|
39
|
+
def aliases
|
40
|
+
@aliases ||= []
|
41
|
+
end
|
42
|
+
|
43
|
+
def commands
|
44
|
+
@commands ||= EverydayThorUtil::BuilderBuildLists::BuilderCommands.new(self)
|
45
|
+
end
|
46
|
+
|
47
|
+
def flags
|
48
|
+
@flags ||= EverydayThorUtil::BuilderBuildLists::BuilderFlags.new(self)
|
49
|
+
end
|
50
|
+
|
51
|
+
def helpers
|
52
|
+
@helpers ||= EverydayThorUtil::BuilderBuildLists::BuilderHelpers.new(self)
|
53
|
+
end
|
54
|
+
|
55
|
+
def leaf?
|
56
|
+
self.commands.commands.empty? && self.helpers.helpers.empty?
|
57
|
+
end
|
58
|
+
|
59
|
+
def [](name)
|
60
|
+
if self.commands.has_key?(name)
|
61
|
+
self.commands[name]
|
62
|
+
elsif self.helpers.has_key?(name)
|
63
|
+
self.helpers[name]
|
64
|
+
elsif self.flags.has_key?(name)
|
65
|
+
self.flags[name]
|
66
|
+
else
|
67
|
+
nil
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def []=(name, obj)
|
72
|
+
if obj.is_a?(Hash)
|
73
|
+
self.flags[name] = obj
|
74
|
+
elsif obj.is_a?(BuilderCommand)
|
75
|
+
self.commands[name] = obj
|
76
|
+
elsif obj.is_a?(Proc)
|
77
|
+
self.helpers[name] = obj
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
class BuilderGlobal
|
82
|
+
def helpers
|
83
|
+
@helpers ||= EverydayThorUtil::BuilderBuildLists::BuilderHelpers.new(self)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
module BuilderBuildLists
|
88
|
+
class BuilderHelpers
|
89
|
+
def initialize(parent)
|
90
|
+
@parent = parent
|
91
|
+
@helpers = {}
|
92
|
+
end
|
93
|
+
|
94
|
+
def helpers
|
95
|
+
@helpers
|
96
|
+
end
|
97
|
+
|
98
|
+
def [](name)
|
99
|
+
@helpers[name.to_sym]
|
100
|
+
end
|
101
|
+
|
102
|
+
def []=(name, body)
|
103
|
+
if body.nil?
|
104
|
+
self.delete(name)
|
105
|
+
nil
|
106
|
+
else
|
107
|
+
@parent.commands.delete(name) if @parent.respond_to?(:commands) && @parent.commands.has_key?(name)
|
108
|
+
@helpers[name.to_sym] = body
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
def has_key?(name)
|
113
|
+
@helpers.has_key?(name.to_sym)
|
114
|
+
end
|
115
|
+
|
116
|
+
def delete(name)
|
117
|
+
@helpers.delete(name.to_sym)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
class BuilderFlags
|
121
|
+
def initialize(parent)
|
122
|
+
@parent = parent
|
123
|
+
@flags = {}
|
124
|
+
end
|
125
|
+
|
126
|
+
def flags
|
127
|
+
@flags
|
128
|
+
end
|
129
|
+
|
130
|
+
def [](name)
|
131
|
+
@flags[name.to_sym]
|
132
|
+
end
|
133
|
+
|
134
|
+
def []=(name, flag)
|
135
|
+
if flag.nil?
|
136
|
+
self.delete(name)
|
137
|
+
nil
|
138
|
+
else
|
139
|
+
@flags[name.to_sym] = flag
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
def has_key?(name)
|
144
|
+
@flags.has_key?(name.to_sym)
|
145
|
+
end
|
146
|
+
|
147
|
+
def delete(name)
|
148
|
+
@flags.delete(name.to_sym)
|
149
|
+
end
|
150
|
+
end
|
151
|
+
class BuilderCommands
|
152
|
+
def initialize(parent)
|
153
|
+
@parent = parent
|
154
|
+
@commands = {}
|
155
|
+
end
|
156
|
+
|
157
|
+
def commands
|
158
|
+
@commands
|
159
|
+
end
|
160
|
+
|
161
|
+
def [](name)
|
162
|
+
@commands[name.to_sym]
|
163
|
+
end
|
164
|
+
|
165
|
+
def []=(name, command)
|
166
|
+
if command.nil?
|
167
|
+
delete(name)
|
168
|
+
nil
|
169
|
+
else
|
170
|
+
@parent.helpers.delete(name) if @parent.helpers.has_key?(name)
|
171
|
+
@commands[name.to_sym] = EverydayThorUtil::BuilderBuildItems::BuilderCommand.new(@parent, command.options, &command.body)
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
def has_key?(name)
|
176
|
+
@commands.has_key?(name.to_sym)
|
177
|
+
end
|
178
|
+
|
179
|
+
def delete(name)
|
180
|
+
@commands.delete(name.to_sym)
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
184
|
+
module Builder
|
185
|
+
def global
|
186
|
+
@global ||= EverydayThorUtil::BuilderBuildItems::BuilderGlobal.new
|
187
|
+
end
|
188
|
+
|
189
|
+
def root_command
|
190
|
+
@root_command ||= EverydayThorUtil::BuilderBuildItems::BuilderCommand.new
|
191
|
+
end
|
192
|
+
|
193
|
+
def flag(opts = {})
|
194
|
+
opts
|
195
|
+
end
|
196
|
+
|
197
|
+
def command(options = {}, &block)
|
198
|
+
EverydayThorUtil::BuilderBuildItems::BuilderCommand.new(nil, options, &block)
|
199
|
+
end
|
200
|
+
|
201
|
+
def build!
|
202
|
+
rc = Class.new(Thor)
|
203
|
+
build_recurse(self.root_command, rc)
|
204
|
+
rc
|
205
|
+
end
|
206
|
+
|
207
|
+
def build_recurse(p, pc)
|
208
|
+
if p.parent.nil?
|
209
|
+
p.flags.flags.each { |fn, f| pc.class_option(fn.to_sym, f) }
|
210
|
+
self.global.helpers.helpers.each { |hn, h| pc.no_commands { pc.create_method(hn.to_sym, &h) } }
|
211
|
+
p.helpers.helpers.each { |hn, h| pc.no_commands { pc.create_method(hn.to_sym, &h) } }
|
212
|
+
end
|
213
|
+
p.commands.commands.each { |cn, c|
|
214
|
+
short_desc = c.options[:short_desc]
|
215
|
+
desc = c.options[:desc]
|
216
|
+
long_desc = c.options[:long_desc]
|
217
|
+
aliases = c.aliases
|
218
|
+
if !c.leaf?
|
219
|
+
cc = Class.new(Thor)
|
220
|
+
cc.namespace cn.to_s
|
221
|
+
self.global.helpers.helpers.each { |hn, h| cc.no_commands { cc.create_method(hn.to_sym, &h) } }
|
222
|
+
c.helpers.helpers.each { |hn, h| pc.no_commands { pc.create_method(hn.to_sym, &h) } }
|
223
|
+
c.flags.flags.each { |fn, f| cc.class_option(fn.to_sym, f) }
|
224
|
+
build_recurse(c, cc)
|
225
|
+
c.flags.flags.each { |fn, f| pc.class_option(fn.to_sym, f) }
|
226
|
+
pc.desc short_desc, desc if short_desc && desc
|
227
|
+
pc.long_desc long_desc if long_desc
|
228
|
+
pc.subcommand cn, cc
|
229
|
+
aliases.each { |an|
|
230
|
+
cc2 = Class.new(Thor)
|
231
|
+
cc2.namespace an
|
232
|
+
self.global.helpers.helpers.each { |hn, h| cc2.no_commands { cc2.create_method(hn.to_sym, &h) } }
|
233
|
+
c.helpers.helpers.each { |hn, h| pc.no_commands { pc.create_method(hn.to_sym, &h) } }
|
234
|
+
c.flags.flags.each { |fn, f| cc2.class_option(fn.to_sym, f) }
|
235
|
+
build_recurse(c, cc2)
|
236
|
+
c.flags.flags.each { |fn, f| pc.class_option(fn.to_sym, f) }
|
237
|
+
pc.desc short_desc.gsub(/^\S+(?=\s|$)/, an.gsub(/_/, '-')), desc if short_desc && desc
|
238
|
+
pc.long_desc long_desc if long_desc
|
239
|
+
pc.subcommand an, cc2
|
240
|
+
} if aliases && !aliases.empty?
|
241
|
+
elsif c.body
|
242
|
+
c.flags.flags.each { |fn, f| pc.class_option(fn.to_sym, f) }
|
243
|
+
pc.desc short_desc, desc if short_desc && desc
|
244
|
+
pc.long_desc long_desc if long_desc
|
245
|
+
pc.create_method(cn.to_sym, &c.body)
|
246
|
+
aliases.each { |an|
|
247
|
+
c.flags.flags.each { |fn, f| pc.class_option(fn.to_sym, f) }
|
248
|
+
pc.desc short_desc.gsub(/^\S+(?=\s|$)/, an.gsub(/_/, '-')), desc if short_desc && desc
|
249
|
+
pc.long_desc long_desc if long_desc
|
250
|
+
pc.dup_method an.to_sym, cn.to_sym
|
251
|
+
} if aliases
|
252
|
+
end
|
253
|
+
}
|
254
|
+
end
|
255
|
+
|
256
|
+
def add_debugging(base, option_sym, env_sym)
|
257
|
+
methods = base.commands.keys - base.subcommands
|
258
|
+
base.class_eval {
|
259
|
+
methods.each { |method_name|
|
260
|
+
original_method = instance_method(method_name)
|
261
|
+
no_commands {
|
262
|
+
define_method(method_name) { |*args, &block|
|
263
|
+
debug = if option_sym && (options.has_key?(option_sym.to_s) || options.has_key?(option_sym.to_sym))
|
264
|
+
options[option_sym.to_sym]
|
265
|
+
elsif env_sym
|
266
|
+
d = ENV[env_sym.to_s]
|
267
|
+
d == '1' || d == 1 || d == 'true' || d == 't'
|
268
|
+
end
|
269
|
+
if debug
|
270
|
+
puts "command: #{self.class.basename2} #{__method__.gsub(/_/, '-').to_s}"
|
271
|
+
puts "parent_options: #{parent_options.inspect}"
|
272
|
+
puts "options: #{options.inspect}"
|
273
|
+
original_method.parameters.each_with_index { |p, i| puts "#{p[1].to_s}: #{args[i]}" }
|
274
|
+
end
|
275
|
+
begin
|
276
|
+
original_method.bind(self).call(*args, &block)
|
277
|
+
rescue ArgumentError => e
|
278
|
+
base.handle_argument_error(base.commands[method_name], e, args, original_method.arity)
|
279
|
+
end
|
280
|
+
}
|
281
|
+
}
|
282
|
+
}
|
283
|
+
}
|
284
|
+
base.subcommand_classes.values.each { |c| add_debugging(c, option_sym, env_sym) }
|
285
|
+
end
|
286
|
+
|
287
|
+
private :build_recurse
|
288
|
+
end
|
289
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: everyday_thor_util
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eric Henderson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-12-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -16,28 +16,28 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '1.
|
19
|
+
version: '1.7'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '1.
|
26
|
+
version: '1.7'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '10.
|
33
|
+
version: '10.4'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '10.
|
40
|
+
version: '10.4'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: everyday-plugins
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -82,6 +82,7 @@ files:
|
|
82
82
|
- Rakefile
|
83
83
|
- everyday_thor_util.gemspec
|
84
84
|
- lib/everyday_thor_util.rb
|
85
|
+
- lib/everyday_thor_util/builder.rb
|
85
86
|
- lib/everyday_thor_util/plugin-helper.rb
|
86
87
|
- lib/everyday_thor_util/thor-fix.rb
|
87
88
|
- lib/everyday_thor_util/version.rb
|
@@ -105,10 +106,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
105
106
|
version: '0'
|
106
107
|
requirements: []
|
107
108
|
rubyforge_project:
|
108
|
-
rubygems_version: 2.
|
109
|
+
rubygems_version: 2.4.5
|
109
110
|
signing_key:
|
110
111
|
specification_version: 4
|
111
112
|
summary: 'Two parts: everyday_thor_util/thor-fix has a patch for Thor and everyday_thor_util/plugin-helper
|
112
113
|
has some Thor handling everyday-plugin helpers'
|
113
114
|
test_files: []
|
114
|
-
has_rdoc:
|