处理由我通过Capistrano运行的命令触发的输入提示的正确方式是什么?
我使用aptitude安装的iptables-persistent包就是一个例子。尽管有--no-gui标志,但仍然会出现一个提示,要求我确认我想要如何配置。
有没有办法通过命令行传递参数来避免这样的提示?
发布于 2013-11-23 09:24:40
我从以下位置找到并能够实现这个非常有用的handle_command_with_input方法:
https://github.com/nesquena/cap-recipes/blob/master/lib/cap_recipes/tasks/utilities.rb
def handle_command_with_input(local_run_method, shell_command, input_query, response=nil)
send(local_run_method, shell_command, {:pty => true}) do |channel, stream, data|
if data =~ input_query
if response
logger.info "#{data} #{"*"*(rand(10)+5)}", channel[:host]
channel.send_data "#{response}\n"
else
logger.info data, channel[:host]
response = ::Capistrano::CLI.password_prompt "#{data}"
channel.send_data "#{response}\n"
end
else
logger.info data, channel[:host]
end
end
end这些代码都不是我写的。谢谢,内斯奎纳。
https://stackoverflow.com/questions/15185530
复制相似问题