Class: PDK::CLI::Util::Interview
- Inherits:
-
TTY::Prompt::AnswersCollector
- Object
- TTY::Prompt::AnswersCollector
- PDK::CLI::Util::Interview
- Defined in:
- lib/pdk/cli/util/interview.rb
Instance Method Summary collapse
- #add_question(options = {}) ⇒ Object
- #add_questions(questions) ⇒ Object
- #num_questions ⇒ Object
- #pastel ⇒ Object
- #run ⇒ Object
Instance Method Details
#add_question(options = {}) ⇒ Object
17 18 19 |
# File 'lib/pdk/cli/util/interview.rb', line 17 def add_question( = {}) (@questions ||= {})[[:name]] = end |
#add_questions(questions) ⇒ Object
11 12 13 14 15 |
# File 'lib/pdk/cli/util/interview.rb', line 11 def add_questions(questions) questions.each do |question| add_question(question) end end |
#num_questions ⇒ Object
21 22 23 |
# File 'lib/pdk/cli/util/interview.rb', line 21 def num_questions (@questions ||= {}).count end |
#pastel ⇒ Object
7 8 9 |
# File 'lib/pdk/cli/util/interview.rb', line 7 def pastel @pastel ||= Pastel.new end |
#run ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/pdk/cli/util/interview.rb', line 25 def run i = 1 num_questions = @questions.count @questions.each do |question_name, question| @name = question_name @prompt.print pastel.bold(_('[Q %{current_number}/%{questions_total}]') % { current_number: i, questions_total: num_questions }) + ' ' @prompt.puts pastel.bold(question[:question]) @prompt.puts question[:help] if question.key?(:help) if question.key?(:choices) multi_select(_('-->'), per_page: question[:choices].count) do |q| q.enum ')' q.default(*question[:default]) if question.key?(:default) question[:choices].each do |text, | q.choice text, end end else ask(_('-->')) do |q| q.required(question.fetch(:required, false)) if question.key?(:validate_pattern) q.validate(question[:validate_pattern], question[:validate_message]) end q.default(question[:default]) if question.key?(:default) end end i += 1 @prompt.puts '' end @answers rescue TTY::Prompt::Reader::InputInterrupt nil end |