8
9
10
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
|
# File 'lib/dex/ui/prompt.rb', line 8
def ask(question, options: nil, default: nil, is_file: nil, allow_empty: true)
if (default && !allow_empty) || (options && (default || is_file))
raise(ArgumentError, 'conflicting arguments')
end
if default
puts_question("#{question} (empty = #{default})")
else
puts_question(question)
end
if options
return ask_options(options)
end
loop do
line = readline(is_file: is_file)
if line.empty? && default
write_default_over_empty_input(default)
return default
end
if !line.empty? || allow_empty
return line
end
end
end
|