highline_wrapper 0.1.0 → 1.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0454ae57461089fa8b01bd5174e89e8eb71dc41c110a82bb86f4473f345bafdf
4
- data.tar.gz: 34dba9a54d461b365da6de34bbd1c20611bec926df54699c2673306a9eb82828
3
+ metadata.gz: d0386ba9a8b59066ee480db64c43883461107598bc2305c524c0cbe4e5f036f9
4
+ data.tar.gz: 4aced242f9477147f29bf870f04caf1573eafc707ccd97be87282381713e8831
5
5
  SHA512:
6
- metadata.gz: 513c0869cf6ac26663fcab9e65cb01897875fcdd4a9d31ff9ff890728a9004a26f1503c94c374e363d99b6e1649931427c121f4a10638120cbec11e9efdd78a8
7
- data.tar.gz: 85e805046f5d586303ea0286ab810d974d6a3466e57e0c794f3d61771e9a67cebf17039100490841c1716d16b79b9c88b1a0c62bea818ec73c6bdd660aaecc24
6
+ metadata.gz: d756e947239db890942a54cc1ea1cbecc71e7149ee247f6ae58e6f3345a5f2adc32320433b99f68d3911cad59b9590742c67c0d1b3b9cb02787a28f98ca424f0
7
+ data.tar.gz: dbe4663597f917865b9ad062a646d9d46302024a365efc578d7438b8b081f4cafc6f79c45fe9db188c91acbb5d2af853fd31b1316caded14663934117d59eced
data/LICENSE.md ADDED
@@ -0,0 +1,11 @@
1
+ Copyright (c) 2021 Emma Sax. All rights reserved.
2
+
3
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
4
+
5
+ 1. Redistributions of source code must retain the above copyright notice, this list of conditions, and the following disclaimer.
6
+
7
+ 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions, and the following disclaimer in the documentation and/or other materials provided with the distribution.
8
+
9
+ 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
10
+
11
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.md CHANGED
@@ -27,7 +27,7 @@ Or install it yourself as:
27
27
  gem install highline_wrapper
28
28
  ```
29
29
 
30
- ### Usage
30
+ ## Usage
31
31
 
32
32
  Once this gem is installed, you can then initiate a new `HighlineWrapper` object:
33
33
 
@@ -41,7 +41,25 @@ 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
+ * `indicate_default_message`: defaults to `true`
50
+ * `secret`: defaults to `false`
51
+ * `default`: defaults to `''`
52
+ * `required`: defaults to `false`
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
+
62
+ <details><summary>Examples</summary>
45
63
 
46
64
  ```ruby
47
65
  > HighlineWrapper.new.ask('What is your favorite number?')
@@ -49,57 +67,374 @@ What is your favorite number?
49
67
  four
50
68
  => "four"
51
69
 
70
+ > HighlineWrapper.new.ask('What is your favorite number?', {required: true})
71
+ What is your favorite number?
72
+ --- This question is required ---
73
+ What is your favorite number?
74
+ --- This question is required ---
75
+ What is your favorite number?
76
+ --- This question is required ---
77
+ What is your favorite number?
78
+ 2
79
+ => "2"
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
+
94
+ > HighlineWrapper.new.ask('What is your favorite color?')
95
+ What is your favorite color?
96
+ --- Default selected: EMPTY ---
97
+ => ""
98
+
99
+ > HighlineWrapper.new.ask('What is your favorite color?', {default: 'orange'})
100
+ What is your favorite color?
101
+ --- Default selected: orange ---
102
+ => "orange"
103
+
104
+ > HighlineWrapper.new.ask('Please type your private token:', {secret: true})
105
+ Please type your private token?
106
+ ****************
107
+ => "MY-PRIVATE-TOKEN"
108
+
109
+ > HighlineWrapper.new.ask('Please type your private token:', {secret: true, indicate_default_message: false})
110
+ Please type your private token:
111
+
112
+ => ""
113
+
114
+ > HighlineWrapper.new.ask('Please type your private token:', {secret: true, required: true})
115
+ Please type your private token:
116
+
117
+ --- This question is required ---
118
+ Please type your private token:
119
+
120
+ --- This question is required ---
121
+ Please type your private token:
122
+ ****************
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
+ => ""
130
+ ```
131
+
132
+ </details>
133
+
134
+ ### Yes/No questions
135
+
136
+ Question configuration options:
137
+ * `indicate_default_message`: defaults to `true`
138
+ * `default`: defaults to `true` (aka 'yes')
139
+ * `required`: defaults to `false`
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
+
148
+ <details><summary>Examples</summary>
149
+
150
+ ```ruby
151
+ > HighlineWrapper.new.ask_yes_no('Do you like Ruby?')
152
+ Do you like Ruby?
153
+ --- Default selected: YES ---
154
+ => true
155
+
156
+ > HighlineWrapper.new.ask_yes_no('Do you like Ruby?', {indicate_default_message: false})
157
+ Do you like Ruby?
158
+ => true
159
+
52
160
  > HighlineWrapper.new.ask_yes_no('Do you like Ruby?')
