highline_wrapper 1.0.0 → 1.3.0
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.
- checksums.yaml +4 -4
- data/Gemfile.lock +18 -20
- data/Guardfile +1 -1
- data/LICENSE.md +29 -0
- data/README.md +159 -78
- data/lib/highline_wrapper.rb +12 -18
- data/lib/highline_wrapper/checkbox_question.rb +13 -3
- data/lib/highline_wrapper/multiple_choice_question.rb +12 -3
- data/lib/highline_wrapper/open_ended_question.rb +9 -1
- data/lib/highline_wrapper/question.rb +6 -1
- data/lib/highline_wrapper/version.rb +1 -1
- data/lib/highline_wrapper/yes_no_question.rb +13 -5
- data/spec/highline_wrapper/checkbox_question_spec.rb +38 -0
- data/spec/highline_wrapper/multiple_choice_question_spec.rb +38 -0
- data/spec/highline_wrapper/open_ended_question_spec.rb +14 -0
- data/spec/highline_wrapper/question_spec.rb +51 -0
- data/spec/highline_wrapper/yes_no_question_spec.rb +21 -1
- metadata +7 -21
- data/LICENSE +0 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 380bac98137ba1ffb3ffded9336dc97b0b92b6f75f152a20cbc7355ce601feb9
|
4
|
+
data.tar.gz: 6ff8a1a2cf154e7f7cfa9b9937aa17ece09b0ccb3dfc168c258d068fe0a6a8ca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 79b809ec51c6db6122bf12ed43c14eef0f24ea14d9e9f9166f0e648fb9a45698645f91a368e36fd2e230a3f45655847a9438126584b8b8f941723d150191c546
|
7
|
+
data.tar.gz: 926256c87d483ee1a5b2024271a59e7df2acbaef72c19461827cfa6e69e20cfa35de366cd2eea7ee322dce0c1ead6bbe6c229bd5918a1d79e80f972e9358e634
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
highline_wrapper (1.
|
4
|
+
highline_wrapper (1.3.0)
|
5
5
|
highline (~> 2.0)
|
6
6
|
|
7
7
|
GEM
|
@@ -9,13 +9,13 @@ GEM
|
|
9
9
|
specs:
|
10
10
|
ast (2.4.2)
|
11
11
|
coderay (1.1.3)
|
12
|
-
concurrent-ruby (1.1.
|
12
|
+
concurrent-ruby (1.1.9)
|
13
13
|
diff-lcs (1.4.4)
|
14
|
-
faker (2.
|
14
|
+
faker (2.18.0)
|
15
15
|
i18n (>= 1.6, < 2)
|
16
|
-
ffi (1.
|
17
|
-
formatador (0.
|
18
|
-
guard (2.
|
16
|
+
ffi (1.15.3)
|
17
|
+
formatador (0.3.0)
|
18
|
+
guard (2.17.0)
|
19
19
|
formatador (>= 0.2.4)
|
20
20
|
listen (>= 2.7, < 4.0)
|
21
21
|
lumberjack (>= 1.0.12, < 2.0)
|
@@ -30,9 +30,9 @@ GEM
|
|
30
30
|
guard-compat (~> 1.1)
|
31
31
|
rspec (>= 2.99.0, < 4.0)
|
32
32
|
highline (2.0.3)
|
33
|
-
i18n (1.8.
|
33
|
+
i18n (1.8.10)
|
34
34
|
concurrent-ruby (~> 1.0)
|
35
|
-
listen (3.
|
35
|
+
listen (3.5.1)
|
36
36
|
rb-fsevent (~> 0.10, >= 0.10.3)
|
37
37
|
rb-inotify (~> 0.9, >= 0.9.10)
|
38
38
|
lumberjack (1.2.8)
|
@@ -42,18 +42,17 @@ GEM
|
|
42
42
|
nenv (~> 0.1)
|
43
43
|
shellany (~> 0.0)
|
44
44
|
parallel (1.20.1)
|
45
|
-
parser (3.0.
|
45
|
+
parser (3.0.1.1)
|
46
46
|
ast (~> 2.4.1)
|
47
|
-
pry (0.14.
|
47
|
+
pry (0.14.1)
|
48
48
|
coderay (~> 1.1)
|
49
49
|
method_source (~> 1.0)
|
50
50
|
rainbow (3.0.0)
|
51
|
-
|
52
|
-
rb-fsevent (0.10.4)
|
51
|
+
rb-fsevent (0.11.0)
|
53
52
|
rb-inotify (0.10.1)
|
54
53
|
ffi (~> 1.0)
|
55
54
|
regexp_parser (2.1.1)
|
56
|
-
rexml (3.2.
|
55
|
+
rexml (3.2.5)
|
57
56
|
rspec (3.10.0)
|
58
57
|
rspec-core (~> 3.10.0)
|
59
58
|
rspec-expectations (~> 3.10.0)
|
@@ -67,24 +66,24 @@ GEM
|
|
67
66
|
diff-lcs (>= 1.2.0, < 2.0)
|
68
67
|
rspec-support (~> 3.10.0)
|
69
68
|
rspec-support (3.10.2)
|
70
|
-
rubocop (1.
|
69
|
+
rubocop (1.18.2)
|
71
70
|
parallel (~> 1.10)
|
72
71
|
parser (>= 3.0.0.0)
|
73
72
|
rainbow (>= 2.2.2, < 4.0)
|
74
73
|
regexp_parser (>= 1.8, < 3.0)
|
75
74
|
rexml
|
76
|
-
rubocop-ast (>= 1.
|
75
|
+
rubocop-ast (>= 1.7.0, < 2.0)
|
77
76
|
ruby-progressbar (~> 1.7)
|
78
77
|
unicode-display_width (>= 1.4.0, < 3.0)
|
79
|
-
rubocop-ast (1.
|
80
|
-
parser (>=
|
78
|
+
rubocop-ast (1.7.0)
|
79
|
+
parser (>= 3.0.1.1)
|
81
80
|
ruby-progressbar (1.11.0)
|
82
81
|
shellany (0.0.1)
|
83
82
|
thor (1.1.0)
|
84
83
|
unicode-display_width (2.0.0)
|
85
84
|
|
86
85
|
PLATFORMS
|
87
|
-
x86_64-darwin-
|
86
|
+
x86_64-darwin-19
|
88
87
|
|
89
88
|
DEPENDENCIES
|
90
89
|
bundler (~> 2.2)
|
@@ -92,9 +91,8 @@ DEPENDENCIES
|
|
92
91
|
guard-rspec (~> 4.3)
|
93
92
|
highline_wrapper!
|
94
93
|
pry (~> 0.13)
|
95
|
-
rake (~> 13.0)
|
96
94
|
rspec (~> 3.9)
|
97
95
|
rubocop (~> 1.10)
|
98
96
|
|
99
97
|
BUNDLED WITH
|
100
|
-
2.2.
|
98
|
+
2.2.21
|
data/Guardfile
CHANGED
data/LICENSE.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
BSD 3-Clause "New" or "Revised" License
|
2
|
+
|
3
|
+
Copyright (c) 2021 Emma Sax.
|
4
|
+
All rights reserved.
|
5
|
+
|
6
|
+
Redistribution and use in source and binary forms, with or without
|
7
|
+
modification, are permitted provided that the following conditions are met:
|
8
|
+
|
9
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
10
|
+
list of conditions, and the following disclaimer.
|
11
|
+
|
12
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
13
|
+
this list of conditions, and the following disclaimer in the documentation
|
14
|
+
and/or other materials provided with the distribution.
|
15
|
+
|
16
|
+
3. Neither the name of the copyright holder nor the names of its
|
17
|
+
contributors may be used to endorse or promote products derived from
|
18
|
+
this software without specific prior written permission.
|
19
|
+
|
20
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
21
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
22
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
23
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
24
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
25
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
26
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
27
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
28
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
29
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/README.md
CHANGED
@@ -46,66 +46,87 @@ Then, you can call its questions to receive answers. There's several configurati
|
|
46
46
|
### Open-ended questions
|
47
47
|
|
48
48
|
Question configuration options:
|
49
|
+
* `indicate_default_message`: defaults to `true`
|
49
50
|
* `secret`: defaults to `false`
|
50
51
|
* `default`: defaults to `''`
|
51
52
|
* `required`: defaults to `false`
|
52
53
|
|
54
|
+
Notes:
|
55
|
+
* If `indicate_default_message` is `true`, then the wrapper will tell us what the default value returned is _if_ the user skips the question
|
56
|
+
* If `secret` is `true`, then the wrapper _may_ automatically add a newline after a skipped answer... this is automatic from HighLine and is, unfortunately, out of the wrapper's control
|
57
|
+
* If `required` is `true`, the question will repeat until the user answers the question
|
58
|
+
* If `required` is `true`, then the `default` value will be ignored (defaults to `''`, but could be set to whatever and the code won't care... the question is required)
|
59
|
+
* If `default` is `''` and `required` is `false`, and the user skips the question, the answer will be `''`
|
60
|
+
* If `secret` is `true`, then the command-line will hide the user's answer behind `*`
|
61
|
+
|
53
62
|
<details><summary>Examples</summary>
|
54
63
|
|
55
64
|
```ruby
|
56
65
|
> HighlineWrapper.new.ask('What is your favorite number?')
|
57
66
|
What is your favorite number?
|
58
67
|
four
|
59
|
-
|
60
68
|
=> "four"
|
61
69
|
|
62
70
|
> HighlineWrapper.new.ask('What is your favorite number?', {required: true})
|
63
71
|
What is your favorite number?
|
64
|
-
|
65
|
-
This question is required.
|
66
|
-
|
72
|
+
--- This question is required ---
|
67
73
|
What is your favorite number?
|
68
|
-
|
69
|
-
|
70
|
-
|
74
|
+
--- This question is required ---
|
75
|
+
What is your favorite number?
|
76
|
+
--- This question is required ---
|
71
77
|
What is your favorite number?
|
72
78
|
2
|
73
|
-
|
74
79
|
=> "2"
|
75
80
|
|
81
|
+
> HighlineWrapper.new.ask('What is your favorite number?', {required: true, indicate_default_message: false})
|
82
|
+
What is your favorite number?
|
83
|
+
--- This question is required ---
|
84
|
+
What is your favorite number?
|
85
|
+
--- This question is required ---
|
86
|
+
What is your favorite number?
|
87
|
+
5
|
88
|
+
=> "5"
|
89
|
+
|
90
|
+
> HighlineWrapper.new.ask('What is your favorite number?', {indicate_default_message: false})
|
91
|
+
What is your favorite number?
|
92
|
+
=> ""
|
93
|
+
|
76
94
|
> HighlineWrapper.new.ask('What is your favorite color?')
|
77
95
|
What is your favorite color?
|
78
|
-
|
96
|
+
--- Default selected: EMPTY ---
|
79
97
|
=> ""
|
80
98
|
|
81
99
|
> HighlineWrapper.new.ask('What is your favorite color?', {default: 'orange'})
|
82
100
|
What is your favorite color?
|
83
|
-
|
101
|
+
--- Default selected: orange ---
|
84
102
|
=> "orange"
|
85
103
|
|
86
104
|
> HighlineWrapper.new.ask('Please type your private token:', {secret: true})
|
87
105
|
Please type your private token?
|
88
106
|
****************
|
89
|
-
|
90
107
|
=> "MY-PRIVATE-TOKEN"
|
91
108
|
|
92
|
-
> HighlineWrapper.new.ask('
|
93
|
-
|
94
|
-
|
95
|
-
This question is required.
|
109
|
+
> HighlineWrapper.new.ask('Please type your private token:', {secret: true, indicate_default_message: false})
|
110
|
+
Please type your private token:
|
96
111
|
|
97
|
-
|
98
|
-
|
99
|
-
This question is required.
|
112
|
+
=> ""
|
100
113
|
|
101
|
-
|
114
|
+
> HighlineWrapper.new.ask('Please type your private token:', {secret: true, required: true})
|
115
|
+
Please type your private token:
|
102
116
|
|
103
|
-
This question is required
|
117
|
+
--- This question is required ---
|
118
|
+
Please type your private token:
|
104
119
|
|
105
|
-
|
120
|
+
--- This question is required ---
|
121
|
+
Please type your private token:
|
106
122
|
****************
|
107
|
-
|
108
123
|
=> "MY-PRIVATE-TOKEN"
|
124
|
+
|
125
|
+
> HighlineWrapper.new.ask('Please type your private token:', {secret: true})
|
126
|
+
Please type your private token:
|
127
|
+
|
128
|
+
--- Default selected: HIDDEN ---
|
129
|
+
=> ""
|
109
130
|
```
|
110
131
|
|
111
132
|
</details>
|
@@ -113,61 +134,79 @@ What is your private token?
|
|
113
134
|
### Yes/No questions
|
114
135
|
|
115
136
|
Question configuration options:
|
137
|
+
* `indicate_default_message`: defaults to `true`
|
116
138
|
* `default`: defaults to `true` (aka 'yes')
|
117
139
|
* `required`: defaults to `false`
|
118
140
|
|
141
|
+
Notes:
|
142
|
+
* If `indicate_default_message` is `true`, then the wrapper will tell us what the default value returned is _if_ the user skips the question
|
143
|
+
* If `required` is `true`, the question will repeat until the user answers the question
|
144
|
+
* If `required` is `true`, then the `default` value will be ignored (defaults to `true`, but could be set to whatever and the code won't care... the question is required)
|
145
|
+
* If `default` is `true` and `required` is `false`, and the user skips the question, the answer will be `true`
|
146
|
+
* The response to the question MUST be given either as `y`/`n`/`yes`/`no` or with any capitalization... anything else given as a response will be unparseable
|
147
|
+
|
119
148
|
<details><summary>Examples</summary>
|
120
149
|
|
121
150
|
```ruby
|
122
151
|
> HighlineWrapper.new.ask_yes_no('Do you like Ruby?')
|
123
152
|
Do you like Ruby?
|
124
|
-
|
153
|
+
--- Default selected: YES ---
|
154
|
+
=> true
|
125
155
|
|
126
|
-
|
156
|
+
> HighlineWrapper.new.ask_yes_no('Do you like Ruby?', {indicate_default_message: false})
|
157
|
+
Do you like Ruby?
|
158
|
+
=> true
|
127
159
|
|
128
160
|
> HighlineWrapper.new.ask_yes_no('Do you like Ruby?')
|
129
161
|
Do you like Ruby?
|
130
|
-
|
131
|
-
|
132
|
-
=> true
|
162
|
+
no
|
163
|
+
=> false
|
133
164
|
|
134
165
|
> HighlineWrapper.new.ask_yes_no('Do you like Ruby?', {default: false})
|
135
166
|
Do you like Ruby?
|
136
|
-
|
167
|
+
--- Default selected: NO ---
|
137
168
|
=> false
|
138
169
|
|
139
170
|
> HighlineWrapper.new.ask_yes_no('Do you like Ruby?', {required: true})
|
140
171
|
Do you like Ruby?
|
141
|
-
|
142
|
-
This question is required.
|
143
|
-
|
172
|
+
--- This question is required ---
|
144
173
|
Do you like Ruby?
|
145
|
-
|
146
|
-
|
174
|
+
--- This question is required ---
|
175
|
+
Do you like Ruby?
|
176
|
+
--- This question is required ---
|
177
|
+
Do you like Ruby?
|
178
|
+
N
|
147
179
|
=> false
|
148
180
|
|
149
181
|
> HighlineWrapper.new.ask_yes_no('Do you like Ruby?')
|
150
182
|
Do you like Ruby?
|
151
183
|
uh-huh
|
152
|
-
|
153
|
-
This question is required.
|
154
|
-
|
184
|
+
--- This question is required ---
|
155
185
|
Do you like Ruby?
|
156
186
|
YES
|
187
|
+
=> true
|
157
188
|
|
189
|
+
> HighlineWrapper.new.ask_yes_no('Do you like Ruby?')
|
190
|
+
Do you like Ruby?
|
191
|
+
yep
|
192
|
+
--- This question is required ---
|
193
|
+
Do you like Ruby?
|
194
|
+
yes
|
158
195
|
=> true
|
159
196
|
```
|
160
197
|
|
161
198
|
</details>
|
162
199
|
|
163
|
-
### Multiple choice
|
200
|
+
### Multiple choice questions
|
164
201
|
|
165
202
|
Question configuration options:
|
203
|
+
* `indicate_default_message`: defaults to `true`
|
166
204
|
* `with_index`: defaults to `false` (particularly handy when there may be duplicate-named but different items in the list—think Sally with ID 45 and Sally with ID 72)
|
167
205
|
* `default`: defaults to `nil`
|
168
206
|
* `required`: defaults to `false`
|
169
207
|
|
170
208
|
Notes:
|
209
|
+
* If `indicate_default_message` is `true`, then the wrapper will tell us what the default value returned is _if_ the user skips the question
|
171
210
|
* If `required` is `true`, the question will repeat until the user answers the question
|
172
211
|
* If `required` is `true`, then the `default` value will be ignored (defaults to `nil`, but could be set to whatever and the code won't care... the question is required)
|
173
212
|
* If `default` is `nil` and `required` is `false`, and the user skips the question, the answer will be `nil`
|
@@ -185,7 +224,6 @@ What is your favorite number of these?
|
|
185
224
|
2. two
|
186
225
|
3. three
|
187
226
|
2
|
188
|
-
|
189
227
|
=> {:value=>"two"}
|
190
228
|
|
191
229
|
> HighlineWrapper.new.ask_multiple_choice('What is your favorite number of these?', ['one', 'two', 'three'], {with_index: true})
|
@@ -194,15 +232,39 @@ What is your favorite number of these?
|
|
194
232
|
2. two
|
195
233
|
3. three
|
196
234
|
2
|
197
|
-
|
198
235
|
=> {:value=>"two", :index=>1}
|
199
236
|
|
237
|
+
> HighlineWrapper.new.ask_multiple_choice('What is your favorite number of these?', ['one', 'two', 'three'], {default: 'three', required: true, indicate_default_message: false})
|
238
|
+
What is your favorite number of these?
|
239
|
+
1. one
|
240
|
+
2. two
|
241
|
+
3. three
|
242
|
+
--- This question is required ---
|
243
|
+
What is your favorite number of these?
|
244
|
+
1. one
|
245
|
+
2. two
|
246
|
+
3. three
|
247
|
+
--- This question is required ---
|
248
|
+
What is your favorite number of these?
|
249
|
+
1. one
|
250
|
+
2. two
|
251
|
+
3. three
|
252
|
+
2
|
253
|
+
=> {:value=>"two"}
|
254
|
+
|
200
255
|
> HighlineWrapper.new.ask_multiple_choice('What is your favorite number of these?', ['one', 'two', 'three'], {with_index: true, default: 'one'})
|
201
256
|
What is your favorite number of these?
|
202
257
|
1. one
|
203
258
|
2. two
|
204
259
|
3. three
|
260
|
+
--- Default selected: 1. one ---
|
261
|
+
=> {:value=>"one", :index=>0}
|
205
262
|
|
263
|
+
> HighlineWrapper.new.ask_multiple_choice('What is your favorite number of these?', ['one', 'two', 'three'], {with_index: true, default: 'one', indicate_default_message: false})
|
264
|
+
What is your favorite number of these?
|
265
|
+
1. one
|
266
|
+
2. two
|
267
|
+
3. three
|
206
268
|
=> {:value=>"one", :index=>0}
|
207
269
|
|
208
270
|
> HighlineWrapper.new.ask_multiple_choice('What is your favorite number of these?', ['one', 'two', 'three'], {default: 'three', required: true})
|
@@ -210,51 +272,55 @@ What is your favorite number of these?
|
|
210
272
|
1. one
|
211
273
|
2. two
|
212
274
|
3. three
|
213
|
-
|
214
|
-
This question is required.
|
215
|
-
|
275
|
+
--- This question is required ---
|
216
276
|
What is your favorite number of these?
|
217
277
|
1. one
|
218
278
|
2. two
|
219
279
|
3. three
|
220
|
-
|
221
|
-
This question is required.
|
222
|
-
|
280
|
+
--- This question is required ---
|
223
281
|
What is your favorite number of these?
|
224
282
|
1. one
|
225
283
|
2. two
|
226
284
|
3. three
|
227
|
-
|
228
|
-
|
229
|
-
=> {:value=>"two"}
|
285
|
+
1
|
286
|
+
=> {:value=>"one"}
|
230
287
|
|
231
288
|
> HighlineWrapper.new.ask_multiple_choice('What is your favorite number of these?', ['one', 'two', 'three'], {default: nil})
|
232
289
|
What is your favorite number of these?
|
233
290
|
1. one
|
234
291
|
2. two
|
235
292
|
3. three
|
236
|
-
|
293
|
+
--- Default selected: EMPTY ---
|
237
294
|
=> nil
|
238
295
|
|
239
|
-
>
|
296
|
+
> HighlineWrapper.new.ask_multiple_choice('What is your favorite number of these?', ['one', 'two', 'three'], {default: nil, with_index: true})
|
240
297
|
What is your favorite number of these?
|
241
298
|
1. one
|
242
299
|
2. two
|
243
300
|
3. three
|
301
|
+
--- Default selected: EMPTY ---
|
302
|
+
=> nil
|
244
303
|
|
304
|
+
> HighlineWrapper.new.ask_multiple_choice('What is your favorite number of these?', ['one', 'two', 'three'], {default: nil, with_index: true, indicate_default_message: false})
|
305
|
+
What is your favorite number of these?
|
306
|
+
1. one
|
307
|
+
2. two
|
308
|
+
3. three
|
245
309
|
=> nil
|
246
310
|
```
|
247
311
|
|
248
312
|
</details>
|
249
313
|
|
250
|
-
### Multiple choice "checkbox"
|
314
|
+
### Multiple choice "checkbox" questions
|
251
315
|
|
252
316
|
Question configuration options:
|
317
|
+
* `indicate_default_message`: defaults to `true`
|
253
318
|
* `with_indexes`: defaults to `false` (particularly handy when there may be duplicate-named but different items in the list—think Sally with ID 45 and Sally with ID 72)
|
254
319
|
* `defaults`: defaults to `[]`
|
255
320
|
* `required`: defaults to `false`
|
256
321
|
|
257
322
|
Notes:
|
323
|
+
* If `indicate_default_message` is `true`, then the wrapper will tell us what the default value returned is _if_ the user skips the question
|
258
324
|
* If `required` is `true`, the question will repeat until the user answers the question
|
259
325
|
* If `required` is `true`, then the `defaults` value will be ignored (this value is defaulting to `[]`, but could be set to whatever and the code won't care... the question is required)
|
260
326
|
* If `defaults` is `[]` and `required` is `false`, then the method will return an empty array
|
@@ -272,7 +338,6 @@ What are your favorite numbers of these?
|
|
272
338
|
2. two
|
273
339
|
3. three
|
274
340
|
1, 3
|
275
|
-
|
276
341
|
=> [{:value=>"one"}, {:value=>"three"}]
|
277
342
|
|
278
343
|
> HighlineWrapper.new.ask_checkbox("What are your favorite numbers of these?", ['one', 'two','three'], {with_indexes: true})
|
@@ -281,15 +346,29 @@ What are your favorite numbers of these?
|
|
281
346
|
2. two
|
282
347
|
3. three
|
283
348
|
1, 3
|
284
|
-
|
285
349
|
=> [{:value=>"one", :index=>0}, {:value=>"three", :index=>2}]
|
286
350
|
|
287
|
-
> HighlineWrapper.new.ask_checkbox("What are your favorite numbers of these?", ['one', 'two','three'], {
|
351
|
+
> HighlineWrapper.new.ask_checkbox("What are your favorite numbers of these?", ['one', 'two','three'], {with_indexes: true, indicate_default_message: false})
|
288
352
|
What are your favorite numbers of these?
|
289
353
|
1. one
|
290
354
|
2. two
|
291
355
|
3. three
|
356
|
+
=> []
|
292
357
|
|
358
|
+
> HighlineWrapper.new.ask_checkbox("What are your favorite numbers of these?", ['one', 'two','three'], {with_indexes: true})
|
359
|
+
What are your favorite numbers of these?
|
360
|
+
1. one
|
361
|
+
2. two
|
362
|
+
3. three
|
363
|
+
--- Defaults selected: EMPTY ---
|
364
|
+
=> []
|
365
|
+
|
366
|
+
> HighlineWrapper.new.ask_checkbox("What are your favorite numbers of these?", ['one', 'two','three'], {defaults: ['two', 'three']})
|
367
|
+
What are your favorite numbers of these?
|
368
|
+
1. one
|
369
|
+
2. two
|
370
|
+
3. three
|
371
|
+
--- Defaults selected: 2. two, 3. three ---
|
293
372
|
=> [{:value=>"two"}, {:value=>"three"}]
|
294
373
|
|
295
374
|
> HighlineWrapper.new.ask_checkbox("What are your favorite numbers of these?", ['one', 'two','three'], {required: true, with_indexes: true})
|
@@ -297,15 +376,17 @@ What are your favorite numbers of these?
|
|
297
376
|
1. one
|
298
377
|
2. two
|
299
378
|
3. three
|
300
|
-
|
301
|
-
|
302
|
-
|
379
|
+
--- This question is required ---
|
380
|
+
What are your favorite numbers of these?
|
381
|
+
1. one
|
382
|
+
2. two
|
383
|
+
3. three
|
384
|
+
--- This question is required ---
|
303
385
|
What are your favorite numbers of these?
|
304
386
|
1. one
|
305
387
|
2. two
|
306
388
|
3. three
|
307
389
|
2
|
308
|
-
|
309
390
|
=> [{:value=>"two", :index=>1}]
|
310
391
|
|
311
392
|
> HighlineWrapper.new.ask_checkbox("What are your favorite numbers of these?", ['one', 'two','three'], {required: true, with_indexes: false})
|
@@ -313,49 +394,49 @@ What are your favorite numbers of these?
|
|
313
394
|
1. one
|
314
395
|
2. two
|
315
396
|
3. three
|
316
|
-
|
317
|
-
This question is required.
|
318
|
-
|
397
|
+
--- This question is required ---
|
319
398
|
What are your favorite numbers of these?
|
320
399
|
1. one
|
321
400
|
2. two
|
322
401
|
3. three
|
323
402
|
1
|
324
|
-
|
325
403
|
=> [{:value=>"one"}]
|
326
404
|
|
327
|
-
> HighlineWrapper.new.ask_checkbox("What are your favorite numbers of these?", ['one', 'two','three'], {defaults: []})
|
328
|
-
What are your favorite numbers of these?
|
329
|
-
1. one
|
330
|
-
2. two
|
331
|
-
3. three
|
332
|
-
|
333
|
-
=> []
|
334
|
-
|
335
|
-
> HighlineWrapper.new.ask_checkbox("What are your favorite numbers of these?", ['one', 'two','three'], {defaults: [], with_indexes: true})
|
405
|
+
> HighlineWrapper.new.ask_checkbox("What are your favorite numbers of these?", ['one', 'two','three'], {defaults: ['two', 'three'], with_indexes: true, indicate_default_message: false})
|
336
406
|
What are your favorite numbers of these?
|
337
407
|
1. one
|
338
408
|
2. two
|
339
409
|
3. three
|
340
|
-
|
341
|
-
=> []
|
410
|
+
=> [{:value=>"two", :index=>1}, {:value=>"three", :index=>2}]
|
342
411
|
```
|
343
412
|
|
344
413
|
</details>
|
345
414
|
|
346
415
|
## Tests
|
347
416
|
|
348
|
-
To run the tests, run `bundle exec rspec` from the command
|
417
|
+
To run the tests, run `bundle exec rspec` from the command-line. GitHub Actions will also run the tests upon every commit to make sure they're up to date and that everything is working correctly. Locally, you can also run `bundle exec guard` to automatically run tests as you develop!
|
418
|
+
|
419
|
+
---
|
420
|
+
|
421
|
+
### Contributing
|
422
|
+
|
423
|
+
To submit a feature request, bug ticket, etc, please submit an official [GitHub issue](https://github.com/emmahsax/highline_wrapper/issues/new). To copy or make changes, please [fork this repository](https://github.com/emmahsax/highline_wrapper/fork). When/if you'd like to contribute back to this upstream, please create a pull request on this repository.
|
424
|
+
|
425
|
+
Please follow included Issue Template(s) and Pull Request Template(s) when creating issues or pull requests.
|
426
|
+
|
427
|
+
### Security Policy
|
428
|
+
|
429
|
+
To report any security vulnerabilities, please view this repository's [Security Policy](https://github.com/emmahsax/highline_wrapper/security/policy).
|
349
430
|
|
350
|
-
|
431
|
+
### Licensing
|
351
432
|
|
352
|
-
|
433
|
+
For information on licensing, please see [LICENSE.md](https://github.com/emmahsax/highline_wrapper/blob/main/LICENSE.md).
|
353
434
|
|
354
|
-
|
435
|
+
### Code of Conduct
|
355
436
|
|
356
437
|
When interacting with this repository, please follow [Contributor Covenant's Code of Conduct](https://contributor-covenant.org).
|
357
438
|
|
358
|
-
|
439
|
+
### Releasing
|
359
440
|
|
360
441
|
To make a new release of this gem:
|
361
442
|
|
data/lib/highline_wrapper.rb
CHANGED
@@ -13,15 +13,14 @@ class HighlineWrapper
|
|
13
13
|
#
|
14
14
|
# prompt: the prompt for the question (string)
|
15
15
|
# options: various options to pass to the questions (hash)
|
16
|
+
# indicate_default_message: whether to tell the terminal what the default value selected is if the question
|
17
|
+
# is skipped (boolean - defaults to true)
|
16
18
|
# secret: whether the terminal should hide the typed value (boolean - defaults to false)
|
17
19
|
# default: the default selection (string - defaults to '')
|
18
20
|
# required: whether the question is required or not (boolean - defaults to false)
|
19
|
-
#
|
20
|
-
# Notes:
|
21
|
-
# If required == true, the question will repeat until the user answers the question
|
22
|
-
# If required == true, then the default value will be ignored
|
23
21
|
def ask(prompt, options = {})
|
24
22
|
defaults = {
|
23
|
+
indicate_default_message: true,
|
25
24
|
secret: false,
|
26
25
|
default: '',
|
27
26
|
required: false
|
@@ -34,14 +33,13 @@ class HighlineWrapper
|
|
34
33
|
#
|
35
34
|
# prompt: the prompt for the question (string)
|
36
35
|
# options: various options to pass to the questions (hash)
|
36
|
+
# indicate_default_message: whether to tell the terminal what the default value selected is if the question
|
37
|
+
# is skipped (boolean - defaults to true)
|
37
38
|
# default: the default selection (boolean - defaults to true)
|
38
39
|
# required: whether the question is required or not (boolean - defaults to false)
|
39
|
-
#
|
40
|
-
# Notes:
|
41
|
-
# If required == true, the question will repeat until the user answers the question
|
42
|
-
# If required == true, then the default value will be ignored
|
43
40
|
def ask_yes_no(prompt, options = {})
|
44
41
|
defaults = {
|
42
|
+
indicate_default_message: true,
|
45
43
|
default: true,
|
46
44
|
required: false
|
47
45
|
}
|
@@ -56,16 +54,14 @@ class HighlineWrapper
|
|
56
54
|
# prompt: the prompt for the question (string)
|
57
55
|
# choices: a list of string options (array) (e.g. [ 'a', 'b', 'c' ])
|
58
56
|
# options: various options to pass to the questions (hash)
|
57
|
+
# indicate_default_message: whether to tell the terminal what the default value selected is if the question
|
58
|
+
# is skipped (boolean - defaults to true)
|
59
59
|
# with_index: whether to return the index of the selection (boolean - defaults to false)
|
60
60
|
# default: the default selection if the user skips the question (string - defaults to nil)
|
61
61
|
# required: whether the question is required or not (boolean - defaults to false)
|
62
|
-
#
|
63
|
-
# Notes:
|
64
|
-
# If required == true, the question will repeat until the user answers the question
|
65
|
-
# If required == true, then the default value will be ignored
|
66
|
-
# If default == nil and required == false, and the user skips the question, the answer will be nil
|
67
62
|
def ask_multiple_choice(prompt, choices, options = {})
|
68
63
|
defaults = {
|
64
|
+
indicate_default_message: true,
|
69
65
|
with_index: false,
|
70
66
|
default: nil,
|
71
67
|
required: false
|
@@ -81,16 +77,14 @@ class HighlineWrapper
|
|
81
77
|
# prompt: the prompt for the question (string)
|
82
78
|
# choices: a list of string options (array) (e.g. [ 'a', 'b', 'c' ])
|
83
79
|
# options: various options to pass to the questions (hash)
|
80
|
+
# indicate_default_message: whether to tell the terminal what the default value selected is if the question
|
81
|
+
# is skipped (boolean - defaults to true)
|
84
82
|
# with_indexes: whether to return the indexes of the selections (boolean - defaults to false)
|
85
83
|
# defaults: the default selections if the user skips the question (array - defaults to [])
|
86
84
|
# required: whether the question is required or not (boolean - defaults to false)
|
87
|
-
#
|
88
|
-
# Notes:
|
89
|
-
# If required == true, the question will repeat until the user answers the question
|
90
|
-
# If required == true, then the defaults value will be ignored
|
91
|
-
# If defaults == [] and required == false, then the method will return an empty array
|
92
85
|
def ask_checkbox(prompt, choices, options = {})
|
93
86
|
defaults = {
|
87
|
+
indicate_default_message: true,
|
94
88
|
with_indexes: false,
|
95
89
|
defaults: [],
|
96
90
|
required: false
|
@@ -7,13 +7,12 @@ class HighlineWrapper
|
|
7
7
|
class << self
|
8
8
|
def ask(prompt, choices, options)
|
9
9
|
indices = ask_highline(format_options(prompt, choices))
|
10
|
-
puts
|
11
10
|
|
12
11
|
return format_multiple_selections(choices, indices, options[:with_indexes]) unless indices.empty?
|
13
12
|
return recurse(prompt, choices, options) if options[:required]
|
14
|
-
return options
|
13
|
+
return return_empty_defaults(options) if options[:defaults].empty?
|
15
14
|
|
16
|
-
|
15
|
+
return_defaults(choices, options)
|
17
16
|
end
|
18
17
|
|
19
18
|
private def ask_highline(prompt)
|
@@ -22,6 +21,17 @@ class HighlineWrapper
|
|
22
21
|
indices
|
23
22
|
end
|
24
23
|
|
24
|
+
private def return_defaults(choices, options)
|
25
|
+
options[:default_indexes] = options[:defaults].map { |d| choices.index(d) }
|
26
|
+
print_default_message(options, choices) if options[:indicate_default_message]
|
27
|
+
format_multiple_selections(choices, options[:default_indexes], options[:with_indexes])
|
28
|
+
end
|
29
|
+
|
30
|
+
private def print_default_message(options, choices)
|
31
|
+
defaults = options[:default_indexes].map { |i| "#{i + 1}. #{choices[i]}".strip }.join(', ')
|
32
|
+
puts "--- Defaults selected: #{defaults} ---"
|
33
|
+
end
|
34
|
+
|
25
35
|
private def format_multiple_selections(choices, indices, with_indexes)
|
26
36
|
selected = []
|
27
37
|
indices.each { |index| selected << format_selection(choices, index, with_indexes) }
|
@@ -7,13 +7,22 @@ class HighlineWrapper
|
|
7
7
|
class << self
|
8
8
|
def ask(prompt, choices, options)
|
9
9
|
index = ask_highline(format_options(prompt, choices)).to_i - 1
|
10
|
-
puts
|
11
10
|
|
12
11
|
return format_selection(choices, index, options[:with_index]) unless index == -1
|
13
12
|
return recurse(prompt, choices, options) if options[:required]
|
14
|
-
return
|
13
|
+
return return_empty_defaults(options) if options[:default].nil?
|
15
14
|
|
16
|
-
|
15
|
+
return_defaults(choices, options)
|
16
|
+
end
|
17
|
+
|
18
|
+
private def return_defaults(choices, options)
|
19
|
+
options[:default_index] = choices.index(options[:default])
|
20
|
+
print_default_message(options) if options[:indicate_default_message]
|
21
|
+
format_selection(choices, options[:default_index], options[:with_index])
|
22
|
+
end
|
23
|
+
|
24
|
+
private def print_default_message(options)
|
25
|
+
puts "--- Default selected: #{options[:default_index] + 1}. #{options[:default]} ---"
|
17
26
|
end
|
18
27
|
end
|
19
28
|
end
|
@@ -7,13 +7,21 @@ class HighlineWrapper
|
|
7
7
|
class << self
|
8
8
|
def ask(prompt, options)
|
9
9
|
answer = ask_highline(prompt, secret: options[:secret]).to_s
|
10
|
-
puts unless answer.empty? && options[:secret]
|
11
10
|
|
12
11
|
return answer unless answer.empty?
|
13
12
|
return recurse(prompt, nil, options) if options[:required]
|
14
13
|
|
14
|
+
print_default_message(options) if options[:indicate_default_message]
|
15
15
|
options[:default]
|
16
16
|
end
|
17
|
+
|
18
|
+
private def print_default_message(options)
|
19
|
+
if !options[:secret]
|
20
|
+
puts "--- Default selected: #{options[:default].empty? ? 'EMPTY' : options[:default]} ---"
|
21
|
+
elsif options[:secret]
|
22
|
+
puts '--- Default selected: HIDDEN ---'
|
23
|
+
end
|
24
|
+
end
|
17
25
|
end
|
18
26
|
end
|
19
27
|
end
|
@@ -23,10 +23,15 @@ class HighlineWrapper
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def recurse(prompt, choices, options)
|
26
|
-
puts
|
26
|
+
puts '--- This question is required ---'
|
27
27
|
choices.nil? ? ask(prompt, options) : ask(prompt, choices, options)
|
28
28
|
end
|
29
29
|
|
30
|
+
def return_empty_defaults(options)
|
31
|
+
puts '--- Default selected: EMPTY ---' if options[:indicate_default_message]
|
32
|
+
options[:defaults] || options[:default]
|
33
|
+
end
|
34
|
+
|
30
35
|
private def highline
|
31
36
|
@highline ||= HighLine.new
|
32
37
|
end
|
@@ -7,19 +7,27 @@ class HighlineWrapper
|
|
7
7
|
class << self
|
8
8
|
def ask(prompt, options)
|
9
9
|
answer = ask_highline(prompt).to_s.downcase
|
10
|
-
puts
|
11
10
|
|
12
11
|
return parse(answer, prompt, options) unless answer.empty?
|
13
12
|
return recurse(prompt, nil, options) if options[:required]
|
14
13
|
|
14
|
+
print_default_message(options) if options[:indicate_default_message]
|
15
15
|
options[:default]
|
16
16
|
end
|
17
17
|
|
18
|
-
def parse(answer, prompt, options)
|
19
|
-
|
20
|
-
|
18
|
+
private def parse(answer, prompt, options)
|
19
|
+
case answer
|
20
|
+
when 'yes', 'y'
|
21
|
+
true
|
22
|
+
when 'no', 'n'
|
23
|
+
false
|
24
|
+
else
|
25
|
+
recurse(prompt, nil, options)
|
26
|
+
end
|
27
|
+
end
|
21
28
|
|
22
|
-
|
29
|
+
private def print_default_message(options)
|
30
|
+
puts "--- Default selected: #{options[:default] ? 'YES' : 'NO'} ---"
|
23
31
|
end
|
24
32
|
end
|
25
33
|
end
|
@@ -44,6 +44,12 @@ describe HighlineWrapper::CheckboxQuestion do
|
|
44
44
|
resp = subject.ask(Faker::Lorem.sentence, choices, options)
|
45
45
|
expect(resp).to eq([])
|
46
46
|
end
|
47
|
+
|
48
|
+
it 'should call the return empty defaults if the user skips' do
|
49
|
+
allow(highline).to receive(:ask).and_return('')
|
50
|
+
expect(subject).to receive(:return_empty_defaults)
|
51
|
+
subject.ask(Faker::Lorem.sentence, choices, options)
|
52
|
+
end
|
47
53
|
end
|
48
54
|
|
49
55
|
context 'with required set to true' do
|
@@ -97,6 +103,7 @@ describe HighlineWrapper::CheckboxQuestion do
|
|
97
103
|
context 'with defaults set' do
|
98
104
|
let(:options) do
|
99
105
|
{
|
106
|
+
indicate_default_message: true,
|
100
107
|
with_indexes: false,
|
101
108
|
defaults: ['two'],
|
102
109
|
required: false
|
@@ -114,6 +121,31 @@ describe HighlineWrapper::CheckboxQuestion do
|
|
114
121
|
resp = subject.ask(Faker::Lorem.sentence, choices, options)
|
115
122
|
expect(resp).to eq([{ value: 'two' }])
|
116
123
|
end
|
124
|
+
|
125
|
+
it 'should call to return the defaults if the user skips' do
|
126
|
+
allow(highline).to receive(:ask).and_return('')
|
127
|
+
expect(subject).to receive(:return_defaults).and_call_original
|
128
|
+
expect(subject).to receive(:puts)
|
129
|
+
subject.ask(Faker::Lorem.sentence, choices, options)
|
130
|
+
end
|
131
|
+
|
132
|
+
context 'when the indicate_default_message is false' do
|
133
|
+
let(:options) do
|
134
|
+
{
|
135
|
+
indicate_default_message: false,
|
136
|
+
with_indexes: false,
|
137
|
+
defaults: ['two'],
|
138
|
+
required: false
|
139
|
+
}
|
140
|
+
end
|
141
|
+
|
142
|
+
it 'should call to return the defaults if the user skips' do
|
143
|
+
allow(highline).to receive(:ask).and_return('')
|
144
|
+
expect(subject).to receive(:return_defaults)
|
145
|
+
expect(subject).not_to receive(:puts)
|
146
|
+
subject.ask(Faker::Lorem.sentence, choices, options)
|
147
|
+
end
|
148
|
+
end
|
117
149
|
end
|
118
150
|
|
119
151
|
context 'with defaults set to []' do
|
@@ -182,6 +214,12 @@ describe HighlineWrapper::CheckboxQuestion do
|
|
182
214
|
resp = subject.ask(Faker::Lorem.sentence, choices, options)
|
183
215
|
expect(resp).to eq([])
|
184
216
|
end
|
217
|
+
|
218
|
+
it 'should call the return empty defaults message' do
|
219
|
+
allow(highline).to receive(:ask).and_return('')
|
220
|
+
expect(subject).to receive(:return_empty_defaults)
|
221
|
+
subject.ask(Faker::Lorem.sentence, choices, options)
|
222
|
+
end
|
185
223
|
end
|
186
224
|
end
|
187
225
|
end
|
@@ -44,6 +44,12 @@ describe HighlineWrapper::MultipleChoiceQuestion do
|
|
44
44
|
resp = subject.ask(Faker::Lorem.sentence, choices, options)
|
45
45
|
expect(resp).to eq(nil)
|
46
46
|
end
|
47
|
+
|
48
|
+
it 'should call the return empty defaults if the user skips' do
|
49
|
+
allow(highline).to receive(:ask).and_return('')
|
50
|
+
expect(subject).to receive(:return_empty_defaults)
|
51
|
+
subject.ask(Faker::Lorem.sentence, choices, options)
|
52
|
+
end
|
47
53
|
end
|
48
54
|
|
49
55
|
context 'with required set to true' do
|
@@ -97,6 +103,7 @@ describe HighlineWrapper::MultipleChoiceQuestion do
|
|
97
103
|
context 'with default set' do
|
98
104
|
let(:options) do
|
99
105
|
{
|
106
|
+
indicate_default_message: true,
|
100
107
|
with_index: false,
|
101
108
|
default: 'two',
|
102
109
|
required: false
|
@@ -114,6 +121,31 @@ describe HighlineWrapper::MultipleChoiceQuestion do
|
|
114
121
|
resp = subject.ask(Faker::Lorem.sentence, choices, options)
|
115
122
|
expect(resp).to eq({ value: 'two' })
|
116
123
|
end
|
124
|
+
|
125
|
+
it 'should call to return the defaults if the user skips' do
|
126
|
+
allow(highline).to receive(:ask).and_return(0)
|
127
|
+
expect(subject).to receive(:return_defaults).and_call_original
|
128
|
+
expect(subject).to receive(:puts)
|
129
|
+
subject.ask(Faker::Lorem.sentence, choices, options)
|
130
|
+
end
|
131
|
+
|
132
|
+
context 'when the indicate_default_message is false' do
|
133
|
+
let(:options) do
|
134
|
+
{
|
135
|
+
indicate_default_message: false,
|
136
|
+
with_indexes: false,
|
137
|
+
default: 'two',
|
138
|
+
required: false
|
139
|
+
}
|
140
|
+
end
|
141
|
+
|
142
|
+
it 'should call to return the defaults if the user skips' do
|
143
|
+
allow(highline).to receive(:ask).and_return(0)
|
144
|
+
expect(subject).to receive(:return_defaults)
|
145
|
+
expect(subject).not_to receive(:puts)
|
146
|
+
subject.ask(Faker::Lorem.sentence, choices, options)
|
147
|
+
end
|
148
|
+
end
|
117
149
|
end
|
118
150
|
|
119
151
|
context 'with default nil' do
|
@@ -182,6 +214,12 @@ describe HighlineWrapper::MultipleChoiceQuestion do
|
|
182
214
|
resp = subject.ask(Faker::Lorem.sentence, choices, options)
|
183
215
|
expect(resp).to eq(nil)
|
184
216
|
end
|
217
|
+
|
218
|
+
it 'should call the return empty defaults message' do
|
219
|
+
allow(highline).to receive(:ask).and_return(0)
|
220
|
+
expect(subject).to receive(:return_empty_defaults)
|
221
|
+
subject.ask(Faker::Lorem.sentence, choices, options)
|
222
|
+
end
|
185
223
|
end
|
186
224
|
end
|
187
225
|
end
|
@@ -21,6 +21,7 @@ describe HighlineWrapper::OpenEndedQuestion do
|
|
21
21
|
context 'with the options as defaults' do
|
22
22
|
let(:options) do
|
23
23
|
{
|
24
|
+
indicate_default_message: true,
|
24
25
|
secret: false,
|
25
26
|
default: '',
|
26
27
|
required: false
|
@@ -44,6 +45,12 @@ describe HighlineWrapper::OpenEndedQuestion do
|
|
44
45
|
resp = subject.ask(Faker::Lorem.sentence, options)
|
45
46
|
expect(resp).to eq('')
|
46
47
|
end
|
48
|
+
|
49
|
+
it 'should call to print the default message' do
|
50
|
+
allow(highline).to receive(:ask).and_return('')
|
51
|
+
expect(subject).to receive(:print_default_message)
|
52
|
+
subject.ask(Faker::Lorem.sentence, options)
|
53
|
+
end
|
47
54
|
end
|
48
55
|
|
49
56
|
context 'with required set to true' do
|
@@ -73,6 +80,7 @@ describe HighlineWrapper::OpenEndedQuestion do
|
|
73
80
|
let(:default_string) { Faker::Lorem.sentence }
|
74
81
|
let(:options) do
|
75
82
|
{
|
83
|
+
indicate_default_message: false,
|
76
84
|
secret: false,
|
77
85
|
default: default_string,
|
78
86
|
required: false
|
@@ -90,5 +98,11 @@ describe HighlineWrapper::OpenEndedQuestion do
|
|
90
98
|
allow(highline).to receive(:ask).and_return('')
|
91
99
|
expect(subject.ask(Faker::Lorem.sentence, options)).to eq(default_string)
|
92
100
|
end
|
101
|
+
|
102
|
+
it 'should not call to print the default message' do
|
103
|
+
allow(highline).to receive(:ask).and_return('')
|
104
|
+
expect(subject).not_to receive(:print_default_message)
|
105
|
+
subject.ask(Faker::Lorem.sentence, options)
|
106
|
+
end
|
93
107
|
end
|
94
108
|
end
|
@@ -60,4 +60,55 @@ describe HighlineWrapper::Question do
|
|
60
60
|
end
|
61
61
|
end
|
62
62
|
end
|
63
|
+
|
64
|
+
describe '#should print out a message indicating EMPTY was selected, and return the defaults' do
|
65
|
+
context 'when default message is true' do
|
66
|
+
let(:options) do
|
67
|
+
{
|
68
|
+
defaults: :default,
|
69
|
+
indicate_default_message: true
|
70
|
+
}
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'should return the default in the options' do
|
74
|
+
expect(subject.send(:return_empty_defaults, options)).to eq(:default)
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'should puts a message' do
|
78
|
+
expect(subject).to receive(:puts)
|
79
|
+
expect(subject.send(:return_empty_defaults, options)).to eq(:default)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
context 'when default message is false' do
|
84
|
+
let(:options) do
|
85
|
+
{
|
86
|
+
defaults: :default,
|
87
|
+
indicate_default_message: false
|
88
|
+
}
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'should return the default in the options' do
|
92
|
+
expect(subject.send(:return_empty_defaults, options)).to eq(:default)
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'should not puts a message' do
|
96
|
+
expect(subject).not_to receive(:puts)
|
97
|
+
expect(subject.send(:return_empty_defaults, options)).to eq(:default)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
context 'when a singular default is present, but not plural' do
|
102
|
+
let(:options) do
|
103
|
+
{
|
104
|
+
default: :default,
|
105
|
+
indicate_default_message: false
|
106
|
+
}
|
107
|
+
end
|
108
|
+
|
109
|
+
it 'should return the default in the options' do
|
110
|
+
expect(subject.send(:return_empty_defaults, options)).to eq(:default)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
63
114
|
end
|
@@ -21,13 +21,14 @@ describe HighlineWrapper::YesNoQuestion do
|
|
21
21
|
context 'with the options as defaults' do
|
22
22
|
let(:options) do
|
23
23
|
{
|
24
|
+
indicate_default_message: true,
|
24
25
|
default: true,
|
25
26
|
required: false
|
26
27
|
}
|
27
28
|
end
|
28
29
|
|
29
30
|
it 'should ask the highline client ask' do
|
30
|
-
expect(highline).to receive(:ask)
|
31
|
+
expect(highline).to receive(:ask).and_return('Y')
|
31
32
|
subject.ask(Faker::Lorem.sentence, options)
|
32
33
|
end
|
33
34
|
|
@@ -42,6 +43,18 @@ describe HighlineWrapper::YesNoQuestion do
|
|
42
43
|
resp = subject.ask(Faker::Lorem.sentence, options)
|
43
44
|
expect(resp).to eq(true)
|
44
45
|
end
|
46
|
+
|
47
|
+
it 'should call to print the default message' do
|
48
|
+
allow(highline).to receive(:ask).and_return('')
|
49
|
+
expect(subject).to receive(:print_default_message)
|
50
|
+
subject.ask(Faker::Lorem.sentence, options)
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'should recurse if the answer given is unparseable' do
|
54
|
+
allow(highline).to receive(:ask).and_return('yep', 'yessss', 'yes')
|
55
|
+
expect(subject).to receive(:recurse).exactly(2).times.and_call_original
|
56
|
+
subject.ask(Faker::Lorem.sentence, options)
|
57
|
+
end
|
45
58
|
end
|
46
59
|
|
47
60
|
context 'with required set to true' do
|
@@ -68,6 +81,7 @@ describe HighlineWrapper::YesNoQuestion do
|
|
68
81
|
context 'with required set to false' do
|
69
82
|
let(:options) do
|
70
83
|
{
|
84
|
+
indicate_default_message: false,
|
71
85
|
default: false,
|
72
86
|
required: false
|
73
87
|
}
|
@@ -84,5 +98,11 @@ describe HighlineWrapper::YesNoQuestion do
|
|
84
98
|
resp = subject.ask(Faker::Lorem.sentence, options)
|
85
99
|
expect(resp).to eq(false)
|
86
100
|
end
|
101
|
+
|
102
|
+
it 'should not call to print the default message' do
|
103
|
+
allow(highline).to receive(:ask).and_return('')
|
104
|
+
expect(subject).not_to receive(:print_default_message)
|
105
|
+
subject.ask(Faker::Lorem.sentence, options)
|
106
|
+
end
|
87
107
|
end
|
88
108
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: highline_wrapper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Emma Sax
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-07-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: highline
|
@@ -80,20 +80,6 @@ dependencies:
|
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0.13'
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: rake
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - "~>"
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: '13.0'
|
90
|
-
type: :development
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - "~>"
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: '13.0'
|
97
83
|
- !ruby/object:Gem::Dependency
|
98
84
|
name: rspec
|
99
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -123,7 +109,7 @@ dependencies:
|
|
123
109
|
- !ruby/object:Gem::Version
|
124
110
|
version: '1.10'
|
125
111
|
description: Making it easier to ask simple questions, such as multiple choice questions,
|
126
|
-
yes/no questions, etc, using HighLine
|
112
|
+
yes/no questions, etc, using HighLine.
|
127
113
|
email:
|
128
114
|
executables: []
|
129
115
|
extensions: []
|
@@ -132,7 +118,7 @@ files:
|
|
132
118
|
- Gemfile
|
133
119
|
- Gemfile.lock
|
134
120
|
- Guardfile
|
135
|
-
- LICENSE
|
121
|
+
- LICENSE.md
|
136
122
|
- README.md
|
137
123
|
- Rakefile
|
138
124
|
- lib/highline_wrapper.rb
|
@@ -150,7 +136,7 @@ files:
|
|
150
136
|
- spec/spec_helper.rb
|
151
137
|
homepage: https://github.com/emmahsax/highline_wrapper
|
152
138
|
licenses:
|
153
|
-
-
|
139
|
+
- BSD-3-Clause
|
154
140
|
metadata: {}
|
155
141
|
post_install_message:
|
156
142
|
rdoc_options: []
|
@@ -167,10 +153,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
167
153
|
- !ruby/object:Gem::Version
|
168
154
|
version: '0'
|
169
155
|
requirements: []
|
170
|
-
rubygems_version: 3.2.
|
156
|
+
rubygems_version: 3.2.15
|
171
157
|
signing_key:
|
172
158
|
specification_version: 4
|
173
|
-
summary: A little wrapper
|
159
|
+
summary: A little HighLine wrapper
|
174
160
|
test_files:
|
175
161
|
- spec/spec_helper.rb
|
176
162
|
- spec/highline_wrapper/checkbox_question_spec.rb
|
data/LICENSE
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
Copyright (c) 2021 Emma Sax
|
2
|
-
|
3
|
-
MIT License
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
-
a copy of this software and associated documentation files (the
|
7
|
-
"Software"), to deal in the Software without restriction, including
|
8
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
-
permit persons to whom the Software is furnished to do so, subject to
|
11
|
-
the following conditions:
|
12
|
-
|
13
|
-
The above copyright notice and this permission notice shall be
|
14
|
-
included in all copies or substantial portions of the Software.
|
15
|
-
|
16
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|