Jamis, I actually found out a way to get this working without an
interactive prompt.
require 'capistrano/cli'
Capistrano::Configuration.instance(:must_exist).load do
namespace :ubuntu do
desc "update apt packages"
task :apt_update do
invoke_command "apt-get -qyu update", :via => run_method
invoke_command "apt-get -qyu upgrade", :via => run_method
invoke_command "apt-get -qyu autoclean", :via => run_method
end
end
end
I'll try your idea out as well. Thanks for the tip!
On Dec 14, 2007, at 8:59 AM, Jamis Buck wrote:
> A naive expect-like routine can be written for cap using the
> callback that run expects to check for the output and respond with
> what you want to say. Note that the block is run once for _each
> server_, so if you put an interactive prompt in there, you'll want
> to make sure that you cache the response and reuse it for similar
> prompts. Here's a naive example (which does not account for multiple
> servers):
>
> # channel: the SSH channel object used for this response
> # stream: either :err or :out, for stderr or stdout responses
> # output: the text that the server is sending, might be in chunks
> run "apt-get update" do |channel, stream, output|
> if output =~ /Are you sure?/
> answer = Capistrano::CLI.ui.ask("Are you sure: ")
> channel.send_data(answer + "\n")
> else
> # allow the default callback to be processed
> Capistrano::Configuration.default_io_proc.call[channel, stream,
> output]
> end
> end
>
> Hopefully that gives you some other ideas, too.
>
> - Jamis
>
> On Dec 13, 2007, at 11:51 PM, Scott wrote:
>
>>
>> Without going into the wisdom of doing this (or actually in fact
>> answering your question), you can add -y to the apt-get command,
>> which
>> will answer yes for you without the prompt.
>>
>> On Dec 13, 3:26 pm, samg <[EMAIL PROTECTED]> wrote:
>>> I wrote a task that runs apt-get update, but when it asks whether I
>>> want to proceed and presents me with a yes or no answer, i dont know
>>> how to proceed. I'm looking at Capistrano.ui.ask, which points to
>>> the
>>> highline library. Has anyone figured out how to have a cap script
>>> present you with a prompt when the shell asks you a question?
>> >>
>
--~--~---------~--~----~------------~-------~--~----~
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/capistrano
-~----------~----~----~----~------~----~------~--~---