thor 0.14.2 → 0.14.3
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.
- data/lib/thor/parser/options.rb +15 -22
- data/lib/thor/version.rb +1 -1
- data/spec/parser/options_spec.rb +5 -1
- metadata +4 -4
data/lib/thor/parser/options.rb
CHANGED
@@ -50,10 +50,12 @@ class Thor
|
|
50
50
|
end
|
51
51
|
|
52
52
|
def parse(args)
|
53
|
-
@pile =
|
53
|
+
@pile = args.dup
|
54
54
|
|
55
55
|
while peek
|
56
|
-
|
56
|
+
match, is_switch = current_is_switch?
|
57
|
+
|
58
|
+
if is_switch
|
57
59
|
case shift
|
58
60
|
when SHORT_SQ_RE
|
59
61
|
unshift($1.split('').map { |f| "-#{f}" })
|
@@ -68,7 +70,7 @@ class Thor
|
|
68
70
|
switch = normalize_switch(switch)
|
69
71
|
option = switch_option(switch)
|
70
72
|
@assigns[option.human_name] = parse_peek(switch, option)
|
71
|
-
elsif
|
73
|
+
elsif match
|
72
74
|
@unknown << shift
|
73
75
|
else
|
74
76
|
shift
|
@@ -92,15 +94,17 @@ class Thor
|
|
92
94
|
#
|
93
95
|
def current_is_switch?
|
94
96
|
case peek
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
97
|
+
when LONG_RE, SHORT_RE, EQ_RE, SHORT_NUM
|
98
|
+
[true, switch?($1)]
|
99
|
+
when SHORT_SQ_RE
|
100
|
+
[true, $1.split('').any? { |f| switch?("-#{f}") }]
|
101
|
+
else
|
102
|
+
[false, false]
|
99
103
|
end
|
100
104
|
end
|
101
105
|
|
102
|
-
def
|
103
|
-
case
|
106
|
+
def current_is_switch_formatted?
|
107
|
+
case peek
|
104
108
|
when LONG_RE, SHORT_RE, EQ_RE, SHORT_NUM, SHORT_SQ_RE
|
105
109
|
true
|
106
110
|
else
|
@@ -108,12 +112,8 @@ class Thor
|
|
108
112
|
end
|
109
113
|
end
|
110
114
|
|
111
|
-
def current_is_switch_formatted?
|
112
|
-
switch_formatted? peek
|
113
|
-
end
|
114
|
-
|
115
115
|
def switch?(arg)
|
116
|
-
switch_option(
|
116
|
+
switch_option(normalize_switch(arg))
|
117
117
|
end
|
118
118
|
|
119
119
|
def switch_option(arg)
|
@@ -127,7 +127,7 @@ class Thor
|
|
127
127
|
# Check if the given argument is actually a shortcut.
|
128
128
|
#
|
129
129
|
def normalize_switch(arg)
|
130
|
-
|
130
|
+
(@shorts[arg] || arg).tr('_', '-')
|
131
131
|
end
|
132
132
|
|
133
133
|
# Parse boolean values which can be given as --foo=true, --foo or --no-foo.
|
@@ -169,12 +169,5 @@ class Thor
|
|
169
169
|
@non_assigned_required.delete(option)
|
170
170
|
send(:"parse_#{option.type}", switch)
|
171
171
|
end
|
172
|
-
|
173
|
-
# Except underscores in commandline switches
|
174
|
-
def except_underscores(args)
|
175
|
-
args.map {|x| x =~ /^--/ ? x.gsub('_', '-') : x }
|
176
|
-
end
|
177
|
-
|
178
|
-
|
179
172
|
end
|
180
173
|
end
|
data/lib/thor/version.rb
CHANGED
data/spec/parser/options_spec.rb
CHANGED
@@ -132,7 +132,6 @@ describe Thor::Options do
|
|
132
132
|
parse("--foo_bar", "baz")["foo_bar"].must == "baz"
|
133
133
|
parse("--baz_foo", "foo bar")["baz_foo"].must == "foo bar"
|
134
134
|
end
|
135
|
-
|
136
135
|
|
137
136
|
describe "with no input" do
|
138
137
|
it "and no switches returns an empty hash" do
|
@@ -188,6 +187,11 @@ describe Thor::Options do
|
|
188
187
|
parse("--foo=12")["foo"].must == "12"
|
189
188
|
parse("--foo=bar=baz")["foo"].must == "bar=baz"
|
190
189
|
end
|
190
|
+
|
191
|
+
it "must accept underscores switch=value assignment" do
|
192
|
+
create :foo_bar => :required
|
193
|
+
parse("--foo_bar=http://example.com/under_score/")["foo_bar"].must == "http://example.com/under_score/"
|
194
|
+
end
|
191
195
|
|
192
196
|
it "accepts a --no-switch format" do
|
193
197
|
create "--foo" => "bar"
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: thor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 33
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 14
|
9
|
-
-
|
10
|
-
version: 0.14.
|
9
|
+
- 3
|
10
|
+
version: 0.14.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Yehuda Katz
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2010-
|
19
|
+
date: 2010-10-04 00:00:00 +02:00
|
20
20
|
default_executable:
|
21
21
|
dependencies: []
|
22
22
|
|