Module: OpsWorks::CLI::Subcommands::Status

Included in:
Agent
Defined in:
lib/opsworks/cli/subcommands/status.rb

Class Method Summary collapse

Class Method Details

.included(thor) ⇒ Object

rubocop:disable MethodLength rubocop:disable CyclomaticComplexity



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/opsworks/cli/subcommands/status.rb', line 7

def self.included(thor)
  thor.class_eval do
    include Helpers::Keychain
    include Helpers::Options

    desc 'status [--stack STACK] APP',
         'Display the most recent deployment of an app'
    option :stack, type: :array
    def status(name)
      fetch_keychain_credentials unless env_credentials?

      table = parse_stacks(options).map do |stack|
        next unless (app = stack.find_app_by_name(name))
        if (deployment = app.last_deployment)
          deployed_at = formatted_time(deployment.created_at)
        else
          deployed_at = '-'
        end
        [stack.name, name, "(#{app.revision})", deployed_at]
      end
      # Sort output in descending date order
      table.compact!
      table.sort! { |x, y| y.last <=> x.last }
      print_table table
    end

    private

    def formatted_time(timestamp)
      timestamp.strftime('%Y-%m-%d %H:%M:%S %Z')
    end
  end
end