module Hoe::RakeHelpers

def prompt_with_default( prompt_string, default, failure_msg="Try again." )

## returns true. An optional failure message can also be passed in.
## anything. If a test is provided, the prompt will repeat until the test
## substituting the given default if the user doesn't input
## Prompt the user with the given prompt_string via #prompt,
def prompt_with_default( prompt_string, default, failure_msg="Try again." )
	response = nil
	begin
		default ||= '~'
		response = prompt( "%s [%s]" % [ prompt_string, default ] )
		response = default.to_s if !response.nil? && response.empty? 
		trace "Validating response %p" % [ response ]
		# the block is a validator.	 We need to make sure that the user didn't
		# enter '~', because if they did, it's nil and we should move on.	 If
		# they didn't, then call the block.
		if block_given? && response != '~' && ! yield( response )
			error_message( failure_msg + "\n\n" )
			response = nil
		end
	end while response.nil?
	return nil if response == '~'
	return response
end