Class: Sfn::Command::Describe
- Inherits:
-
Sfn::Command
- Object
- Bogo::Cli::Command
- Sfn::Command
- Sfn::Command::Describe
- Includes:
- Sfn::CommandModule::Base
- Defined in:
- lib/sfn/command/describe.rb
Overview
Cloudformation describe command
Constant Summary collapse
- AVAILABLE_DISPLAYS =
[:resources, :outputs, :tags]
Instance Method Summary collapse
-
#default_attributes ⇒ Array<String>
Default attributes.
-
#execute! ⇒ Object
Run the stack describe action.
-
#outputs(stack) ⇒ Object
Display outputs.
-
#resources(stack) ⇒ Object
Display resources.
-
#tags(stack) ⇒ Object
Display tags.
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.
102 103 104 |
# File 'lib/sfn/command/describe.rb', line 102 def default_attributes %w(updated logical_id type status status_reason) end |
#execute! ⇒ Object
Run the stack describe action
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/sfn/command/describe.rb', line 16 def execute! name_required! stack_name = name_args.last root_stack = api_action! do provider.connection.stacks.get(stack_name) end if(root_stack) ([root_stack] + root_stack.nested_stacks).compact.each do |stack| ui.info "Stack description of #{ui.color(stack.name, :bold)}:" display = [].tap do |to_display| AVAILABLE_DISPLAYS.each do |display_option| if(config[display_option]) to_display << display_option end end end display = AVAILABLE_DISPLAYS.dup if display.empty? display.each do |display_method| self.send(display_method, stack) end ui.puts end else ui.fatal "Failed to find requested stack: #{ui.color(stack_name, :bold, :red)}" exit -1 end end |
#outputs(stack) ⇒ Object
Display outputs
74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/sfn/command/describe.rb', line 74 def outputs(stack) ui.info "Outputs for stack: #{ui.color(stack.name, :bold)}" unless(stack.outputs.empty?) stack.outputs.each do |output| key, value = output.key, output.value key = snake(key).to_s.split('_').map(&:capitalize).join(' ') ui.info [' ', ui.color("#{key}:", :bold), value].join(' ') end else ui.info " #{ui.color('No outputs found')}" end end |
#resources(stack) ⇒ Object
Display resources
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/sfn/command/describe.rb', line 47 def resources(stack) stack_resources = stack.resources.all.sort do |x, y| y.updated <=> x.updated end.map do |resource| Smash.new(resource.attributes) end ui.table(self) do table(:border => false) do row(:header => true) do allowed_attributes.each do |attr| column as_title(attr), :width => stack_resources.map{|r| r[attr].to_s.length}.push(as_title(attr).length).max + 2 end end stack_resources.each do |resource| row do allowed_attributes.each do |attr| column resource[attr] end end end end end.display end |
#tags(stack) ⇒ Object
Display tags
90 91 92 93 94 95 96 97 98 99 |
# File 'lib/sfn/command/describe.rb', line 90 def (stack) ui.info "Tags for stack: #{ui.color(stack.name, :bold)}" unless(stack..empty?) stack..each do |key, value| ui.info [' ', ui.color("#{key}:", :bold), value].join(' ') end else ui.info " #{ui.color('No tags found')}" end end |