Class: Moonshot::AskUserSource

Inherits:
Object
  • Object
show all
Defined in:
lib/moonshot/ask_user_source.rb

Instance Method Summary collapse

Instance Method Details

#get(sp) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/moonshot/ask_user_source.rb', line 7

def get(sp)
  return unless Moonshot.config.interactive

  @sp = sp

  prompt
  loop do
    input = gets.chomp

    if String(input).empty? && @sp.default?
      # We will use the default value, print it here so the output is clear.
      puts 'Using default value.'
      return
    elsif String(input).empty?
      puts "Cannot proceed without value for #{@sp.name}!"
    else
      @sp.set(String(input))
      return
    end

    prompt
  end
end