Method: Sfn::Command::Plan#display_plan_lists

Defined in:
lib/sfn/command/plan.rb

#display_plan_lists(stack) ⇒ Object

Display plan list in table form

Parameters:

  • (Miasma::Models::Orchestration::Stack)


149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
# File 'lib/sfn/command/plan.rb', line 149

def display_plan_lists(stack)
  unless stack
    raise "Failed to locate requested stack `#{name_args.first}`"
  end
  plans = stack.plans.all
  if plans.empty?
    ui.warn "No plans found for stack `#{stack.name}`"
    return
  end
  ui.info "Plans for stack: #{ui.color(stack.name, :bold)}\n"
  n_width = "Plan Name".length
  i_width = "Plan ID".length
  s_width = "Plan State".length
  c_width = "Created".length
  plan_info = plans.map do |plan|
    plan_id = plan.id.to_s.split("/").last
    n_width = plan.name.to_s.length if plan.name.to_s.length > n_width
    i_width = plan_id.to_s.length if plan_id.length > i_width
    s_width = plan.state.to_s.length if plan.state.to_s.length > s_width
    c_width = plan.created_at.to_s.length if plan.created_at.to_s.length > c_width
    [plan.name, plan_id, plan.state, plan.created_at]
  end
  table = ui.table(self) do
    table(:border => false) do
      row(:header => true) do
        column "Plan Name", :width => n_width + 5
        column "Plan ID", :width => i_width + 5
        column "Plan State", :width => s_width + 5
        column "Created", :width => c_width + 5
      end
      plan_info.sort_by(&:first).each do |plan|
        row do
          plan.each do |item|
            column item
          end
        end
      end
    end
  end.display
end