Module: Gaptool::Helpers
- Defined in:
- lib/gaptool_client/helpers.rb
Class Method Summary collapse
- .error(message, opts = {}) ⇒ Object
- .info(nodes, parseable, grepable, short = false) ⇒ Object
- .split_attrs(attribute_list) ⇒ Object
Class Method Details
.error(message, opts = {}) ⇒ Object
38 39 40 41 42 43 |
# File 'lib/gaptool_client/helpers.rb', line 38 def self.error(, opts = {}) code = opts[:code] || 1 color = opts[:color] || :red STDERR.puts(Rainbow().send(color)) exit code end |
.info(nodes, parseable, grepable, short = false) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/gaptool_client/helpers.rb', line 6 def self.info(nodes, parseable, grepable, short = false) if parseable && !short puts({ nodes: nodes }.to_json) elsif parseable puts({ nodes: nodes.map { |node| node.select { |k, _v| %w(role environment instance).include?(k) } } }.to_json) else nodes.each do |node| host = "#{node['role']}:#{node['environment']}:#{node['instance']}" if grepable && short puts host elsif !grepable puts Rainbow(host).green end next if short keys = node.keys.sort keys.each do |key| value = node[key] if grepable puts "#{host}|#{key}|#{value}" else value = Time.at(node[key].to_i) if key == 'launch_time' if key == keys.last puts " ┖ #{Rainbow(key).cyan}: #{value}\n\n" else puts " ┠ #{Rainbow(key).cyan}: #{value}" end end end end end end |
.split_attrs(attribute_list) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/gaptool_client/helpers.rb', line 45 def self.split_attrs(attribute_list) opts = {} attribute_list.each do |attr_| key, value = attr_.split('=', 2) split = key.split('.') cur = opts split.each_with_index do |part, idx| if idx == split.size - 1 # leaf, add the value cur[part] = value else cur[part] ||= {} end cur = cur[part] end end opts end |