2013-03-03 60 views
2

處理由我通過Capistrano運行的命令觸發的輸入提示的正確方法是什麼?在Capistrano處理輸入提示的正確方法?

一個示例是我使用​​安裝的iptables-persistent軟件包。儘管標記爲--no-gui,但仍然出現提示,要求我確認如何配置事物。

有沒有辦法通過命令行傳遞參數來避免這種提示?

回答

0

我發現能夠從實現這個非常有用的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 

的代碼都不是我的。格拉西亞斯奈斯克納。