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
Constant Summary
Constants inherited from Sfn::Command
CONFIG_BASE_NAME, VALID_CONFIG_EXTENSIONS
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
Methods included from Sfn::CommandModule::Callbacks
#api_action!, #callbacks_for, #run_callbacks_for
Constructor Details
This class inherits a constructor from Sfn::Command
Instance Method Details
#default_attributes ⇒ Array<String>
Returns default attributes to display
      50 51 52 53 54 55 56  | 
    
      # File 'lib/sfn/command/list.rb', line 50 def default_attributes if provider.connection.provider == :aws %w(name created updated status template_description) else %w(name created updated status description) end end  | 
  
#execute! ⇒ Object
Run the list command
      10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30  | 
    
      # File 'lib/sfn/command/list.rb', line 10 def execute! ui.table(self) do table(:border => false) do stacks = api_action! { get_stacks } row(:header => true) do allowed_attributes.each do |attr| width_val = stacks.map { |e| e[attr].to_s.length }.push(attr.length).max + 2 width_val = width_val > 70 ? 70 : width_val < 20 ? 20 : width_val column attr.split("_").map(&:capitalize).join(" "), :width => width_val 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
      35 36 37 38 39 40 41 42 43 44 45 46 47  | 
    
      # File 'lib/sfn/command/list.rb', line 35 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  |