Highline Wrapper 
A little wrapper to help ask some easy questions via the command-line with Highline. The types of questions this wrapper supports is:
- Open-ended question
- Yes/No question
- Multiple choice question where the user is allowed to select one answer
- Multiple choice "checkbox" question where the user is allowed to select multiple answers
Installation
Add this line to your application's Gemfile:
gem 'highline_wrapper'
And then execute:
bundle install
Or install it yourself as:
gem install highline_wrapper
Usage
Once this gem is installed, you can then initiate a new HighlineWrapper object:
HighlineWrapper.new
Then, add this to the top of your file (or to your gem):
require 'highline_wrapper'
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.
Open-ended questions
Question configuration options:
secret: defaults tofalsedefault: defaults to''required: defaults tofalse
Examples
```ruby > HighlineWrapper.new.ask('What is your favorite number?') What is your favorite number? four => "four" > HighlineWrapper.new.ask('What is your favorite number?', true) What is your favorite number? This question is required. What is your favorite number? This question is required. What is your favorite number? 2 => "2" > HighlineWrapper.new.ask('What is your favorite color?') What is your favorite color? => "" > HighlineWrapper.new.ask('What is your favorite color?', 'orange') What is your favorite color? => "orange" > HighlineWrapper.new.ask('Please type your private token:', true) Please type your private token? **************** => "MY-PRIVATE-TOKEN" > HighlineWrapper.new.ask('What is your private token?', true, required: true) What is your private token? This question is required. What is your private token? This question is required. What is your private token? This question is required. What is your private token? **************** => "MY-PRIVATE-TOKEN" ```Yes/No questions
Question configuration options:
default: defaults totrue(aka 'yes')required: defaults tofalse
Examples
```ruby > HighlineWrapper.new.ask_yes_no('Do you like Ruby?') Do you like Ruby? no => false > HighlineWrapper.new.ask_yes_no('Do you like Ruby?') Do you like Ruby? yes => true > HighlineWrapper.new.ask_yes_no('Do you like Ruby?', false) Do you like Ruby? => false > HighlineWrapper.new.ask_yes_no('Do you like Ruby?', true) Do you like Ruby? This question is required. Do you like Ruby? No => false > HighlineWrapper.new.ask_yes_no('Do you like Ruby?') Do you like Ruby? uh-huh This question is required. Do you like Ruby? YES => true ```Multiple choice question
Question configuration options:
with_index: defaults tofalse(particularly handy when there may be duplicate-named but different items in the list—think Sally with ID 45 and Sally with ID 72)default: defaults tonilrequired: defaults tofalse
Notes:
- If
requiredistrue, the question will repeat until the user answers the question - If
requiredistrue, then thedefaultvalue will be ignored (defaults tonil, but could be set to whatever and the code won't care... the question is required) - If
defaultisnilandrequiredisfalse, and the user skips the question, the answer will benil - If
with_indexistrue, a hash will be returned with the choice AND the index of the selection in the originalchoicesarray- e.g.
{ value: 'c', index: 2 }
- e.g.
- If
with_indexisfalse, then a hash of one item will be returned- e.g.
{ value: 'c' }
- e.g.
Examples
```ruby > HighlineWrapper.new.ask_multiple_choice('What is your favorite number of these?', ['one', 'two', 'three']) What is your favorite number of these? 1. one 2. two 3. three 2 => :value=>"two" > HighlineWrapper.new.ask_multiple_choice('What is your favorite number of these?', ['one', 'two', 'three'], true) What is your favorite number of these? 1. one 2. two 3. three 2 => :index=>1 > HighlineWrapper.new.ask_multiple_choice('What is your favorite number of these?', ['one', 'two', 'three'], true, default: 'one') What is your favorite number of these? 1. one 2. two 3. three => :index=>0 > HighlineWrapper.new.ask_multiple_choice('What is your favorite number of these?', ['one', 'two', 'three'], 'three', required: true) What is your favorite number of these? 1. one 2. two 3. three This question is required. What is your favorite number of these? 1. one 2. two 3. three This question is required. What is your favorite number of these? 1. one 2. two 3. three 2 => :value=>"two" > HighlineWrapper.new.ask_multiple_choice('What is your favorite number of these?', ['one', 'two', 'three'], nil) What is your favorite number of these? 1. one 2. two 3. three => nil > HighlineWrapper.new.ask_multiple_choice('What is your favorite number of these?', ['one', 'two', 'three'], nil, with_index: true) What is your favorite number of these? 1. one 2. two 3. three => nil ```Multiple choice "checkbox" question
Question configuration options:
with_indexes: defaults tofalse(particularly handy when there may be duplicate-named but different items in the list—think Sally with ID 45 and Sally with ID 72)defaults: defaults to[]required: defaults tofalse
Notes:
- If
requiredistrue, the question will repeat until the user answers the question - If
requiredistrue, then thedefaultsvalue will be ignored (this value is defaulting to[], but could be set to whatever and the code won't care... the question is required) - If
defaultsis[]andrequiredisfalse, then the method will return an empty array - If
with_indexesistrue, an array of hashes will be returned with the choice AND the index (of the selection in the originalchoicesarray) in each hash- e.g.
[{ value: 'a', index: 0 }, { value: 'c', index: 2 }]
- e.g.
- If
with_indexesisfalse, then an hashes will be returned where each hash only has a value- e.g.
[{ value: 'a' }, { value: 'c' }]
- e.g.
Examples
```ruby > HighlineWrapper.new.ask_checkbox("What are your favorite numbers of these?", ['one', 'two','three']) What are your favorite numbers of these? 1. one 2. two 3. three 1, 3 => [:value=>"one", :value=>"three"] > HighlineWrapper.new.ask_checkbox("What are your favorite numbers of these?", ['one', 'two','three'], true) What are your favorite numbers of these? 1. one 2. two 3. three 1, 3 => [:index=>0, :index=>2] > HighlineWrapper.new.ask_checkbox("What are your favorite numbers of these?", ['one', 'two','three'], ['two', 'three']) What are your favorite numbers of these? 1. one 2. two 3. three => [:value=>"two", :value=>"three"] > HighlineWrapper.new.ask_checkbox("What are your favorite numbers of these?", ['one', 'two','three'], true, with_indexes: true) What are your favorite numbers of these? 1. one 2. two 3. three This question is required. What are your favorite numbers of these? 1. one 2. two 3. three 2 => [:index=>1] > HighlineWrapper.new.ask_checkbox("What are your favorite numbers of these?", ['one', 'two','three'], true, with_indexes: false) What are your favorite numbers of these? 1. one 2. two 3. three This question is required. What are your favorite numbers of these? 1. one 2. two 3. three 1 => [:value=>"one"] > HighlineWrapper.new.ask_checkbox("What are your favorite numbers of these?", ['one', 'two','three'], []) What are your favorite numbers of these? 1. one 2. two 3. three => [] > HighlineWrapper.new.ask_checkbox("What are your favorite numbers of these?", ['one', 'two','three'], [], with_indexes: true) What are your favorite numbers of these? 1. one 2. two 3. three => [] ```Tests
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!
Contributing
To submit a feature request, bug ticket, etc, please submit an official GitHub Issue.
To report any security vulnerabilities, please view this project's Security Policy.
When interacting with this repository, please follow Contributor Covenant's Code of Conduct.
Releasing
To make a new release of this gem:
- Merge the pull request via the big green button
- Run
git tag vX.X.Xandgit push --tag - Make a new release here
- Run
gem build *.gemspec - Run
gem push *.gemto push the new gem to RubyGems - Run
rm *.gemto clean up your local repository
To set up your local machine to push to RubyGems via the API, see the RubyGems documentation.