josevalim-thor 0.10.20 → 0.10.21
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/thor/actions.rb +8 -2
- data/lib/thor/base.rb +2 -1
- data/lib/thor/invocation.rb +14 -8
- data/lib/thor/parser/option.rb +8 -4
- data/lib/thor/util.rb +2 -4
- metadata +2 -2
data/lib/thor/actions.rb
CHANGED
@@ -305,8 +305,14 @@ class Thor
|
|
305
305
|
end
|
306
306
|
|
307
307
|
def _cleanup_options_and_set(options, key)
|
308
|
-
|
309
|
-
|
308
|
+
case options
|
309
|
+
when Array
|
310
|
+
%w(--force -f --skip -s).each { |i| options.delete(i) }
|
311
|
+
options << "--#{key}"
|
312
|
+
when Hash
|
313
|
+
[:force, :skip, "force", "skip"].each { |i| options.delete(i) }
|
314
|
+
options.merge!(key => true)
|
315
|
+
end
|
310
316
|
end
|
311
317
|
|
312
318
|
end
|
data/lib/thor/base.rb
CHANGED
@@ -381,9 +381,10 @@ class Thor
|
|
381
381
|
|
382
382
|
printer = lambda do |group_name, options|
|
383
383
|
list = []
|
384
|
+
padding = options.collect{ |o| o.aliases.size }.max.to_i * 4
|
384
385
|
|
385
386
|
options.each do |option|
|
386
|
-
list << [ option.usage, option.description || "" ]
|
387
|
+
list << [ option.usage(padding), option.description || "" ]
|
387
388
|
list << [ "", "Default: #{option.default}" ] if option.show_default?
|
388
389
|
end
|
389
390
|
|
data/lib/thor/invocation.rb
CHANGED
@@ -130,24 +130,30 @@ class Thor
|
|
130
130
|
when Symbol, String
|
131
131
|
name = name.to_s
|
132
132
|
|
133
|
-
|
134
|
-
|
135
|
-
object, task = Thor::Util.namespace_to_thor_class(name)
|
136
|
-
task
|
137
|
-
rescue Thor::Error
|
138
|
-
task = name
|
133
|
+
# If is not one of this class tasks, do a lookup.
|
134
|
+
unless task = self.class.all_tasks[name]
|
135
|
+
object, task = Thor::Util.namespace_to_thor_class(name, false)
|
136
|
+
task ||= sent_task
|
139
137
|
end
|
140
138
|
else
|
141
139
|
object, task = name, sent_task
|
142
140
|
end
|
143
141
|
|
144
|
-
object
|
142
|
+
# If the object was not set, use self and use the name as task.
|
143
|
+
object, task = self, name unless object
|
144
|
+
return object, _validate_klass_and_task(object, task)
|
145
|
+
end
|
146
|
+
|
147
|
+
# Check if the object given is a Thor class object and get a task object
|
148
|
+
# for it.
|
149
|
+
#
|
150
|
+
def _validate_klass_and_task(object, task)
|
145
151
|
klass = object.is_a?(Class) ? object : object.class
|
146
152
|
raise "Expected Thor class, got #{klass}" unless klass <= Thor::Base
|
147
153
|
|
148
154
|
task ||= klass.default_task if klass <= Thor
|
149
155
|
task = klass.all_tasks[task.to_s] || Task.dynamic(task) if task && !task.is_a?(Thor::Task)
|
150
|
-
|
156
|
+
task
|
151
157
|
end
|
152
158
|
|
153
159
|
end
|
data/lib/thor/parser/option.rb
CHANGED
@@ -78,16 +78,20 @@ class Thor
|
|
78
78
|
@human_name ||= dasherized? ? undasherize(name) : name
|
79
79
|
end
|
80
80
|
|
81
|
-
def usage
|
81
|
+
def usage(padding=0)
|
82
82
|
sample = if banner
|
83
83
|
"#{switch_name}=#{banner}"
|
84
84
|
else
|
85
85
|
switch_name
|
86
86
|
end
|
87
87
|
|
88
|
-
sample = "[#{sample}]"
|
89
|
-
|
90
|
-
|
88
|
+
sample = "[#{sample}]" unless required?
|
89
|
+
|
90
|
+
if aliases.empty?
|
91
|
+
(" " * padding) << sample
|
92
|
+
else
|
93
|
+
"#{aliases.join(', ')}, #{sample}"
|
94
|
+
end
|
91
95
|
end
|
92
96
|
|
93
97
|
protected
|
data/lib/thor/util.rb
CHANGED
@@ -35,8 +35,6 @@ class Thor
|
|
35
35
|
# older versions of Thor. On current versions, if you need to get the
|
36
36
|
# namespace from a class, just call namespace on it.
|
37
37
|
#
|
38
|
-
# TODO Deprecate this method in the future.
|
39
|
-
#
|
40
38
|
# ==== Parameters
|
41
39
|
# constant<Object>:: The constant to be converted to the thor path.
|
42
40
|
#
|
@@ -115,7 +113,7 @@ class Thor
|
|
115
113
|
# Thor::Error:: raised if the namespace evals to a class which does not
|
116
114
|
# inherit from Thor or Thor::Group.
|
117
115
|
#
|
118
|
-
def self.namespace_to_thor_class(namespace)
|
116
|
+
def self.namespace_to_thor_class(namespace, raise_if_nil=true)
|
119
117
|
klass, task_name = Thor::Util.find_by_namespace(namespace), nil
|
120
118
|
|
121
119
|
if klass.nil? && namespace.include?(?:)
|
@@ -124,7 +122,7 @@ class Thor
|
|
124
122
|
klass = Thor::Util.find_by_namespace(namespace.join(":"))
|
125
123
|
end
|
126
124
|
|
127
|
-
raise Error, "could not find Thor class or task '#{namespace}'"
|
125
|
+
raise Error, "could not find Thor class or task '#{namespace}'" if raise_if_nil && klass.nil?
|
128
126
|
|
129
127
|
return klass, task_name
|
130
128
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: josevalim-thor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.10.
|
4
|
+
version: 0.10.21
|
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: 2009-06-
|
12
|
+
date: 2009-06-30 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|