53
161
  Do you like Ruby?
54
162
  no
55
163
  => false
56
164
 
165
+ > HighlineWrapper.new.ask_yes_no('Do you like Ruby?', {default: false})
166
+ Do you like Ruby?
167
+ --- Default selected: NO ---
168
+ => false
169
+
170
+ > HighlineWrapper.new.ask_yes_no('Do you like Ruby?', {required: true})
171
+ Do you like Ruby?
172
+ --- This question is required ---
173
+ Do you like Ruby?
174
+ --- This question is required ---
175
+ Do you like Ruby?
176
+ --- This question is required ---
177
+ Do you like Ruby?
178
+ N
179
+ => false
180
+
57
181
  > HighlineWrapper.new.ask_yes_no('Do you like Ruby?')
58
182
  Do you like Ruby?
183
+ uh-huh
184
+ --- This question is required ---
185
+ Do you like Ruby?
186
+ YES
187
+ => true
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?
59
194
  yes
60
195
  => true
196
+ ```
197
+
198
+ </details>
199
+
200
+ ### Multiple choice questions
201
+
202
+ Question configuration options:
203
+ * `indicate_default_message`: defaults to `true`
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)
205
+ * `default`: defaults to `nil`
206
+ * `required`: defaults to `false`
207
+
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
210
+ * If `required` is `true`, the question will repeat until the user answers the question
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)
212
+ * If `default` is `nil` and `required` is `false`, and the user skips the question, the answer will be `nil`
213
+ * If `with_index` is `true`, a hash will be returned with the choice AND the index of the selection in the original `choices` array
214
+ * e.g. `{ value: 'c', index: 2 }`
215
+ * If `with_index` is `false`, then a hash of one item will be returned
216
+ * e.g. `{ value: 'c' }`
217
+
218
+ <details><summary>Examples</summary>
219
+
220
+ ```ruby
221
+ > HighlineWrapper.new.ask_multiple_choice('What is your favorite number of these?', ['one', 'two', 'three'])
222
+ What is your favorite number of these?
223
+ 1. one
224
+ 2. two
225
+ 3. three
226
+ 2
227
+ => {:value=>"two"}
61
228
 
