def prompt(params)
params_desc = {
:message => { :mandatory => true, :type => :string },
:property => { :mandatory => true, :type => :string },
:default => { :mandatory => false, :type => :string },
:pattern => { :mandatory => false, :type => :string },
:error => { :mandatory => false, :type => :string },
:attempts => { :mandatory => false, :type => :integer, :default => 0 }
}
check_parameters(params, params_desc)
message = params[:message]
property = params[:property]
default = params[:default]
pattern = params[:pattern]
error = params[:error]
attempts = params[:attempts]
message << " [#{default}]" if default
message << ':'
ok = false
nb_attempts = 1
while not (ok or (nb_attempts > attempts and attempts != 0))
puts message
value = gets.strip
value = default if default and value.length == 0
if pattern
if value =~ /#{pattern}/
ok = true
elsif error
puts error
end
else
ok = true
end
nb_attempts += 1
end
error "Failed to obtain a matching prompt" if not ok
@build.context.set_property(property, value)
end