Class: LeapCli::Commands::TagTable

Inherits:
Object
  • Object
show all
Includes:
CommandLineReporter
Defined in:
lib/leap_cli/commands/list.rb

Instance Method Summary collapse

Constructor Details

#initialize(heading, tag_list, colors) ⇒ TagTable

Returns a new instance of TagTable.



64
65
66
67
68
# File 'lib/leap_cli/commands/list.rb', line 64

def initialize(heading, tag_list, colors)
  @heading = heading
  @tag_list = tag_list
  @colors = colors
end

Instance Method Details

#runObject



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/leap_cli/commands/list.rb', line 69

def run
  tags = @tag_list.keys.select{|tag| tag !~ /^_/}.sort # sorted list of tags, excluding _partials
  max_width = [20, (tags+[@heading]).inject(0) {|max,i| [i.size,max].max}].max
  table :border => false do
    row :color => @colors[0]  do
      column @heading, :align => 'right', :width => max_width
      column "NODES", :width => HighLine::SystemExtensions.terminal_size.first - max_width - 2, :padding => 2
    end
    tags.each do |tag|
      next if @tag_list[tag].node_list.empty?
      row :color => @colors[1] do
        column tag
        column @tag_list[tag].node_list.keys.sort.join(', ')
      end
    end
  end
  vertical_spacing
end