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.
Simply inserting the shell command…
sh “read whatever_variable_name”
… into the Rakefile doesn’t work- I get the following error:
Command failed with status (127): [read whatever_variable_name…]
I guess this is because Rake doesn’t respond to the results of shell
commands, but only executes them “blind”.
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.
File.read ? Kernel#gets ? Readline ?
Rakefile is a normal ruby file, so you can do anything you can do in
ruby.
You can event call IRB to get more interactivity, although I’m not sure
if that’s the intent of rake
Other than that, you can parametrize rake tasks through environment
variables:
either by really setting the env, or passing on command line:
rake task_name var1=abcd var2=efgh
then in your rakefile you can reference them as ENV[‘var1’] and
ENV[‘var2’]
… and this would automatically default to looking for input from the
user at the command line. However, doing the same thing in a Rakefile,
it was by default looking for input from an object with the name of the
rake task instead, and I would thus get an error message like:
No such file or directory - rake_task_name
I thus had to overtly specify to do a “gets” on the standard input:
$stdin.gets
… and this worked fine.
Perhaps this is obvious to more experienced ruby programmers, but not to
me!
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.
File.read ? Kernel#gets ? Readline ?
Rakefile is a normal ruby file, so you can do anything you can do in
ruby.
You can event call IRB to get more interactivity, although I’m not sure
if that’s the intent of rake
Other than that, you can parametrize rake tasks through environment
variables:
either by really setting the env, or passing on command line:
rake task_name var1=abcd var2=efgh
then in your rakefile you can reference them as ENV[‘var1’] and
ENV[‘var2’]
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 L. 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?
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?
This is an example of the solution I ended up with for asking the user
For this to work, I needed to specify in the Rake task that “gets”
Rob.
You may find subversion (instead of zipping the old sources) and
capistrano (for the overall deployment) useful
This is an example of the solution I ended up with for asking the user
For this to work, I needed to specify in the Rake task that “gets”
Rob.
You may find subversion (instead of zipping the old sources) and
capistrano (for the overall deployment) useful
On Thu, 29 Nov 2007 20:36:11 +0900, Jano S. wrote:
You may find subversion (instead of zipping the old sources) and
capistrano (for the overall deployment) useful
I don’t understand how subversion works in conjunction with rails.
What’s being “uploaded”? One file at a time? the whole directory?
From what I understand, you don’t upload, you do a svn export/checkout
to a directory on the server.
It obviously requires shell access to the webhost, although there are
surely ways how one can manage
without one. The export is usually followed bu running the tests, and
in case of success, replacing
the actual version with the new one, and restarting mongrels.
This is more or less my idea about what capistrano might do. For an
exact description see their page.
On Sun, 02 Dec 2007 19:38:58 +0900, Jano S. wrote:
This is more or less my idea about what capistrano might do. For an
exact description see their page.
I’m reading about svn, subversion, but am using google code and it seems
to work fine. The sqlite db, and a few inconsequentials, are also being
uploaded, but that’s configurable (I imagine).