139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
|
# File 'lib/gaptool_client/commands.rb', line 139
def execute
config, content = Gaptool::SSH.config
if remove?
data = ''
else
puts Rainbow('Getting nodes from API').green
data = [Gaptool::SSH::START_MARKER, '# to remove this block, run gt ssh-config --remove']
Gaptool::API.client.getallnodes(hidden: true).sort_by { |n| n['instance'] }.each do |node|
host = Gaptool::API.get_host(node)
puts " - #{Rainbow(host).blue}"
data << Gaptool::SSH.config_for(node)
end
data << Gaptool::SSH::STOP_MARKER
data = data.join("\n")
end
if Regexp.new(Gaptool::SSH::START_MARKER).match(content)
content.gsub!(/#{Gaptool::SSH::START_MARKER}.*?#{Gaptool::SSH::STOP_MARKER}/m, data)
elsif !remove?
content = content + "\n" + data
end
File.open(config, 'w') { |f| f.write(content) }
end
|