Top Level Namespace
Instance Method Summary collapse
-
#render(file, binding) ⇒ Object
render a template.
-
#run_and_watch_prompt(cmd, regex_to_watch) ⇒ Object
allows to run a command which require the user input via the prompt.
-
#sudo_and_watch_prompt(cmd, regex_to_watch) ⇒ Object
allows to sudo a command which require the user input via the prompt.
-
#watch_prompt(ch, stream, data, regex_to_watch) ⇒ Object
utility method called by sudo_and_watch_prompt and run_and_watch_prompt.
Instance Method Details
#render(file, binding) ⇒ Object
render a template
4 5 6 7 |
# File 'lib/capistrano/ext/ubuntu-machine/helpers.rb', line 4 def render(file, binding) template = File.read("#{File.dirname(__FILE__)}/templates/#{file}.erb") result = ERB.new(template).result(binding) end |
#run_and_watch_prompt(cmd, regex_to_watch) ⇒ Object
allows to run a command which require the user input via the prompt
17 18 19 20 21 |
# File 'lib/capistrano/ext/ubuntu-machine/helpers.rb', line 17 def run_and_watch_prompt(cmd, regex_to_watch) run cmd, :pty => true do |ch, stream, data| watch_prompt(ch, stream, data, regex_to_watch) end end |
#sudo_and_watch_prompt(cmd, regex_to_watch) ⇒ Object
allows to sudo a command which require the user input via the prompt
10 11 12 13 14 |
# File 'lib/capistrano/ext/ubuntu-machine/helpers.rb', line 10 def sudo_and_watch_prompt(cmd, regex_to_watch) sudo cmd, :pty => true do |ch, stream, data| watch_prompt(ch, stream, data, regex_to_watch) end end |
#watch_prompt(ch, stream, data, regex_to_watch) ⇒ Object
utility method called by sudo_and_watch_prompt and run_and_watch_prompt
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/capistrano/ext/ubuntu-machine/helpers.rb', line 24 def watch_prompt(ch, stream, data, regex_to_watch) # the regex can be an array or a single regex -> we force it to always be an array with [*xx] if [*regex_to_watch].find { |regex| data =~ regex} # prompt, and then send the response to the remote process ch.send_data(Capistrano::CLI.password_prompt(data) + "\n") else # use the default handler for all other text Capistrano::Configuration.default_io_proc.call(ch, stream, data) end end |