diff --git a/.ruby-version b/.ruby-version index be94e6f..15a2799 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -3.2.2 +3.3.0 diff --git a/README.md b/README.md index 5a4286e..beb2c29 100644 --- a/README.md +++ b/README.md @@ -69,36 +69,51 @@ four > HighlineWrapper.new.ask('What is your favorite number?', {required: true}) What is your favorite number? + --- This question is required --- + 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 number?', {required: true, indicate_default_message: false}) What is your favorite number? + --- This question is required --- + What is your favorite number? + --- This question is required --- + What is your favorite number? 5 => "5" > HighlineWrapper.new.ask('What is your favorite number?', {indicate_default_message: false}) What is your favorite number? + => "" > HighlineWrapper.new.ask('What is your favorite color?') What is your favorite color? + --- Default selected: EMPTY --- + => "" > HighlineWrapper.new.ask('What is your favorite color?', {default: 'orange'}) What is your favorite color? + --- Default selected: orange --- + => "orange" > HighlineWrapper.new.ask('Please type your private token:', {secret: true}) @@ -115,9 +130,11 @@ Please type your private token: Please type your private token: --- This question is required --- + Please type your private token: --- This question is required --- + Please type your private token: **************** => "MY-PRIVATE-TOKEN" @@ -150,7 +167,9 @@ Notes: ```ruby > HighlineWrapper.new.ask_yes_no('Do you like Ruby?') Do you like Ruby? + --- Default selected: YES --- + => true > HighlineWrapper.new.ask_yes_no('Do you like Ruby?', {indicate_default_message: false}) @@ -164,16 +183,24 @@ no > HighlineWrapper.new.ask_yes_no('Do you like Ruby?', {default: false}) Do you like Ruby? + --- Default selected: NO --- + => false > HighlineWrapper.new.ask_yes_no('Do you like Ruby?', {required: true}) Do you like Ruby? + --- This question is required --- + Do you like Ruby? + --- This question is required --- + Do you like Ruby? + --- This question is required --- + Do you like Ruby? N => false @@ -182,6 +209,7 @@ N Do you like Ruby? uh-huh --- This question is required --- + Do you like Ruby? YES => true @@ -190,6 +218,7 @@ YES Do you like Ruby? yep --- This question is required --- + Do you like Ruby? yes => true @@ -239,12 +268,16 @@ 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 @@ -257,7 +290,9 @@ What is your favorite number of these? 1. one 2. two 3. three + --- Default selected: 1. one --- + => {:value=>"one", :index=>0} > HighlineWrapper.new.ask_multiple_choice('What is your favorite number of these?', ['one', 'two', 'three'], {with_index: true, default: 'one', indicate_default_message: false}) @@ -272,12 +307,16 @@ 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 @@ -290,7 +329,9 @@ What is your favorite number of these? 1. one 2. two 3. three + --- Default selected: EMPTY --- + => nil > HighlineWrapper.new.ask_multiple_choice('What is your favorite number of these?', ['one', 'two', 'three'], {default: nil, with_index: true}) @@ -298,7 +339,9 @@ What is your favorite number of these? 1. one 2. two 3. three + --- Default selected: EMPTY --- + => nil > HighlineWrapper.new.ask_multiple_choice('What is your favorite number of these?', ['one', 'two', 'three'], {default: nil, with_index: true, indicate_default_message: false}) @@ -306,6 +349,7 @@ What is your favorite number of these? 1. one 2. two 3. three + => nil ``` @@ -353,6 +397,7 @@ 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}) @@ -360,7 +405,9 @@ What are your favorite numbers of these? 1. one 2. two 3. three + --- Defaults selected: EMPTY --- + => [] > HighlineWrapper.new.ask_checkbox("What are your favorite numbers of these?", ['one', 'two','three'], {defaults: ['two', 'three']}) @@ -368,7 +415,9 @@ What are your favorite numbers of these? 1. one 2. two 3. three + --- Defaults selected: 2. two, 3. three --- + => [{:value=>"two"}, {:value=>"three"}] > HighlineWrapper.new.ask_checkbox("What are your favorite numbers of these?", ['one', 'two','three'], {required: true, with_indexes: true}) @@ -376,12 +425,16 @@ 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 + --- This question is required --- + What are your favorite numbers of these? 1. one 2. two @@ -394,7 +447,9 @@ 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 @@ -407,6 +462,7 @@ What are your favorite numbers of these? 1. one 2. two 3. three + => [{:value=>"two", :index=>1}, {:value=>"three", :index=>2}] ``` diff --git a/highline_wrapper.gemspec b/highline_wrapper.gemspec index a4bff37..d6e9ef7 100644 --- a/highline_wrapper.gemspec +++ b/highline_wrapper.gemspec @@ -21,7 +21,8 @@ Gem::Specification.new do |gem| gem.summary = 'A little HighLine wrapper' gem.version = HighlineWrapper::VERSION - gem.add_dependency 'highline', '~> 2.0' + gem.add_dependency 'abbrev', '~> 0.1' + gem.add_dependency 'highline', '~> 3.0' gem.add_development_dependency 'bundler', '~> 2.2' gem.add_development_dependency 'faker', '~> 3.0' diff --git a/lib/highline_wrapper/checkbox_question.rb b/lib/highline_wrapper/checkbox_question.rb index e550f36..950e36a 100644 --- a/lib/highline_wrapper/checkbox_question.rb +++ b/lib/highline_wrapper/checkbox_question.rb @@ -29,7 +29,7 @@ def ask(prompt, choices, options) private def print_default_message(options, choices) defaults = options[:default_indexes].map { |i| "#{i + 1}. #{choices[i]}".strip }.join(', ') - puts "--- Defaults selected: #{defaults} ---" + puts "--- Defaults selected: #{defaults} ---\n\n" end private def format_multiple_selections(choices, indices, with_indexes) diff --git a/lib/highline_wrapper/multiple_choice_question.rb b/lib/highline_wrapper/multiple_choice_question.rb index fb5e5f1..725a561 100644 --- a/lib/highline_wrapper/multiple_choice_question.rb +++ b/lib/highline_wrapper/multiple_choice_question.rb @@ -22,7 +22,7 @@ def ask(prompt, choices, options) end private def print_default_message(options) - puts "--- Default selected: #{options[:default_index] + 1}. #{options[:default]} ---" + puts "--- Default selected: #{options[:default_index] + 1}. #{options[:default]} ---\n\n" end end end diff --git a/lib/highline_wrapper/open_ended_question.rb b/lib/highline_wrapper/open_ended_question.rb index c55930c..75c8a2a 100644 --- a/lib/highline_wrapper/open_ended_question.rb +++ b/lib/highline_wrapper/open_ended_question.rb @@ -17,9 +17,9 @@ def ask(prompt, options) private def print_default_message(options) if !options[:secret] - puts "--- Default selected: #{options[:default].empty? ? 'EMPTY' : options[:default]} ---" + puts "--- Default selected: #{options[:default].empty? ? 'EMPTY' : options[:default]} ---\n\n" elsif options[:secret] - puts '--- Default selected: HIDDEN ---' + puts "--- Default selected: HIDDEN ---\n\n" end end end diff --git a/lib/highline_wrapper/question.rb b/lib/highline_wrapper/question.rb index a8943a7..1a828bc 100644 --- a/lib/highline_wrapper/question.rb +++ b/lib/highline_wrapper/question.rb @@ -5,7 +5,6 @@ class Question class << self def ask_highline(prompt, secret: false) highline.ask(prompt) do |conf| - conf.readline = true conf.echo = '*' if secret end end @@ -23,12 +22,12 @@ def format_selection(choices, index, with_index) end def recurse(prompt, choices, options) - puts '--- This question is required ---' + puts "--- This question is required ---\n\n" choices.nil? ? ask(prompt, options) : ask(prompt, choices, options) end def return_empty_defaults(options) - puts '--- Default selected: EMPTY ---' if options[:indicate_default_message] + puts "--- Default selected: EMPTY ---\n\n" if options[:indicate_default_message] options[:defaults] || options[:default] end diff --git a/lib/highline_wrapper/version.rb b/lib/highline_wrapper/version.rb index 5c8b80f..68b28d6 100644 --- a/lib/highline_wrapper/version.rb +++ b/lib/highline_wrapper/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true class HighlineWrapper - VERSION = '1.3.1' + VERSION = '2.0.0' end diff --git a/lib/highline_wrapper/yes_no_question.rb b/lib/highline_wrapper/yes_no_question.rb index d2938d7..58a4d87 100644 --- a/lib/highline_wrapper/yes_no_question.rb +++ b/lib/highline_wrapper/yes_no_question.rb @@ -27,7 +27,7 @@ def ask(prompt, options) end private def print_default_message(options) - puts "--- Default selected: #{options[:default] ? 'YES' : 'NO'} ---" + puts "--- Default selected: #{options[:default] ? 'YES' : 'NO'} ---\n\n" end end end diff --git a/spec/highline_wrapper/checkbox_question_spec.rb b/spec/highline_wrapper/checkbox_question_spec.rb index e66d369..9be7339 100644 --- a/spec/highline_wrapper/checkbox_question_spec.rb +++ b/spec/highline_wrapper/checkbox_question_spec.rb @@ -5,7 +5,7 @@ describe HighlineWrapper::CheckboxQuestion do let(:choices) { %w[one two three] } - let(:response) { double(:response, readline: true, to_i: 3) } + let(:response) { double(:response, to_i: 3) } let(:highline) { double(:highline_cli, ask: response) } before do diff --git a/spec/highline_wrapper/multiple_choice_question_spec.rb b/spec/highline_wrapper/multiple_choice_question_spec.rb index a418cb8..ce26298 100644 --- a/spec/highline_wrapper/multiple_choice_question_spec.rb +++ b/spec/highline_wrapper/multiple_choice_question_spec.rb @@ -5,7 +5,7 @@ describe HighlineWrapper::MultipleChoiceQuestion do let(:choices) { %w[one two three] } - let(:response) { double(:response, readline: true, to_i: 3) } + let(:response) { double(:response, to_i: 3) } let(:highline) { double(:highline_cli, ask: response) } before do diff --git a/spec/highline_wrapper/open_ended_question_spec.rb b/spec/highline_wrapper/open_ended_question_spec.rb index 4543936..2dd5ee9 100644 --- a/spec/highline_wrapper/open_ended_question_spec.rb +++ b/spec/highline_wrapper/open_ended_question_spec.rb @@ -4,7 +4,7 @@ require 'highline_wrapper' describe HighlineWrapper::OpenEndedQuestion do - let(:response) { double(:response, readline: true, to_i: 3) } + let(:response) { double(:response, to_i: 3) } let(:highline) { double(:highline_cli, ask: response) } before do diff --git a/spec/highline_wrapper/question_spec.rb b/spec/highline_wrapper/question_spec.rb index 9d5d4d8..c14cadc 100644 --- a/spec/highline_wrapper/question_spec.rb +++ b/spec/highline_wrapper/question_spec.rb @@ -4,7 +4,7 @@ require 'highline_wrapper' describe HighlineWrapper::Question do - let(:response) { double(:response, readline: true, to_i: 3) } + let(:response) { double(:response, to_i: 3) } let(:highline) { double(:highline_cli, ask: response) } before do diff --git a/spec/highline_wrapper/yes_no_question_spec.rb b/spec/highline_wrapper/yes_no_question_spec.rb index 1dc8ab0..575f541 100644 --- a/spec/highline_wrapper/yes_no_question_spec.rb +++ b/spec/highline_wrapper/yes_no_question_spec.rb @@ -4,7 +4,7 @@ require 'highline_wrapper' describe HighlineWrapper::YesNoQuestion do - let(:response) { double(:response, readline: true, to_i: 3) } + let(:response) { double(:response, to_i: 3) } let(:highline) { double(:highline_cli, ask: response) } before do