Method: CBin::Config::Asker#ask_with_answer

Defined in:
lib/cocoapods-lhj-bin/config/config_asker.rb

#ask_with_answer(question, pre_answer, selection) ⇒ Object

[View source]

11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/cocoapods-lhj-bin/config/config_asker.rb', line 11

def ask_with_answer(question, pre_answer, selection)
  print "\n#{question}\n"

  print_selection_info = lambda {
    print "可选值:[ #{selection.join(' / ')} ]\n" if selection
  }
  print_selection_info.call
  print "旧值:#{pre_answer}\n" unless pre_answer.nil?

  answer = ''
  loop do
    show_prompt
    answer = STDIN.gets.chomp.strip

    if answer == '' && !pre_answer.nil?
      answer = pre_answer
      print answer.yellow
      print "\n"
    end

    next if answer.empty?
    break if !selection || selection.include?(answer)

    print_selection_info.call
  end

  answer
end