highline_wrapper 0.1.0 → 1.0.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 +100 -0
- data/README.md +269 -13
- data/lib/highline_wrapper.rb +82 -31
- data/lib/highline_wrapper/checkbox_question.rb +32 -0
- data/lib/highline_wrapper/multiple_choice_question.rb +20 -0
- data/lib/highline_wrapper/open_ended_question.rb +19 -0
- data/lib/highline_wrapper/question.rb +35 -0
- data/lib/highline_wrapper/version.rb +1 -1
- data/lib/highline_wrapper/yes_no_question.rb +26 -0
- data/spec/highline_wrapper/checkbox_question_spec.rb +188 -0
- data/spec/highline_wrapper/multiple_choice_question_spec.rb +188 -0
- data/spec/highline_wrapper/open_ended_question_spec.rb +94 -0
- data/spec/highline_wrapper/question_spec.rb +63 -0
- data/spec/highline_wrapper/yes_no_question_spec.rb +88 -0
- metadata +24 -11
- data/lib/highline_wrapper/client.rb +0 -68
- data/spec/highline_wrapper/client_spec.rb +0 -109
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2ce70d5eeb141d2b2440550b66335dc2e94a69acd4a0a214fea5dd78506b0bf8
|
4
|
+
data.tar.gz: e88f0e2c78bba7f92aec919a21326d75ac84b324c5ff3c0c2b5177346605bb62
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ae702cfaa01941f91f445145af9f4143a234f3ef9c41cec601454fa75a1b0268b9ffa70a2384b236472b916281e2dac38c8721791c5b1d7c60029b1b135949f2
|
7
|
+
data.tar.gz: 3891869ced3281e666861618dae0f43f81eff9f62c1a8cfd26d4e67758085585fe33595918b484fdf67fdf13ed1b7e013de82730229bf8c8d4fed39e5afc0981
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
highline_wrapper (1.0.0)
|
5
|
+
highline (~> 2.0)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
ast (2.4.2)
|
11
|
+
coderay (1.1.3)
|
12
|
+
concurrent-ruby (1.1.8)
|
13
|
+
diff-lcs (1.4.4)
|
14
|
+
faker (2.16.0)
|
15
|
+
i18n (>= 1.6, < 2)
|
16
|
+
ffi (1.14.2)
|
17
|
+
formatador (0.2.5)
|
18
|
+
guard (2.16.2)
|
19
|
+
formatador (>= 0.2.4)
|
20
|
+
listen (>= 2.7, < 4.0)
|
21
|
+
lumberjack (>= 1.0.12, < 2.0)
|
22
|
+
nenv (~> 0.1)
|
23
|
+
notiffany (~> 0.0)
|
24
|
+
pry (>= 0.9.12)
|
25
|
+
shellany (~> 0.0)
|
26
|
+
thor (>= 0.18.1)
|
27
|
+
guard-compat (1.2.1)
|
28
|
+
guard-rspec (4.7.3)
|
29
|
+
guard (~> 2.1)
|
30
|
+
guard-compat (~> 1.1)
|
31
|
+
rspec (>= 2.99.0, < 4.0)
|
32
|
+
highline (2.0.3)
|
33
|
+
i18n (1.8.9)
|
34
|
+
concurrent-ruby (~> 1.0)
|
35
|
+
listen (3.4.1)
|
36
|
+
rb-fsevent (~> 0.10, >= 0.10.3)
|
37
|
+
rb-inotify (~> 0.9, >= 0.9.10)
|
38
|
+
lumberjack (1.2.8)
|
39
|
+
method_source (1.0.0)
|
40
|
+
nenv (0.3.0)
|
41
|
+
notiffany (0.1.3)
|
42
|
+
nenv (~> 0.1)
|
43
|
+
shellany (~> 0.0)
|
44
|
+
parallel (1.20.1)
|
45
|
+
parser (3.0.0.0)
|
46
|
+
ast (~> 2.4.1)
|
47
|
+
pry (0.14.0)
|
48
|
+
coderay (~> 1.1)
|
49
|
+
method_source (~> 1.0)
|
50
|
+
rainbow (3.0.0)
|
51
|
+
rake (13.0.3)
|
52
|
+
rb-fsevent (0.10.4)
|
53
|
+
rb-inotify (0.10.1)
|
54
|
+
ffi (~> 1.0)
|
55
|
+
regexp_parser (2.1.1)
|
56
|
+
rexml (3.2.4)
|
57
|
+
rspec (3.10.0)
|
58
|
+
rspec-core (~> 3.10.0)
|
59
|
+
rspec-expectations (~> 3.10.0)
|
60
|
+
rspec-mocks (~> 3.10.0)
|
61
|
+
rspec-core (3.10.1)
|
62
|
+
rspec-support (~> 3.10.0)
|
63
|
+
rspec-expectations (3.10.1)
|
64
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
65
|
+
rspec-support (~> 3.10.0)
|
66
|
+
rspec-mocks (3.10.2)
|
67
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
68
|
+
rspec-support (~> 3.10.0)
|
69
|
+
rspec-support (3.10.2)
|
70
|
+
rubocop (1.11.0)
|
71
|
+
parallel (~> 1.10)
|
72
|
+
parser (>= 3.0.0.0)
|
73
|
+
rainbow (>= 2.2.2, < 4.0)
|
74
|
+
regexp_parser (>= 1.8, < 3.0)
|
75
|
+
rexml
|
76
|
+
rubocop-ast (>= 1.2.0, < 2.0)
|
77
|
+
ruby-progressbar (~> 1.7)
|
78
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
79
|
+
rubocop-ast (1.4.1)
|
80
|
+
parser (>= 2.7.1.5)
|
81
|
+
ruby-progressbar (1.11.0)
|
82
|
+
shellany (0.0.1)
|
83
|
+
thor (1.1.0)
|
84
|
+
unicode-display_width (2.0.0)
|
85
|
+
|
86
|
+
PLATFORMS
|
87
|
+
x86_64-darwin-20
|
88
|
+
|
89
|
+
DEPENDENCIES
|
90
|
+
bundler (~> 2.2)
|
91
|
+
faker (~> 2.15)
|
92
|
+
guard-rspec (~> 4.3)
|
93
|
+
highline_wrapper!
|
94
|
+
pry (~> 0.13)
|
95
|
+
rake (~> 13.0)
|
96
|
+
rspec (~> 3.9)
|
97
|
+
rubocop (~> 1.10)
|
98
|
+
|
99
|
+
BUNDLED WITH
|
100
|
+
2.2.4
|
data/README.md
CHANGED
@@ -27,7 +27,7 @@ Or install it yourself as:
|
|
27
27
|
gem install highline_wrapper
|
28
28
|
```
|
29
29
|
|
30
|
-
|
30
|
+
## Usage
|
31
31
|
|
32
32
|
Once this gem is installed, you can then initiate a new `HighlineWrapper` object:
|
33
33
|
|
@@ -41,53 +41,309 @@ Then, add this to the top of your file (or to your gem):
|
|
41
41
|
require 'highline_wrapper'
|
42
42
|
```
|
43
43
|
|
44
|
-
Then, you can call its questions to receive answers
|
44
|
+
Then, you can call its questions to receive answers. There's several configuration options for each type of question. Look below for the different options for each type of question, and what they each return.
|
45
|
+
|
46
|
+
### Open-ended questions
|
47
|
+
|
48
|
+
Question configuration options:
|
49
|
+
* `secret`: defaults to `false`
|
50
|
+
* `default`: defaults to `''`
|
51
|
+
* `required`: defaults to `false`
|
52
|
+
|
53
|
+
<details><summary>Examples</summary>
|
45
54
|
|
46
55
|
```ruby
|
47
56
|
> HighlineWrapper.new.ask('What is your favorite number?')
|
48
57
|
What is your favorite number?
|
49
58
|
four
|
59
|
+
|
50
60
|
=> "four"
|
51
61
|
|
62
|
+
> HighlineWrapper.new.ask('What is your favorite number?', {required: true})
|
63
|
+
What is your favorite number?
|
64
|
+
|
65
|
+
This question is required.
|
66
|
+
|
67
|
+
What is your favorite number?
|
68
|
+
|
69
|
+
This question is required.
|
70
|
+
|
71
|
+
What is your favorite number?
|
72
|
+
2
|
73
|
+
|
74
|
+
=> "2"
|
75
|
+
|
76
|
+
> HighlineWrapper.new.ask('What is your favorite color?')
|
77
|
+
What is your favorite color?
|
78
|
+
|
79
|
+
=> ""
|
80
|
+
|
81
|
+
> HighlineWrapper.new.ask('What is your favorite color?', {default: 'orange'})
|
82
|
+
What is your favorite color?
|
83
|
+
|
84
|
+
=> "orange"
|
85
|
+
|
86
|
+
> HighlineWrapper.new.ask('Please type your private token:', {secret: true})
|
87
|
+
Please type your private token?
|
88
|
+
****************
|
89
|
+
|
90
|
+
=> "MY-PRIVATE-TOKEN"
|
91
|
+
|
92
|
+
> HighlineWrapper.new.ask('What is your private token?', {secret: true, required: true})
|
93
|
+
What is your private token?
|
94
|
+
|
95
|
+
This question is required.
|
96
|
+
|
97
|
+
What is your private token?
|
98
|
+
|
99
|
+
This question is required.
|
100
|
+
|
101
|
+
What is your private token?
|
102
|
+
|
103
|
+
This question is required.
|
104
|
+
|
105
|
+
What is your private token?
|
106
|
+
****************
|
107
|
+
|
108
|
+
=> "MY-PRIVATE-TOKEN"
|
109
|
+
```
|
110
|
+
|
111
|
+
</details>
|
112
|
+
|
113
|
+
### Yes/No questions
|
114
|
+
|
115
|
+
Question configuration options:
|
116
|
+
* `default`: defaults to `true` (aka 'yes')
|
117
|
+
* `required`: defaults to `false`
|
118
|
+
|
119
|
+
<details><summary>Examples</summary>
|
120
|
+
|
121
|
+
```ruby
|
52
122
|
> HighlineWrapper.new.ask_yes_no('Do you like Ruby?')
|
53
123
|
Do you like Ruby?
|
54
124
|
no
|
125
|
+
|
55
126
|
=> false
|
56
127
|
|
57
128
|
> HighlineWrapper.new.ask_yes_no('Do you like Ruby?')
|
58
129
|
Do you like Ruby?
|
59
130
|
yes
|
131
|
+
|
60
132
|
=> true
|
61
133
|
|
62
|
-
HighlineWrapper.new.
|
63
|
-
|
134
|
+
> HighlineWrapper.new.ask_yes_no('Do you like Ruby?', {default: false})
|
135
|
+
Do you like Ruby?
|
136
|
+
|
137
|
+
=> false
|
138
|
+
|
139
|
+
> HighlineWrapper.new.ask_yes_no('Do you like Ruby?', {required: true})
|
140
|
+
Do you like Ruby?
|
141
|
+
|
142
|
+
This question is required.
|
143
|
+
|
144
|
+
Do you like Ruby?
|
145
|
+
No
|
146
|
+
|
147
|
+
=> false
|
148
|
+
|
149
|
+
> HighlineWrapper.new.ask_yes_no('Do you like Ruby?')
|
150
|
+
Do you like Ruby?
|
151
|
+
uh-huh
|
152
|
+
|
153
|
+
This question is required.
|
154
|
+
|
155
|
+
Do you like Ruby?
|
156
|
+
YES
|
157
|
+
|
158
|
+
=> true
|
159
|
+
```
|
160
|
+
|
161
|
+
</details>
|
162
|
+
|
163
|
+
### Multiple choice question
|
164
|
+
|
165
|
+
Question configuration options:
|
166
|
+
* `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
|
+
* `default`: defaults to `nil`
|
168
|
+
* `required`: defaults to `false`
|
169
|
+
|
170
|
+
Notes:
|
171
|
+
* If `required` is `true`, the question will repeat until the user answers the question
|
172
|
+
* 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
|
+
* If `default` is `nil` and `required` is `false`, and the user skips the question, the answer will be `nil`
|
174
|
+
* If `with_index` is `true`, a hash will be returned with the choice AND the index of the selection in the original `choices` array
|
175
|
+
* e.g. `{ value: 'c', index: 2 }`
|
176
|
+
* If `with_index` is `false`, then a hash of one item will be returned
|
177
|
+
* e.g. `{ value: 'c' }`
|
178
|
+
|
179
|
+
<details><summary>Examples</summary>
|
180
|
+
|
181
|
+
```ruby
|
182
|
+
> HighlineWrapper.new.ask_multiple_choice('What is your favorite number of these?', ['one', 'two', 'three'])
|
183
|
+
What is your favorite number of these?
|
184
|
+
1. one
|
185
|
+
2. two
|
186
|
+
3. three
|
187
|
+
2
|
188
|
+
|
189
|
+
=> {:value=>"two"}
|
190
|
+
|
191
|
+
> HighlineWrapper.new.ask_multiple_choice('What is your favorite number of these?', ['one', 'two', 'three'], {with_index: true})
|
64
192
|
What is your favorite number of these?
|
65
193
|
1. one
|
66
194
|
2. two
|
67
195
|
3. three
|
68
196
|
2
|
69
|
-
=> "two"
|
70
197
|
|
71
|
-
|
72
|
-
|
198
|
+
=> {:value=>"two", :index=>1}
|
199
|
+
|
200
|
+
> HighlineWrapper.new.ask_multiple_choice('What is your favorite number of these?', ['one', 'two', 'three'], {with_index: true, default: 'one'})
|
201
|
+
What is your favorite number of these?
|
202
|
+
1. one
|
203
|
+
2. two
|
204
|
+
3. three
|
205
|
+
|
206
|
+
=> {:value=>"one", :index=>0}
|
207
|
+
|
208
|
+
> HighlineWrapper.new.ask_multiple_choice('What is your favorite number of these?', ['one', 'two', 'three'], {default: 'three', required: true})
|
209
|
+
What is your favorite number of these?
|
210
|
+
1. one
|
211
|
+
2. two
|
212
|
+
3. three
|
213
|
+
|
214
|
+
This question is required.
|
215
|
+
|
216
|
+
What is your favorite number of these?
|
217
|
+
1. one
|
218
|
+
2. two
|
219
|
+
3. three
|
220
|
+
|
221
|
+
This question is required.
|
222
|
+
|
223
|
+
What is your favorite number of these?
|
224
|
+
1. one
|
225
|
+
2. two
|
226
|
+
3. three
|
227
|
+
2
|
228
|
+
|
229
|
+
=> {:value=>"two"}
|
230
|
+
|
231
|
+
> HighlineWrapper.new.ask_multiple_choice('What is your favorite number of these?', ['one', 'two', 'three'], {default: nil})
|
232
|
+
What is your favorite number of these?
|
233
|
+
1. one
|
234
|
+
2. two
|
235
|
+
3. three
|
236
|
+
|
237
|
+
=> nil
|
238
|
+
|
239
|
+
> HighlineWrapper.new.ask_multiple_choice('What is your favorite number of these?', ['one', 'two', 'three'], {default: nil, with_index: true})
|
240
|
+
What is your favorite number of these?
|
241
|
+
1. one
|
242
|
+
2. two
|
243
|
+
3. three
|
244
|
+
|
245
|
+
=> nil
|
246
|
+
```
|
247
|
+
|
248
|
+
</details>
|
249
|
+
|
250
|
+
### Multiple choice "checkbox" question
|
251
|
+
|
252
|
+
Question configuration options:
|
253
|
+
* `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
|
+
* `defaults`: defaults to `[]`
|
255
|
+
* `required`: defaults to `false`
|
256
|
+
|
257
|
+
Notes:
|
258
|
+
* If `required` is `true`, the question will repeat until the user answers the question
|
259
|
+
* 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
|
+
* If `defaults` is `[]` and `required` is `false`, then the method will return an empty array
|
261
|
+
* If `with_indexes` is `true`, an array of hashes will be returned with the choice AND the index (of the selection in the original `choices` array) in each hash
|
262
|
+
* e.g. `[{ value: 'a', index: 0 }, { value: 'c', index: 2 }]`
|
263
|
+
* If `with_indexes` is `false`, then an hashes will be returned where each hash only has a value
|
264
|
+
* e.g. `[{ value: 'a' }, { value: 'c' }]`
|
265
|
+
|
266
|
+
<details><summary>Examples</summary>
|
267
|
+
|
268
|
+
```ruby
|
269
|
+
> HighlineWrapper.new.ask_checkbox("What are your favorite numbers of these?", ['one', 'two','three'])
|
73
270
|
What are your favorite numbers of these?
|
74
271
|
1. one
|
75
272
|
2. two
|
76
273
|
3. three
|
77
|
-
1,3
|
78
|
-
|
274
|
+
1, 3
|
275
|
+
|
276
|
+
=> [{:value=>"one"}, {:value=>"three"}]
|
79
277
|
|
80
|
-
> HighlineWrapper.new.ask_checkbox("What are your favorite numbers of these?
|
81
|
-
", ['one', 'two','three'], with_indexes: true)
|
278
|
+
> HighlineWrapper.new.ask_checkbox("What are your favorite numbers of these?", ['one', 'two','three'], {with_indexes: true})
|
82
279
|
What are your favorite numbers of these?
|
83
280
|
1. one
|
84
281
|
2. two
|
85
282
|
3. three
|
86
283
|
1, 3
|
87
|
-
|
284
|
+
|
285
|
+
=> [{:value=>"one", :index=>0}, {:value=>"three", :index=>2}]
|
286
|
+
|
287
|
+
> HighlineWrapper.new.ask_checkbox("What are your favorite numbers of these?", ['one', 'two','three'], {defaults: ['two', 'three']})
|
288
|
+
What are your favorite numbers of these?
|
289
|
+
1. one
|
290
|
+
2. two
|
291
|
+
3. three
|
292
|
+
|
293
|
+
=> [{:value=>"two"}, {:value=>"three"}]
|
294
|
+
|
295
|
+
> HighlineWrapper.new.ask_checkbox("What are your favorite numbers of these?", ['one', 'two','three'], {required: true, with_indexes: true})
|
296
|
+
What are your favorite numbers of these?
|
297
|
+
1. one
|
298
|
+
2. two
|
299
|
+
3. three
|
300
|
+
|
301
|
+
This question is required.
|
302
|
+
|
303
|
+
What are your favorite numbers of these?
|
304
|
+
1. one
|
305
|
+
2. two
|
306
|
+
3. three
|
307
|
+
2
|
308
|
+
|
309
|
+
=> [{:value=>"two", :index=>1}]
|
310
|
+
|
311
|
+
> HighlineWrapper.new.ask_checkbox("What are your favorite numbers of these?", ['one', 'two','three'], {required: true, with_indexes: false})
|
312
|
+
What are your favorite numbers of these?
|
313
|
+
1. one
|
314
|
+
2. two
|
315
|
+
3. three
|
316
|
+
|
317
|
+
This question is required.
|
318
|
+
|
319
|
+
What are your favorite numbers of these?
|
320
|
+
1. one
|
321
|
+
2. two
|
322
|
+
3. three
|
323
|
+
1
|
324
|
+
|
325
|
+
=> [{:value=>"one"}]
|
326
|
+
|
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})
|
336
|
+
What are your favorite numbers of these?
|
337
|
+
1. one
|
338
|
+
2. two
|
339
|
+
3. three
|
340
|
+
|
341
|
+
=> []
|
88
342
|
```
|
89
343
|
|
90
|
-
|
344
|
+
</details>
|
345
|
+
|
346
|
+
## Tests
|
91
347
|
|
92
348
|
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!
|
93
349
|
|
data/lib/highline_wrapper.rb
CHANGED
@@ -9,42 +9,93 @@ Dir[files].each do |file|
|
|
9
9
|
end
|
10
10
|
|
11
11
|
class HighlineWrapper
|
12
|
-
# Returns
|
13
|
-
#
|
14
|
-
|
15
|
-
|
12
|
+
# Returns: the answer to the question (string)
|
13
|
+
#
|
14
|
+
# prompt: the prompt for the question (string)
|
15
|
+
# options: various options to pass to the questions (hash)
|
16
|
+
# secret: whether the terminal should hide the typed value (boolean - defaults to false)
|
17
|
+
# default: the default selection (string - defaults to '')
|
18
|
+
# 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
|
+
def ask(prompt, options = {})
|
24
|
+
defaults = {
|
25
|
+
secret: false,
|
26
|
+
default: '',
|
27
|
+
required: false
|
28
|
+
}
|
29
|
+
options = defaults.merge(options)
|
30
|
+
HighlineWrapper::OpenEndedQuestion.ask(prompt, options)
|
16
31
|
end
|
17
32
|
|
18
|
-
# Returns
|
19
|
-
#
|
20
|
-
#
|
21
|
-
|
22
|
-
|
33
|
+
# Returns: yes for true, no for false (boolean)
|
34
|
+
#
|
35
|
+
# prompt: the prompt for the question (string)
|
36
|
+
# options: various options to pass to the questions (hash)
|
37
|
+
# default: the default selection (boolean - defaults to true)
|
38
|
+
# 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
|
+
def ask_yes_no(prompt, options = {})
|
44
|
+
defaults = {
|
45
|
+
default: true,
|
46
|
+
required: false
|
47
|
+
}
|
48
|
+
options = defaults.merge(options)
|
49
|
+
HighlineWrapper::YesNoQuestion.ask(prompt, options)
|
23
50
|
end
|
24
51
|
|
25
|
-
# Returns
|
26
|
-
# e.g. 'c'
|
27
|
-
#
|
28
|
-
#
|
29
|
-
#
|
30
|
-
#
|
31
|
-
#
|
32
|
-
|
33
|
-
|
52
|
+
# Returns: the selection in a hash (hash)
|
53
|
+
# e.g. { value: 'c' }
|
54
|
+
# e.g. { value: 'c', index: 2 }
|
55
|
+
#
|
56
|
+
# prompt: the prompt for the question (string)
|
57
|
+
# choices: a list of string options (array) (e.g. [ 'a', 'b', 'c' ])
|
58
|
+
# options: various options to pass to the questions (hash)
|
59
|
+
# with_index: whether to return the index of the selection (boolean - defaults to false)
|
60
|
+
# default: the default selection if the user skips the question (string - defaults to nil)
|
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
|
+
def ask_multiple_choice(prompt, choices, options = {})
|
68
|
+
defaults = {
|
69
|
+
with_index: false,
|
70
|
+
default: nil,
|
71
|
+
required: false
|
72
|
+
}
|
73
|
+
options = defaults.merge(options)
|
74
|
+
HighlineWrapper::MultipleChoiceQuestion.ask(prompt, choices, options)
|
34
75
|
end
|
35
76
|
|
36
|
-
# Returns
|
37
|
-
# e.g. [ 'a', 'c' ]
|
38
|
-
#
|
39
|
-
#
|
40
|
-
#
|
41
|
-
#
|
42
|
-
#
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
77
|
+
# Returns: the selections chosen as an array of hashes (array)
|
78
|
+
# e.g. [{ value: 'a' }, { value: 'c' }]
|
79
|
+
# e.g. [{ value: 'a', index: 0 }, { value: 'c', index: 2 }])
|
80
|
+
#
|
81
|
+
# prompt: the prompt for the question (string)
|
82
|
+
# choices: a list of string options (array) (e.g. [ 'a', 'b', 'c' ])
|
83
|
+
# options: various options to pass to the questions (hash)
|
84
|
+
# with_indexes: whether to return the indexes of the selections (boolean - defaults to false)
|
85
|
+
# defaults: the default selections if the user skips the question (array - defaults to [])
|
86
|
+
# 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
|
+
def ask_checkbox(prompt, choices, options = {})
|
93
|
+
defaults = {
|
94
|
+
with_indexes: false,
|
95
|
+
defaults: [],
|
96
|
+
required: false
|
97
|
+
}
|
98
|
+
options = defaults.merge(options)
|
99
|
+
HighlineWrapper::CheckboxQuestion.ask(prompt, choices, options)
|
49
100
|
end
|
50
101
|
end
|