Class: Sfn::Command::List
- Inherits:
-
Sfn::Command
- Object
- Bogo::Cli::Command
- Sfn::Command
- Sfn::Command::List
- Includes:
- Sfn::CommandModule::Base
- Defined in:
- lib/sfn/command/list.rb
Overview
List command
Instance Method Summary collapse
-
#default_attributes ⇒ Array<String>
Default attributes to display.
-
#execute! ⇒ Object
Run the list command.
-
#get_stacks ⇒ Array<Hash>
Get the list of stacks to display.
Methods included from Sfn::CommandModule::Base
Methods inherited from Sfn::Command
Constructor Details
This class inherits a constructor from Sfn::Command
Instance Method Details
#default_attributes ⇒ Array<String>
Returns default attributes to display.
49 50 51 52 53 54 55 |
# File 'lib/sfn/command/list.rb', line 49 def default_attributes if(provider.connection.provider == :aws) %w(name created status template_description) else %w(name created status description) end end |
#execute! ⇒ Object
Run the list command
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/sfn/command/list.rb', line 11 def execute! ui.table(self) do table(:border => false) do stacks = get_stacks row(:header => true) do allowed_attributes.each do |attr| column attr.split('_').map(&:capitalize).join(' '), :width => (stacks.map{|s| s[attr].to_s.length}.max || 20) + 2 end end get_stacks.each do |stack| row do allowed_attributes.each do |attr| column stack[attr] end end end end end.display end |
#get_stacks ⇒ Array<Hash>
Get the list of stacks to display
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/sfn/command/list.rb', line 34 def get_stacks provider.stacks.all.map do |stack| Smash.new(stack.attributes) end.sort do |x, y| if(y[:created].to_s.empty?) -1 elsif(x[:created].to_s.empty?) 1 else Time.parse(x[:created].to_s) <=> Time.parse(y[:created].to_s) end end end |