thor 0.9.8 → 0.9.9
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/thor/runner.rb +31 -12
- data/lib/thor/task.rb +0 -5
- data/lib/thor/tasks.rb +1 -1
- data/lib/thor/util.rb +23 -5
- metadata +3 -3
data/lib/thor/runner.rb
CHANGED
@@ -18,8 +18,17 @@ class Thor::Runner < Thor
|
|
18
18
|
method_options :as => :optional, :relative => :boolean
|
19
19
|
def install(name)
|
20
20
|
initialize_thorfiles
|
21
|
+
|
22
|
+
base = name
|
23
|
+
package = :file
|
24
|
+
|
21
25
|
begin
|
22
|
-
|
26
|
+
if File.directory?(File.expand_path(name))
|
27
|
+
base, package = File.join(name, "main.thor"), :directory
|
28
|
+
contents = open(base).read
|
29
|
+
else
|
30
|
+
contents = open(name).read
|
31
|
+
end
|
23
32
|
rescue OpenURI::HTTPError
|
24
33
|
raise Error, "Error opening URI `#{name}'"
|
25
34
|
rescue Errno::ENOENT
|
@@ -35,9 +44,7 @@ class Thor::Runner < Thor
|
|
35
44
|
|
36
45
|
return false unless response =~ /^\s*y/i
|
37
46
|
|
38
|
-
constants = Thor::Util.constants_in_contents(contents)
|
39
|
-
|
40
|
-
# name = name =~ /\.thor$/ || is_uri ? name : "#{name}.thor"
|
47
|
+
constants = Thor::Util.constants_in_contents(contents, base)
|
41
48
|
|
42
49
|
as = options["as"] || begin
|
43
50
|
first_line = contents.split("\n")[0]
|
@@ -63,8 +70,12 @@ class Thor::Runner < Thor
|
|
63
70
|
|
64
71
|
puts "Storing thor file in your system repository"
|
65
72
|
|
66
|
-
File.
|
67
|
-
|
73
|
+
destination = File.join(thor_root, yaml[as][:filename])
|
74
|
+
|
75
|
+
if package == :file
|
76
|
+
File.open(destination, "w") {|f| f.puts contents }
|
77
|
+
else
|
78
|
+
FileUtils.cp_r(name, destination)
|
68
79
|
end
|
69
80
|
|
70
81
|
yaml[as][:filename] # Indicate sucess
|
@@ -78,7 +89,7 @@ class Thor::Runner < Thor
|
|
78
89
|
puts "Uninstalling #{name}."
|
79
90
|
|
80
91
|
file = File.join(thor_root, "#{yaml[name][:filename]}")
|
81
|
-
|
92
|
+
FileUtils.rm_rf(file)
|
82
93
|
yaml.delete(name)
|
83
94
|
save_yaml(yaml)
|
84
95
|
|
@@ -121,8 +132,8 @@ class Thor::Runner < Thor
|
|
121
132
|
search = ".*#{search}" if options["substring"]
|
122
133
|
search = /^#{search}.*/i
|
123
134
|
group = options[:group] || 'standard'
|
124
|
-
|
125
|
-
classes = Thor.subclasses.select do |k|
|
135
|
+
|
136
|
+
classes = Thor.subclasses.select do |k|
|
126
137
|
(options[:all] || k.group_name == group) &&
|
127
138
|
Thor::Util.constant_to_thor_path(k.name) =~ search
|
128
139
|
end
|
@@ -154,7 +165,10 @@ class Thor::Runner < Thor
|
|
154
165
|
# C:\Documents and Settings\james\.thor
|
155
166
|
#
|
156
167
|
# If we don't #gsub the \ character, Dir.glob will fail.
|
157
|
-
Dir["#{thor_root.gsub(/\\/, '/')}
|
168
|
+
files = Dir["#{thor_root.gsub(/\\/, '/')}/*"]
|
169
|
+
files.map! do |file|
|
170
|
+
File.directory?(file) ? File.join(file, "main.thor") : file
|
171
|
+
end
|
158
172
|
end
|
159
173
|
|
160
174
|
private
|
@@ -252,8 +266,9 @@ class Thor::Runner < Thor
|
|
252
266
|
end
|
253
267
|
|
254
268
|
def load_thorfile(path)
|
269
|
+
txt = File.read(path)
|
255
270
|
begin
|
256
|
-
|
271
|
+
Thor::Tasks.class_eval txt, path
|
257
272
|
rescue Object => e
|
258
273
|
$stderr.puts "WARNING: unable to load thorfile #{path.inspect}: #{e.message}"
|
259
274
|
end
|
@@ -272,8 +287,12 @@ class Thor::Runner < Thor
|
|
272
287
|
|
273
288
|
# We want to load system-wide Thorfiles first
|
274
289
|
# so the local Thorfiles will override them.
|
275
|
-
(relevant_to ? thorfiles_relevant_to(relevant_to) :
|
290
|
+
files = (relevant_to ? thorfiles_relevant_to(relevant_to) :
|
276
291
|
thor_root_glob) + thorfiles - ["#{thor_root}/thor.yml"]
|
292
|
+
|
293
|
+
files.map! do |file|
|
294
|
+
File.directory?(file) ? File.join(file, "main.thor") : file
|
295
|
+
end
|
277
296
|
end
|
278
297
|
|
279
298
|
def thorfiles_relevant_to(meth)
|
data/lib/thor/task.rb
CHANGED
@@ -62,10 +62,6 @@ class Thor
|
|
62
62
|
@_full_opts ||= Options.new((klass.opts || {}).merge(@options))
|
63
63
|
end
|
64
64
|
|
65
|
-
def options?
|
66
|
-
@options.kind_of?(Hash) && !@options.empty?
|
67
|
-
end
|
68
|
-
|
69
65
|
def formatted_usage(namespace = false)
|
70
66
|
(namespace ? self.namespace + ':' : '') + usage +
|
71
67
|
(opts ? " " + opts.formatted_usage : "")
|
@@ -75,7 +71,6 @@ class Thor
|
|
75
71
|
|
76
72
|
def parse_args(args)
|
77
73
|
return [[], {}] if args.nil?
|
78
|
-
return [args, {}] unless options?
|
79
74
|
hash = full_opts.parse(args)
|
80
75
|
list = full_opts.non_opts
|
81
76
|
[list, hash]
|
data/lib/thor/tasks.rb
CHANGED
@@ -22,7 +22,7 @@ class Thor
|
|
22
22
|
old_stderr, $stderr = $stderr.dup, File.open(null, "w")
|
23
23
|
package
|
24
24
|
$stderr = old_stderr
|
25
|
-
system %{#{sudo} #{gem} install pkg/#{spec.name}-#{spec.version} --no-rdoc --no-ri --no-update-sources}
|
25
|
+
system %{#{sudo} #{Gem.ruby} -S #{gem} install pkg/#{spec.name}-#{spec.version} --no-rdoc --no-ri --no-update-sources}
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
data/lib/thor/util.rb
CHANGED
@@ -15,10 +15,24 @@ module ObjectSpace
|
|
15
15
|
end
|
16
16
|
|
17
17
|
class Thor
|
18
|
+
module Tasks; end
|
19
|
+
|
18
20
|
module Util
|
19
21
|
|
22
|
+
def self.full_const_get(obj, name)
|
23
|
+
list = name.split("::")
|
24
|
+
list.shift if list.first.empty?
|
25
|
+
list.each do |x|
|
26
|
+
# This is required because const_get tries to look for constants in the
|
27
|
+
# ancestor chain, but we only want constants that are HERE
|
28
|
+
obj = obj.const_defined?(x) ? obj.const_get(x) : obj.const_missing(x)
|
29
|
+
end
|
30
|
+
obj
|
31
|
+
end
|
32
|
+
|
20
33
|
def self.constant_to_thor_path(str, remove_default = true)
|
21
|
-
str =
|
34
|
+
str = str.to_s.gsub(/^Thor::Tasks::/, "")
|
35
|
+
str = snake_case(str).squeeze(":")
|
22
36
|
str.gsub!(/^default/, '') if remove_default
|
23
37
|
str
|
24
38
|
end
|
@@ -35,16 +49,20 @@ class Thor
|
|
35
49
|
str.gsub(/:(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
|
36
50
|
end
|
37
51
|
|
38
|
-
def self.constants_in_contents(str)
|
52
|
+
def self.constants_in_contents(str, file = __FILE__)
|
39
53
|
klasses = ObjectSpace.classes.dup
|
40
|
-
Module.new.class_eval(str)
|
54
|
+
Module.new.class_eval(str, file)
|
41
55
|
klasses = ObjectSpace.classes - klasses
|
42
56
|
klasses = klasses.select {|k| k < Thor }
|
43
57
|
klasses.map! {|k| k.to_s.gsub(/#<Module:\w+>::/, '')}
|
44
58
|
end
|
45
59
|
|
46
|
-
def self.make_constant(str)
|
47
|
-
|
60
|
+
def self.make_constant(str, base = [Thor::Tasks, Object])
|
61
|
+
which = base.find do |obj|
|
62
|
+
full_const_get(obj, str) rescue nil
|
63
|
+
end
|
64
|
+
return full_const_get(which, str) if which
|
65
|
+
raise NameError, "uninitialized constant #{str}"
|
48
66
|
end
|
49
67
|
|
50
68
|
def self.snake_case(str)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: thor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yehuda Katz
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-
|
12
|
+
date: 2008-12-15 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -65,7 +65,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
65
65
|
requirements: []
|
66
66
|
|
67
67
|
rubyforge_project: thor
|
68
|
-
rubygems_version: 1.3.
|
68
|
+
rubygems_version: 1.3.1
|
69
69
|
signing_key:
|
70
70
|
specification_version: 2
|
71
71
|
summary: A gem that maps options to a class
|