Sha256: 48df6625194d4070d92cef82f60bdb462c0d743a26455ea0f65fa0d8b65d4237
Contents?: true
Size: 1.93 KB
Versions: 34
Compression:
Stored size: 1.93 KB
Contents
#!/usr/bin/env ruby require 'time' require 'terminal-table' require 'hybrid_platforms_conductor/executable' possible_string_sorts = %i[ date node user ] possible_sorts = Hash[possible_string_sorts.map do |property_name| [ property_name, proc { |node, deploy_info| [deploy_info.key?(:error) || !deploy_info.key?(property_name) ? '' : deploy_info[property_name], node] } ] end] sort_by = :node sort_desc = false executable = HybridPlatformsConductor::Executable.new(deploy_options: false) do |opts| opts.on('-r', '--sort-by SORT', "Specify a sort. Possible values are: #{possible_sorts.keys.sort.join(', ')}. Each value can append _desc to specify a reverse sorting. Defaults to #{sort_by}.") do |sort_name| if sort_name =~ /^(.+)_desc$/ sort_desc = true sort_name = $1 end sort_by = sort_name.to_sym end end nodes_handler = executable.nodes_handler deployer = executable.deployer executable.parse_options! raise "Unknown sort name: #{sort_by}. Should be one of #{possible_sorts.keys.join(', ')}." unless possible_sorts.key?(sort_by) sorted_deploy_info = Hash[ deployer.deployment_info_from(nodes_handler.select_nodes(executable.selected_nodes.empty? ? [{ all: true }] : executable.selected_nodes)). map do |node, deploy_info| decorated_deploy_info = deploy_info.merge(node: node) decorated_deploy_info[:date] = deploy_info[:date].strftime('%F %T') if deploy_info.key?(:date) decorated_deploy_info[:services] = deploy_info[:services].join(', ') if deploy_info.key?(:services) [node, decorated_deploy_info] end ].sort_by(&possible_sorts[sort_by]) sorted_deploy_info.reverse! if sort_desc info_displayed = { node: 'Node', date: 'Date', user: 'Admin', services: 'Services', error: 'Error' } executable.out(Terminal::Table.new(headings: info_displayed.values) do |table| sorted_deploy_info.each do |_node, deploy_info| table << info_displayed.keys.map { |key| deploy_info[key] } end end)
Version data entries
34 entries across 34 versions & 1 rubygems