josevalim-thor 0.10.17 → 0.10.18
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/thor.rb +2 -4
- data/lib/thor/actions.rb +16 -2
- data/lib/thor/base.rb +1 -1
- data/lib/thor/group.rb +1 -4
- data/lib/thor/option.rb +9 -0
- data/lib/thor/options.rb +15 -5
- metadata +2 -2
data/lib/thor.rb
CHANGED
@@ -124,10 +124,8 @@ class Thor
|
|
124
124
|
opts = Thor::Options.new(options)
|
125
125
|
opts.parse(args)
|
126
126
|
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
instance = new(opts.arguments, defaults.merge!(opts.options), config) do |klass, invoke, overrides|
|
127
|
+
merge_with_thor_options(opts.options, task.options)
|
128
|
+
instance = new(opts.arguments, opts.options, config) do |klass, invoke, overrides|
|
131
129
|
klass.prepare(invoke, args, config.merge(overrides))
|
132
130
|
end
|
133
131
|
|
data/lib/thor/actions.rb
CHANGED
@@ -42,9 +42,18 @@ class Thor
|
|
42
42
|
# as destination root.
|
43
43
|
#
|
44
44
|
def initialize(args=[], options={}, config={})
|
45
|
+
self.behavior = case config[:behavior].to_s
|
46
|
+
when "force", "skip"
|
47
|
+
_cleanup_options_and_set(options, config[:behavior])
|
48
|
+
:invoke
|
49
|
+
when "revoke"
|
50
|
+
:revoke
|
51
|
+
else
|
52
|
+
:invoke
|
53
|
+
end
|
54
|
+
|
45
55
|
super
|
46
|
-
self.root
|
47
|
-
self.behavior = config[:behavior].to_s == "revoke" ? :revoke : :invoke
|
56
|
+
self.root = config[:root]
|
48
57
|
end
|
49
58
|
|
50
59
|
# Wraps an action object and call it accordingly to the thor class behavior.
|
@@ -295,5 +304,10 @@ class Thor
|
|
295
304
|
super.merge!(:root => self.root)
|
296
305
|
end
|
297
306
|
|
307
|
+
def _cleanup_options_and_set(options, key)
|
308
|
+
[:force, :skip, "force", "skip"].each { |i| options.delete(i) }
|
309
|
+
options.merge!(key => true)
|
310
|
+
end
|
311
|
+
|
298
312
|
end
|
299
313
|
end
|
data/lib/thor/base.rb
CHANGED
@@ -388,7 +388,7 @@ class Thor
|
|
388
388
|
options.each do |option|
|
389
389
|
next if option.argument?
|
390
390
|
list << [ option.usage, option.description || "" ]
|
391
|
-
list << [ "", "Default: #{option.default}" ] if option.
|
391
|
+
list << [ "", "Default: #{option.default}" ] if option.show_default?
|
392
392
|
end
|
393
393
|
|
394
394
|
unless list.empty?
|
data/lib/thor/group.rb
CHANGED
@@ -24,10 +24,7 @@ class Thor::Group
|
|
24
24
|
opts = Thor::Options.new(class_options)
|
25
25
|
opts.parse(args)
|
26
26
|
|
27
|
-
|
28
|
-
merge_with_thor_options(defaults, {})
|
29
|
-
|
30
|
-
instance = new(opts.arguments, defaults.merge!(opts.options), config) do |klass, invoke, overrides|
|
27
|
+
instance = new(opts.arguments, opts.options, config) do |klass, invoke, overrides|
|
31
28
|
klass.prepare(invoke, args, config.merge(overrides))
|
32
29
|
end
|
33
30
|
|
data/lib/thor/option.rb
CHANGED
data/lib/thor/options.rb
CHANGED
@@ -137,6 +137,12 @@ class Thor
|
|
137
137
|
end
|
138
138
|
end
|
139
139
|
|
140
|
+
# Returns true if the next value exists and is not a switch.
|
141
|
+
#
|
142
|
+
def current_is_value?
|
143
|
+
peek && peek !~ /^-/
|
144
|
+
end
|
145
|
+
|
140
146
|
# Check if the given argument matches with a switch.
|
141
147
|
#
|
142
148
|
def switch?(arg)
|
@@ -167,14 +173,18 @@ class Thor
|
|
167
173
|
@non_assigned_required.delete(option)
|
168
174
|
|
169
175
|
type = if option.type == :default
|
170
|
-
|
176
|
+
current_is_value? ? :string : :boolean
|
171
177
|
else
|
172
178
|
option.type
|
173
179
|
end
|
174
180
|
|
175
181
|
case type
|
176
182
|
when :boolean
|
177
|
-
|
183
|
+
if current_is_value?
|
184
|
+
shift == "true"
|
185
|
+
else
|
186
|
+
@switches.key?(switch) || switch !~ /^--(no|skip)-([-\w]+)$/
|
187
|
+
end
|
178
188
|
when :string
|
179
189
|
shift
|
180
190
|
when :numeric
|
@@ -198,7 +208,7 @@ class Thor
|
|
198
208
|
def parse_hash
|
199
209
|
hash = {}
|
200
210
|
|
201
|
-
while
|
211
|
+
while current_is_value? && peek.include?(?:)
|
202
212
|
key, value = shift.split(':')
|
203
213
|
hash[key] = value
|
204
214
|
end
|
@@ -218,7 +228,7 @@ class Thor
|
|
218
228
|
def parse_array
|
219
229
|
array = []
|
220
230
|
|
221
|
-
while
|
231
|
+
while current_is_value?
|
222
232
|
array << shift
|
223
233
|
end
|
224
234
|
|
@@ -240,7 +250,7 @@ class Thor
|
|
240
250
|
def check_requirement!(switch, option)
|
241
251
|
if option.input_required?
|
242
252
|
raise RequiredArgumentMissingError, "no value provided for required argument '#{switch}'" if peek.nil?
|
243
|
-
raise MalformattedArgumentError, "cannot pass switch '#{peek}' as an argument"
|
253
|
+
raise MalformattedArgumentError, "cannot pass switch '#{peek}' as an argument" unless current_is_value?
|
244
254
|
end
|
245
255
|
end
|
246
256
|
|
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.18
|
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-28 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|