62
- HighlineWrapper.new.ask_multiple_choice('What is your favorite number of t
63
- hese?', ['one', 'two', 'three'])
229
+ > HighlineWrapper.new.ask_multiple_choice('What is your favorite number of these?', ['one', 'two', 'three'], {with_index: true})
230
+ What is your favorite number of these?
231
+ 1. one
232
+ 2. two
233
+ 3. three
234
+ 2
235
+ => {:value=>"two", :index=>1}
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 ---
64
248
  What is your favorite number of these?
65
249
  1. one
66
250
  2. two
67
251
  3. three
68
252
  2
69
- => "two"
253
+ => {:value=>"two"}
70
254
 
71
- > HighlineWrapper.new.ask_checkbox("What are your favorite numbers of these?
72
- ", ['one', 'two','three'])
255
+ > HighlineWrapper.new.ask_multiple_choice('What is your favorite number of these?', ['one', 'two', 'three'], {with_index: true, default: 'one'})
256
+ What is your favorite number of these?
257
+ 1. one
258
+ 2. two
259
+ 3. three
260
+ --- Default selected: 1. one ---
261
+ => {:value=>"one", :index=>0}
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
268
+ => {:value=>"one", :index=>0}
269
+
270
+ > HighlineWrapper.new.ask_multiple_choice('What is your favorite number of these?', ['one', 'two', 'three'], {default: 'three', required: true})
271
+ What is your favorite number of these?
272
+ 1. one
273
+ 2. two
274
+ 3. three
275
+ --- This question is required ---
276
+ What is your favorite number of these?
277
+ 1. one
278
+ 2. two
279
+ 3. three
280
+ --- This question is required ---
281
+ What is your favorite number of these?
282
+ 1. one
283
+ 2. two
284
+ 3. three
285
+ 1
286
+ => {:value=>"one"}
287
+
288
+ > HighlineWrapper.new.ask_multiple_choice('What is your favorite number of these?', ['one', 'two', 'three'], {default: nil})
289
+ What is your favorite number of these?
290
+ 1. one
291
+ 2. two
292
+ 3. three
293
+ --- Default selected: EMPTY ---
294
+ => nil
295
+
296
+ > HighlineWrapper.new.ask_multiple_choice('What is your favorite number of these?', ['one', 'two', 'three'], {default: nil, with_index: true})
297
+ What is your favorite number of these?
298
+ 1. one
299
+ 2. two
300
+ 3. three
301
+ --- Default selected: EMPTY ---
302
+ => nil
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
309
+ => nil
310
+ ```
311
+
312
+ </details>
313
+
314
+ ### Multiple choice "checkbox" questions
315
+
316
+ Question configuration options:
317
+ * `indicate_default_message`: defaults to `true`
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)
319
+ * `defaults`: defaults to `[]`
320
+ * `required`: defaults to `false`
321
+
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
324
+ * If `required` is `true`, the question will repeat until the user answers the question
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)
326
+ * If `defaults` is `[]` and `required` is `false`, then the method will return an empty array
327
+ * 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
328
+ * e.g. `[{ value: 'a', index: 0 }, { value: 'c', index: 2 }]`
329
+ * If `with_indexes` is `false`, then an hashes will be returned where each hash only has a value
330
+ * e.g. `[{ value: 'a' }, { value: 'c' }]`
331
+
332
+ <details><summary>Examples</summary>
333
+
334
+ ```ruby
335
+ > HighlineWrapper.new.ask_checkbox("What are your favorite numbers of these?", ['one', 'two','three'])
73
336
  What are your favorite numbers of these?
74
337
  1. one
75
338
  2. two
76
339
  3. three
77
- 1,3
78
- => ["one", "three"]
340
+ 1, 3
341
+ => [{:value=>"one"}, {:value=>"three"}]
79
342
 
80
- > HighlineWrapper.new.ask_checkbox("What are your favorite numbers of these?
81
- ", ['one', 'two','three'], with_indexes: true)
343
+ > HighlineWrapper.new.ask_checkbox("What are your favorite numbers of these?", ['one', 'two','three'], {with_indexes: true})
82
344
  What are your favorite numbers of these?
83
345
  1. one
84
346
  2. two
85
347
  3. three
86
348
  1, 3
87
- => [{:choice=>"one", :index=>0}, {:choice=>"three", :index=>2}]
349
+ => [{:value=>"one", :index=>0}, {:value=>"three", :index=>2}]
350
+
351
+ > HighlineWrapper.new.ask_checkbox("What are your favorite numbers of these?", ['one', 'two','three'], {with_indexes: true, indicate_default_message: false})
352
+ What are your favorite numbers of these?
353
+ 1. one
354
+ 2. two
355
+ 3. three
356
+ => []
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 ---
372
+ => [{:value=>"two"}, {:value=>"three"}]
373
+
374
+ > HighlineWrapper.new.ask_checkbox("What are your favorite numbers of these?", ['one', 'two','three'], {required: true, with_indexes: true})
375
+ What are your favorite numbers of these?
376
+ 1. one
377
+ 2. two
378
+ 3. three
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 ---
385
+ What are your favorite numbers of these?
386
+ 1. one
387
+ 2. two
388
+ 3. three
389
+ 2
390
+ => [{:value=>"two", :index=>1}]
391
+
392
+ > HighlineWrapper.new.ask_checkbox("What are your favorite numbers of these?", ['one', 'two','three'], {required: true, with_indexes: false})
393
+ What are your favorite numbers of these?
394
+ 1. one
395
+ 2. two
396
+ 3. three
397
+ --- This question is required ---
398
+ What are your favorite numbers of these?
399
+ 1. one
400
+ 2. two
401
+ 3. three
402
+ 1
403
+ => [{:value=>"one"}]
404
+
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})
406
+ What are your favorite numbers of these?
407
+ 1. one
408
+ 2. two
409
+ 3. three
410
+ => [{:value=>"two", :index=>1}, {:value=>"three", :index=>2}]
88
411
  ```
89
412
 
90
- ### Tests
413
+ </details>
414
+
415
+ ## Tests
91
416
 
92
- 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!
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!
93
418
 
94
- ## Contributing
419
+ ---
420
+
421
+ ### Contributing
95
422
 
96
423
  To submit a feature request, bug ticket, etc, please submit an official [GitHub Issue](https://github.com/emmahsax/highline_wrapper/issues/new).
97
424
 
98
- To report any security vulnerabilities, please view this project's [Security Policy](https://github.com/emmahsax/highline_wrapper/security/policy).
425
+ ### Security Policy
426
+
427
+ To report any security vulnerabilities, please view this repository's [Security Policy](https://github.com/emmahsax/highline_wrapper/security/policy).
428
+
429
+ ### Licensing
430
+
431
+ For information on licensing, please see [LICENSE.md](https://github.com/emmahsax/highline_wrapper/blob/main/LICENSE.md).
432
+
433
+ ### Code of Conduct
99
434
 
100
435
  When interacting with this repository, please follow [Contributor Covenant's Code of Conduct](https://contributor-covenant.org).
101
436
 
102
- ## Releasing
437
+ ### Releasing
103
438
 
104
439
  To make a new release of this gem:
105
440
 
@@ -9,42 +9,87 @@ Dir[files].each do |file|
9
9
  end
10
10
 
11
11
  class HighlineWrapper
12
- # Returns - string; the answer to the question
13
- # prompt - string; the prompt for the question
14
- def ask(prompt, secret: false)
15
- client.ask(prompt, secret)
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
+ # indicate_default_message: whether to tell the terminal what the default value selected is if the question
17
+ # is skipped (boolean - defaults to true)
18
+ # secret: whether the terminal should hide the typed value (boolean - defaults to false)
19
+ # default: the default selection (string - defaults to '')
20
+ # required: whether the question is required or not (boolean - defaults to false)
21
+ def ask(prompt, options = {})
22
+ defaults = {
23
+ indicate_default_message: true,
24
+ secret: false,
25
+ default: '',
26
+ required: false
27
+ }
28
+ options = defaults.merge(options)
29
+ HighlineWrapper::OpenEndedQuestion.ask(prompt, options)
16
30
  end
17
31
 
18
- # Returns - boolean; yes for true, no for false
19
- # prompt - string; the prompt for the question
20
- # preference - boolean; whether skipping the question should return true or false
21
- def ask_yes_no(prompt, preference: true)
22
- client.ask_yes_no(prompt, preference)
32
+ # Returns: yes for true, no for false (boolean)
33
+ #
34
+ # prompt: the prompt for the question (string)
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)
38
+ # default: the default selection (boolean - defaults to true)
39
+ # required: whether the question is required or not (boolean - defaults to false)
40
+ def ask_yes_no(prompt, options = {})
41
+ defaults = {
42
+ indicate_default_message: true,
43
+ default: true,
44
+ required: false
45
+ }
46
+ options = defaults.merge(options)
47
+ HighlineWrapper::YesNoQuestion.ask(prompt, options)
23
48
  end
24
49
 
25
- # Returns - string OR hash; the selection
26
- # e.g. 'c'
27
- # prompt - string; the prompt for the question
28
- # choices - array; an array of string options
29
- # e.g. [ 'a', 'b', 'c' ]
30
- # with_index - boolean; whether to return the index of the selection
31
- # e.g. { choice: 'c', index: 2 }
32
- def ask_multiple_choice(prompt, choices, with_index: false)
33
- client.ask_multiple_choice(prompt, choices, with_index)
50
+ # Returns: the selection in a hash (hash)
51
+ # e.g. { value: 'c' }
52
+ # e.g. { value: 'c', index: 2 }
53
+ #
54
+ # prompt: the prompt for the question (string)
55
+ # choices: a list of string options (array) (e.g. [ 'a', 'b', 'c' ])
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
+ # 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
+ def ask_multiple_choice(prompt, choices, options = {})
63
+ defaults = {
64
+ indicate_default_message: true,
65
+ with_index: false,
66
+ default: nil,
67
+ required: false
68
+ }
69
+ options = defaults.merge(options)
70
+ HighlineWrapper::MultipleChoiceQuestion.ask(prompt, choices, options)
34
71
  end
35
72
 
36
- # Returns - array; an array of selections
37
- # e.g. [ 'a', 'c' ]
38
- # prompt - string; the prompt for the question
39
- # choices - array; an array of string options
40
- # e.g. [ 'a', 'b', 'c' ]
41
- # with_indexes - boolean; whether to return the indices of the selections
42
- # e.g. [ { choice: 'a', index: 0 }, { choice: 'c', index: 2 } ]
43
- def ask_checkbox(prompt, choices, with_indexes: false)
44
- client.ask_checkbox(prompt, choices, with_indexes)
45
- end
46
-
47
- private def client
48
- @client ||= HighlineWrapper::Client.new
73
+ # Returns: the selections chosen as an array of hashes (array)
74
+ # e.g. [{ value: 'a' }, { value: 'c' }]
75
+ # e.g. [{ value: 'a', index: 0 }, { value: 'c', index: 2 }])
76
+ #
77
+ # prompt: the prompt for the question (string)
78
+ # choices: a list of string options (array) (e.g. [ 'a', 'b', 'c' ])
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)
82
+ # with_indexes: whether to return the indexes of the selections (boolean - defaults to false)
83
+ # defaults: the default selections if the user skips the question (array - defaults to [])
84
+ # required: whether the question is required or not (boolean - defaults to false)
85
+ def ask_checkbox(prompt, choices, options = {})
86
+ defaults = {
87
+ indicate_default_message: true,
88
+ with_indexes: false,
89
+ defaults: [],
90
+ required: false
91
+ }
92
+ options = defaults.merge(options)
93
+ HighlineWrapper::CheckboxQuestion.ask(prompt, choices, options)
49
94
  end
50
95
  end