highline_wrapper 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +20 -3
- data/README.md +136 -76
- 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 +6 -2
- 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 +14 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f360fc32885250acb479282caea2a5594cd40ad0f7ed101bf87bf4c229212d2f
|
4
|
+
data.tar.gz: 71dcb19db17ce249d0fb08307b88dcd4fa22686d951065e5d0cc5e479866a53a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2a3e21cc1744f27746016e1744f16640504cdaad8f1b80e1bdf3a9f4b16ac3afa5aed6787f1128e2b02867ba9edd02d83d17fa25f834d27c6334c93063daac9f
|
7
|
+
data.tar.gz: 2560f9a19bcd5fdb633084109aac6a82769d49f54b065ca780c1f0e32503aa9ee66952a731753e0bc5d18a83585e5fb74c57a06f124ca0739f7d201cd8dbf571
|
data/Gemfile.lock
CHANGED
@@ -1,19 +1,22 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
highline_wrapper (1.
|
4
|
+
highline_wrapper (1.1.0)
|
5
5
|
highline (~> 2.0)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
10
|
ast (2.4.2)
|
11
|
+
binding_of_caller (1.0.0)
|
12
|
+
debug_inspector (>= 0.0.1)
|
11
13
|
coderay (1.1.3)
|
12
14
|
concurrent-ruby (1.1.8)
|
15
|
+
debug_inspector (1.0.0)
|
13
16
|
diff-lcs (1.4.4)
|
14
17
|
faker (2.16.0)
|
15
18
|
i18n (>= 1.6, < 2)
|
16
|
-
ffi (1.
|
19
|
+
ffi (1.15.0)
|
17
20
|
formatador (0.2.5)
|
18
21
|
guard (2.16.2)
|
19
22
|
formatador (>= 0.2.4)
|
@@ -32,6 +35,7 @@ GEM
|
|
32
35
|
highline (2.0.3)
|
33
36
|
i18n (1.8.9)
|
34
37
|
concurrent-ruby (~> 1.0)
|
38
|
+
interception (0.5)
|
35
39
|
listen (3.4.1)
|
36
40
|
rb-fsevent (~> 0.10, >= 0.10.3)
|
37
41
|
rb-inotify (~> 0.9, >= 0.9.10)
|
@@ -47,6 +51,15 @@ GEM
|
|
47
51
|
pry (0.14.0)
|
48
52
|
coderay (~> 1.1)
|
49
53
|
method_source (~> 1.0)
|
54
|
+
pry-doc (1.1.0)
|
55
|
+
pry (~> 0.11)
|
56
|
+
yard (~> 0.9.11)
|
57
|
+
pry-rescue (1.5.2)
|
58
|
+
interception (>= 0.5)
|
59
|
+
pry (>= 0.12.0)
|
60
|
+
pry-stack_explorer (0.6.1)
|
61
|
+
binding_of_caller (~> 1.0)
|
62
|
+
pry (~> 0.13)
|
50
63
|
rainbow (3.0.0)
|
51
64
|
rake (13.0.3)
|
52
65
|
rb-fsevent (0.10.4)
|
@@ -82,6 +95,7 @@ GEM
|
|
82
95
|
shellany (0.0.1)
|
83
96
|
thor (1.1.0)
|
84
97
|
unicode-display_width (2.0.0)
|
98
|
+
yard (0.9.26)
|
85
99
|
|
86
100
|
PLATFORMS
|
87
101
|
x86_64-darwin-20
|
@@ -92,9 +106,12 @@ DEPENDENCIES
|
|
92
106
|
guard-rspec (~> 4.3)
|
93
107
|
highline_wrapper!
|
94
108
|
pry (~> 0.13)
|
109
|
+
pry-doc
|
110
|
+
pry-rescue
|
111
|
+
pry-stack_explorer
|
95
112
|
rake (~> 13.0)
|
96
113
|
rspec (~> 3.9)
|
97
114
|
rubocop (~> 1.10)
|
98
115
|
|
99
116
|
BUNDLED WITH
|
100
|
-
2.2.
|
117
|
+
2.2.14
|
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
|
-
|
109
|
+
> HighlineWrapper.new.ask('Please type your private token:', {secret: true, indicate_default_message: false})
|
110
|
+
Please type your private token:
|
94
111
|
|
95
|
-
|
96
|
-
|
97
|
-
What is your private token?
|
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,70 @@ 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
|
+
|
119
147
|
<details><summary>Examples</summary>
|
120
148
|
|
121
149
|
```ruby
|
122
150
|
> HighlineWrapper.new.ask_yes_no('Do you like Ruby?')
|
123
151
|
Do you like Ruby?
|
124
|
-
|
152
|
+
--- Default selected: YES ---
|
153
|
+
=> true
|
125
154
|
|
126
|
-
|
155
|
+
> HighlineWrapper.new.ask_yes_no('Do you like Ruby?', {indicate_default_message: false})
|
156
|
+
Do you like Ruby?
|
157
|
+
=> true
|
127
158
|
|
128
159
|
> HighlineWrapper.new.ask_yes_no('Do you like Ruby?')
|
129
160
|
Do you like Ruby?
|
130
|
-
|
131
|
-
|
132
|
-
=> true
|
161
|
+
no
|
162
|
+
=> false
|
133
163
|
|
134
164
|
> HighlineWrapper.new.ask_yes_no('Do you like Ruby?', {default: false})
|
135
165
|
Do you like Ruby?
|
136
|
-
|
166
|
+
--- Default selected: NO ---
|
137
167
|
=> false
|
138
168
|
|
139
169
|
> HighlineWrapper.new.ask_yes_no('Do you like Ruby?', {required: true})
|
140
170
|
Do you like Ruby?
|
141
|
-
|
142
|
-
This question is required.
|
143
|
-
|
171
|
+
--- This question is required ---
|
144
172
|
Do you like Ruby?
|
145
|
-
|
146
|
-
|
173
|
+
--- This question is required ---
|
174
|
+
Do you like Ruby?
|
175
|
+
--- This question is required ---
|
176
|
+
Do you like Ruby?
|
177
|
+
no
|
147
178
|
=> false
|
148
179
|
|
149
180
|
> HighlineWrapper.new.ask_yes_no('Do you like Ruby?')
|
150
181
|
Do you like Ruby?
|
151
182
|
uh-huh
|
152
|
-
|
153
|
-
This question is required.
|
154
|
-
|
183
|
+
--- This question is required ---
|
155
184
|
Do you like Ruby?
|
156
|
-
|
157
|
-
|
185
|
+
yep
|
158
186
|
=> true
|
159
187
|
```
|
160
188
|
|
161
189
|
</details>
|
162
190
|
|
163
|
-
### Multiple choice
|
191
|
+
### Multiple choice questions
|
164
192
|
|
165
193
|
Question configuration options:
|
194
|
+
* `indicate_default_message`: defaults to `true`
|
166
195
|
* `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
196
|
* `default`: defaults to `nil`
|
168
197
|
* `required`: defaults to `false`
|
169
198
|
|
170
199
|
Notes:
|
200
|
+
* 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
201
|
* If `required` is `true`, the question will repeat until the user answers the question
|
172
202
|
* 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
203
|
* If `default` is `nil` and `required` is `false`, and the user skips the question, the answer will be `nil`
|
@@ -185,7 +215,6 @@ What is your favorite number of these?
|
|
185
215
|
2. two
|
186
216
|
3. three
|
187
217
|
2
|
188
|
-
|
189
218
|
=> {:value=>"two"}
|
190
219
|
|
191
220
|
> HighlineWrapper.new.ask_multiple_choice('What is your favorite number of these?', ['one', 'two', 'three'], {with_index: true})
|
@@ -194,15 +223,39 @@ What is your favorite number of these?
|
|
194
223
|
2. two
|
195
224
|
3. three
|
196
225
|
2
|
197
|
-
|
198
226
|
=> {:value=>"two", :index=>1}
|
199
227
|
|
228
|
+
> HighlineWrapper.new.ask_multiple_choice('What is your favorite number of these?', ['one', 'two', 'three'], {default: 'three', required: true, indicate_default_message: false})
|
229
|
+
What is your favorite number of these?
|
230
|
+
1. one
|
231
|
+
2. two
|
232
|
+
3. three
|
233
|
+
--- This question is required ---
|
234
|
+
What is your favorite number of these?
|
235
|
+
1. one
|
236
|
+
2. two
|
237
|
+
3. three
|
238
|
+
--- This question is required ---
|
239
|
+
What is your favorite number of these?
|
240
|
+
1. one
|
241
|
+
2. two
|
242
|
+
3. three
|
243
|
+
2
|
244
|
+
=> {:value=>"two"}
|
245
|
+
|
200
246
|
> HighlineWrapper.new.ask_multiple_choice('What is your favorite number of these?', ['one', 'two', 'three'], {with_index: true, default: 'one'})
|
201
247
|
What is your favorite number of these?
|
202
248
|
1. one
|
203
249
|
2. two
|
204
250
|
3. three
|
251
|
+
--- Default selected: 1. one ---
|
252
|
+
=> {:value=>"one", :index=>0}
|
205
253
|
|
254
|
+
> HighlineWrapper.new.ask_multiple_choice('What is your favorite number of these?', ['one', 'two', 'three'], {with_index: true, default: 'one', indicate_default_message: false})
|
255
|
+
What is your favorite number of these?
|
256
|
+
1. one
|
257
|
+
2. two
|
258
|
+
3. three
|
206
259
|
=> {:value=>"one", :index=>0}
|
207
260
|
|
208
261
|
> HighlineWrapper.new.ask_multiple_choice('What is your favorite number of these?', ['one', 'two', 'three'], {default: 'three', required: true})
|
@@ -210,51 +263,55 @@ What is your favorite number of these?
|
|
210
263
|
1. one
|
211
264
|
2. two
|
212
265
|
3. three
|
213
|
-
|
214
|
-
This question is required.
|
215
|
-
|
266
|
+
--- This question is required ---
|
216
267
|
What is your favorite number of these?
|
217
268
|
1. one
|
218
269
|
2. two
|
219
270
|
3. three
|
220
|
-
|
221
|
-
This question is required.
|
222
|
-
|
271
|
+
--- This question is required ---
|
223
272
|
What is your favorite number of these?
|
224
273
|
1. one
|
225
274
|
2. two
|
226
275
|
3. three
|
227
|
-
|
228
|
-
|
229
|
-
=> {:value=>"two"}
|
276
|
+
1
|
277
|
+
=> {:value=>"one"}
|
230
278
|
|
231
279
|
> HighlineWrapper.new.ask_multiple_choice('What is your favorite number of these?', ['one', 'two', 'three'], {default: nil})
|
232
280
|
What is your favorite number of these?
|
233
281
|
1. one
|
234
282
|
2. two
|
235
283
|
3. three
|
236
|
-
|
284
|
+
--- Default selected: EMPTY ---
|
237
285
|
=> nil
|
238
286
|
|
239
|
-
>
|
287
|
+
> HighlineWrapper.new.ask_multiple_choice('What is your favorite number of these?', ['one', 'two', 'three'], {default: nil, with_index: true})
|
240
288
|
What is your favorite number of these?
|
241
289
|
1. one
|
242
290
|
2. two
|
243
291
|
3. three
|
292
|
+
--- Default selected: EMPTY ---
|
293
|
+
=> nil
|
244
294
|
|
295
|
+
> HighlineWrapper.new.ask_multiple_choice('What is your favorite number of these?', ['one', 'two', 'three'], {default: nil, with_index: true, indicate_default_message: false})
|
296
|
+
What is your favorite number of these?
|
297
|
+
1. one
|
298
|
+
2. two
|
299
|
+
3. three
|
245
300
|
=> nil
|
246
301
|
```
|
247
302
|
|
248
303
|
</details>
|
249
304
|
|
250
|
-
### Multiple choice "checkbox"
|
305
|
+
### Multiple choice "checkbox" questions
|
251
306
|
|
252
307
|
Question configuration options:
|
308
|
+
* `indicate_default_message`: defaults to `true`
|
253
309
|
* `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
310
|
* `defaults`: defaults to `[]`
|
255
311
|
* `required`: defaults to `false`
|
256
312
|
|
257
313
|
Notes:
|
314
|
+
* 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
315
|
* If `required` is `true`, the question will repeat until the user answers the question
|
259
316
|
* 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
317
|
* If `defaults` is `[]` and `required` is `false`, then the method will return an empty array
|
@@ -272,7 +329,6 @@ What are your favorite numbers of these?
|
|
272
329
|
2. two
|
273
330
|
3. three
|
274
331
|
1, 3
|
275
|
-
|
276
332
|
=> [{:value=>"one"}, {:value=>"three"}]
|
277
333
|
|
278
334
|
> HighlineWrapper.new.ask_checkbox("What are your favorite numbers of these?", ['one', 'two','three'], {with_indexes: true})
|
@@ -281,15 +337,29 @@ What are your favorite numbers of these?
|
|
281
337
|
2. two
|
282
338
|
3. three
|
283
339
|
1, 3
|
284
|
-
|
285
340
|
=> [{:value=>"one", :index=>0}, {:value=>"three", :index=>2}]
|
286
341
|
|
287
|
-
> HighlineWrapper.new.ask_checkbox("What are your favorite numbers of these?", ['one', 'two','three'], {
|
342
|
+
> HighlineWrapper.new.ask_checkbox("What are your favorite numbers of these?", ['one', 'two','three'], {with_indexes: true, indicate_default_message: false})
|
343
|
+
What are your favorite numbers of these?
|
344
|
+
1. one
|
345
|
+
2. two
|
346
|
+
3. three
|
347
|
+
=> []
|
348
|
+
|
349
|
+
> HighlineWrapper.new.ask_checkbox("What are your favorite numbers of these?", ['one', 'two','three'], {with_indexes: true})
|
288
350
|
What are your favorite numbers of these?
|
289
351
|
1. one
|
290
352
|
2. two
|
291
353
|
3. three
|
354
|
+
--- Defaults selected: EMPTY ---
|
355
|
+
=> []
|
292
356
|
|
357
|
+
> HighlineWrapper.new.ask_checkbox("What are your favorite numbers of these?", ['one', 'two','three'], {defaults: ['two', 'three']})
|
358
|
+
What are your favorite numbers of these?
|
359
|
+
1. one
|
360
|
+
2. two
|
361
|
+
3. three
|
362
|
+
--- Defaults selected: 2. two, 3. three ---
|
293
363
|
=> [{:value=>"two"}, {:value=>"three"}]
|
294
364
|
|
295
365
|
> HighlineWrapper.new.ask_checkbox("What are your favorite numbers of these?", ['one', 'two','three'], {required: true, with_indexes: true})
|
@@ -297,15 +367,17 @@ What are your favorite numbers of these?
|
|
297
367
|
1. one
|
298
368
|
2. two
|
299
369
|
3. three
|
300
|
-
|
301
|
-
|
302
|
-
|
370
|
+
--- This question is required ---
|
371
|
+
What are your favorite numbers of these?
|
372
|
+
1. one
|
373
|
+
2. two
|
374
|
+
3. three
|
375
|
+
--- This question is required ---
|
303
376
|
What are your favorite numbers of these?
|
304
377
|
1. one
|
305
378
|
2. two
|
306
379
|
3. three
|
307
380
|
2
|
308
|
-
|
309
381
|
=> [{:value=>"two", :index=>1}]
|
310
382
|
|
311
383
|
> HighlineWrapper.new.ask_checkbox("What are your favorite numbers of these?", ['one', 'two','three'], {required: true, with_indexes: false})
|
@@ -313,39 +385,27 @@ What are your favorite numbers of these?
|
|
313
385
|
1. one
|
314
386
|
2. two
|
315
387
|
3. three
|
316
|
-
|
317
|
-
This question is required.
|
318
|
-
|
388
|
+
--- This question is required ---
|
319
389
|
What are your favorite numbers of these?
|
320
390
|
1. one
|
321
391
|
2. two
|
322
392
|
3. three
|
323
393
|
1
|
324
|
-
|
325
394
|
=> [{:value=>"one"}]
|
326
395
|
|
327
|
-
> HighlineWrapper.new.ask_checkbox("What are your favorite numbers of these?", ['one', 'two','three'], {defaults: []})
|
396
|
+
> HighlineWrapper.new.ask_checkbox("What are your favorite numbers of these?", ['one', 'two','three'], {defaults: ['two', 'three'], with_indexes: true, indicate_default_message: false})
|
328
397
|
What are your favorite numbers of these?
|
329
398
|
1. one
|
330
399
|
2. two
|
331
400
|
3. three
|
332
|
-
|
333
|
-
=> []
|
334
|
-
|
335
|
-
> HighlineWrapper.new.ask_checkbox("What are your favorite numbers of these?", ['one', 'two','three'], {defaults: [], with_indexes: true})
|
336
|
-
What are your favorite numbers of these?
|
337
|
-
1. one
|
338
|
-
2. two
|
339
|
-
3. three
|
340
|
-
|
341
|
-
=> []
|
401
|
+
=> [{:value=>"two", :index=>1}, {:value=>"three", :index=>2}]
|
342
402
|
```
|
343
403
|
|
344
404
|
</details>
|
345
405
|
|
346
406
|
## Tests
|
347
407
|
|
348
|
-
To run the tests, run `bundle exec rspec` from the command
|
408
|
+
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!
|
349
409
|
|
350
410
|
## Contributing
|
351
411
|
|
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,20 +7,24 @@ 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)
|
18
|
+
private def parse(answer, prompt, options)
|
19
19
|
return true if answer.include?('y')
|
20
20
|
return false if answer.include?('n')
|
21
21
|
|
22
22
|
recurse(prompt, nil, options)
|
23
23
|
end
|
24
|
+
|
25
|
+
private def print_default_message(options)
|
26
|
+
puts "--- Default selected: #{options[:default] ? 'YES' : 'NO'} ---"
|
27
|
+
end
|
24
28
|
end
|
25
29
|
end
|
26
30
|
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,6 +21,7 @@ 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
|
}
|
@@ -42,6 +43,12 @@ 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
|
45
52
|
end
|
46
53
|
|
47
54
|
context 'with required set to true' do
|
@@ -68,6 +75,7 @@ describe HighlineWrapper::YesNoQuestion do
|
|
68
75
|
context 'with required set to false' do
|
69
76
|
let(:options) do
|
70
77
|
{
|
78
|
+
indicate_default_message: false,
|
71
79
|
default: false,
|
72
80
|
required: false
|
73
81
|
}
|
@@ -84,5 +92,11 @@ describe HighlineWrapper::YesNoQuestion do
|
|
84
92
|
resp = subject.ask(Faker::Lorem.sentence, options)
|
85
93
|
expect(resp).to eq(false)
|
86
94
|
end
|
95
|
+
|
96
|
+
it 'should not call to print the default message' do
|
97
|
+
allow(highline).to receive(:ask).and_return('')
|
98
|
+
expect(subject).not_to receive(:print_default_message)
|
99
|
+
subject.ask(Faker::Lorem.sentence, options)
|
100
|
+
end
|
87
101
|
end
|
88
102
|
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.1.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-03-
|
11
|
+
date: 2021-03-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: highline
|