hsume2-hirb 0.6.1 → 0.6.2
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/hirb/menu.rb +9 -5
- data/lib/hirb/version.rb +1 -1
- data/test/menu_test.rb +7 -2
- metadata +3 -3
data/lib/hirb/menu.rb
CHANGED
@@ -12,6 +12,7 @@ module Hirb
|
|
12
12
|
CHOSEN_REGEXP = /^(\d([^:]+)?)(?::)?(\S+)?/
|
13
13
|
CHOSEN_ARG = '%s'
|
14
14
|
ALL_ARG = '*'
|
15
|
+
ALL_REGEXP = /^(\*)(?::)?(\S+)?/
|
15
16
|
DIRECTIONS = "Specify individual choices (4,7), range of choices (1-3) or all choices (*)."
|
16
17
|
|
17
18
|
|
@@ -141,9 +142,12 @@ module Hirb
|
|
141
142
|
end
|
142
143
|
|
143
144
|
def map_all_args(tokens)
|
144
|
-
tokens.map { |t| t == ALL_ARG ? @output : t }
|
145
145
|
tokens.map { |arr,f|
|
146
|
-
arr == ALL_ARG
|
146
|
+
if arr == ALL_ARG
|
147
|
+
f.nil? ? @output : yield(@output, f)
|
148
|
+
else
|
149
|
+
yield(arr, f)
|
150
|
+
end
|
147
151
|
}.flatten
|
148
152
|
end
|
149
153
|
|
@@ -167,10 +171,10 @@ module Hirb
|
|
167
171
|
@new_args << CHOSEN_ARG
|
168
172
|
field = $3 ? unalias_field($3) : default_field ||
|
169
173
|
raise(Error, "No default field/column found. Fields must be explicitly picked.")
|
170
|
-
[Util.choose_from_array(@output, word), field
|
171
|
-
elsif word
|
174
|
+
[Util.choose_from_array(@output, word), field]
|
175
|
+
elsif word[ALL_REGEXP]
|
172
176
|
@new_args << CHOSEN_ARG
|
173
|
-
ALL_ARG
|
177
|
+
$2 ? [ALL_ARG, unalias_field($2)] : ALL_ARG
|
174
178
|
else
|
175
179
|
@new_args << word
|
176
180
|
nil
|
data/lib/hirb/version.rb
CHANGED
data/test/menu_test.rb
CHANGED
@@ -36,7 +36,7 @@ describe "Menu" do
|
|
36
36
|
it "with block renders" do
|
37
37
|
menu_input "1,2"
|
38
38
|
expected_result = [1,2]
|
39
|
-
capture_stdout {
|
39
|
+
capture_stdout {
|
40
40
|
menu([1,2,3]) {|e| e.should == expected_result }.should == expected_result
|
41
41
|
}
|
42
42
|
end
|
@@ -202,6 +202,11 @@ describe "Menu" do
|
|
202
202
|
two_d_menu(:action=>true, :invoke=>[[{:a => 1, :bro => 2}, {:a => 3, :bro => 4}, {:a => 1, :bro => 2}, {:a => 3, :bro => 4}, 4]])
|
203
203
|
end
|
204
204
|
|
205
|
+
it "with all choices with field" do
|
206
|
+
menu_input "p *:bro"
|
207
|
+
two_d_menu(:action=>true, :invoke=>[[2, 4]])
|
208
|
+
end
|
209
|
+
|
205
210
|
it "with no command given prints error" do
|
206
211
|
menu_input "1"
|
207
212
|
capture_stderr { two_d_menu(:action=>true) }.should =~ /No command given/
|
@@ -252,4 +257,4 @@ describe "Menu" do
|
|
252
257
|
}.should =~ /Default.*required/
|
253
258
|
end
|
254
259
|
end
|
255
|
-
end
|
260
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hsume2-hirb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 3
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 6
|
9
|
-
-
|
10
|
-
version: 0.6.
|
9
|
+
- 2
|
10
|
+
version: 0.6.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Gabriel Horner
|