Hi Thufir,

I'm new to Rake as well, so I don't know if I can tell you anything much 
more than what is in the previous posts. The project I was concerned 
with here was to use Rake to do deployments of my Rails sites- moving 
and backing up the previously released version, unzipping the new one, 
setting up the mongrel server stuff etc. I needed my Rake task to stop 
and ask the user for input at various points, and that was what this 
question was about.

This is an example of the solution I ended up with for asking the user 
for input :

puts "\nDeploying #{new_release_name}\n\nPlease enter the name of the 
last release:\n"
last_release_name = $stdin.gets.chomp

This waits for the user to enter a name for the last release at the 
command line, then stores that string in the variable 
"last_release_name", and carries on with the task.

For this to work, I needed to specify in the Rake task that "gets" 
should look to standard input - $stdin - for input from the user, as by 
default in Rake, "gets" apparently looks for input to an object with the 
name of the task itself.

I originally framed the question in terms of the unix command "read", 
which does something similar to "gets" here, because I was familiar with 
this from writing shell scripts.

I hope this is helpful.

Rob.


Thufir wrote:
> On Wed, 28 Nov 2007 19:44:34 +0900, Rob Lucas wrote:
> 
>> Perhaps I'm missing something, but I can't find information anywhere
>> about adding any level of interaction with the user into rake tasks.
>> What I want really is something equivalent to the unix/ linux command
>> "read" so that the task can vary conditionally depending on responses
>> from the user. The point would be to replace various shell scripts that
>> I have with a single, more elegant Rakefile.
> 
> 
> I'm new to rails and have only touched rake a bit.  Would expand on what
> you're currently doing, please?
> 
> 
> 
> thanks,
> 
> Thufir
-- 
Posted via http://www.ruby-forum.com/.