Class: Net::SSH::Prompt::Prompter

Inherits:
Object
  • Object
show all
Defined in:
lib/net/ssh/prompt.rb

Overview

default prompt object implementation. More sophisticated implemenetations might implement caching.

Instance Method Summary collapse

Constructor Details

#initialize(info) ⇒ Prompter

Returns a new instance of Prompter.



52
53
54
55
56
57
58
59
60
# File 'lib/net/ssh/prompt.rb', line 52

def initialize(info)
  @askpass = Prompt.askpass
  @header = []
  if info[:type] == 'keyboard-interactive'
    @header << info[:name] unless info[:name].empty?
    @header << info[:instruction] unless info[:instruction].empty?
  end
  $stdout.puts(@header) unless @askpass || @header.empty?
end

Instance Method Details

#ask(prompt, echo = true) ⇒ Object

ask input from user, a prompter might ask for multiple inputs (like user and password) in a single session.



64
65
66
67
68
69
70
71
72
73
# File 'lib/net/ssh/prompt.rb', line 64

def ask(prompt, echo = true)
  return ask_askpass(prompt) if @askpass

  $stdout.print(prompt)
  $stdout.flush
  hide = !echo && $stdin.tty?
  ret = hide ? $stdin.noecho(&:gets) : $stdin.gets
  $stdout.print("\n") unless echo
  ret.chomp
end

#success ⇒ Object

success method will be called when the password was accepted It's a good time to save password asked to a cache.



77
# File 'lib/net/ssh/prompt.rb', line 77

def success; end