Class: Bcome::Interactive::SessionItem::TransparentSsh
- Inherits:
-
Base
- Object
- Base
- Bcome::Interactive::SessionItem::TransparentSsh
show all
- Defined in:
- lib/interactive/session_item/transparent_ssh.rb
Constant Summary
collapse
- END_SESSION_KEY =
"\\q"
- HELP_KEY =
"\\?"
- LIST_KEY =
"\\l"
Instance Method Summary
collapse
Methods inherited from Base
#bcome_identifier, #initialize, #irb_session, #options, #set_response_on_session
Instance Method Details
8
9
10
11
12
13
14
15
16
17
18
19
|
# File 'lib/interactive/session_item/transparent_ssh.rb', line 8
def do
input = get_input
raise ::Bcome::Interactive::SessionHalt.new if exit?(input)
if (input)
elsif list_machines?(input)
list_machines
else
execute_on_machines(input)
end
send(:do)
end
|
#execute_on_machines(user_input) ⇒ Object
58
59
60
61
62
|
# File 'lib/interactive/session_item/transparent_ssh.rb', line 58
def execute_on_machines(user_input)
machines.pmap {|machine|
machine.run(user_input)
}
end
|
#exit?(input) ⇒ Boolean
42
43
44
|
# File 'lib/interactive/session_item/transparent_ssh.rb', line 42
def exit?(input)
input == END_SESSION_KEY
end
|
54
55
56
|
# File 'lib/interactive/session_item/transparent_ssh.rb', line 54
def get_input
return ::Readline.readline("\n#{terminal_prompt}", true).squeeze(" " ).to_s
end
|
#has_selected_machines? ⇒ Boolean
73
74
75
|
# File 'lib/interactive/session_item/transparent_ssh.rb', line 73
def has_selected_machines?
selected_machines.is_a?(Array) && selected_machines.any?
end
|
#list_machines ⇒ Object
64
65
66
67
|
# File 'lib/interactive/session_item/transparent_ssh.rb', line 64
def list_machines
listed = "\n#{machines.collect(&:identifier).join(", ")}\n"
print listed.friendly
end
|
#list_machines?(input) ⇒ Boolean
50
51
52
|
# File 'lib/interactive/session_item/transparent_ssh.rb', line 50
def list_machines?(input)
input == LIST_KEY
end
|
69
70
71
|
# File 'lib/interactive/session_item/transparent_ssh.rb', line 69
def machines
@machines ||= has_selected_machines? ? selected_machines : @irb_session.resources.collect(&:node)
end
|
#selected_machines ⇒ Object
77
78
79
|
# File 'lib/interactive/session_item/transparent_ssh.rb', line 77
def selected_machines
@selections ||= @irb_session.instance_variable_get(:@objects)
end
|
21
22
23
|
# File 'lib/interactive/session_item/transparent_ssh.rb', line 21
def
system("clear") ; print start_message
end
|
46
47
48
|
# File 'lib/interactive/session_item/transparent_ssh.rb', line 46
def (input)
input == HELP_KEY
end
|
#start_message ⇒ Object
25
26
27
28
29
30
31
|
# File 'lib/interactive/session_item/transparent_ssh.rb', line 25
def start_message
warning = "\nCommands entered here will be executed on every machine in your selection.".danger
second_warning = "\nUse with CAUTION.".danger
info = "\n\n\\l list machines\n\\q to quit\n\\? this message".informational
return "#{warning}#{second_warning}#{info}\n"
end
|
#terminal_prompt ⇒ Object
33
34
35
|
# File 'lib/interactive/session_item/transparent_ssh.rb', line 33
def terminal_prompt
"#{bcome_identifier}>\s" + "interactive\s>\s".command end
|
#valid_response(response) ⇒ Object
37
38
39
40
|
# File 'lib/interactive/session_item/transparent_ssh.rb', line 37
def valid_response(response)
a = response.gsub("\s", "").downcase
valid_responses.include?(response)
end
|