Sha256: 88f19d2ae17fa62903d190fb38ec2094de5cb2344b0d212069e66dea6fc20a8e

Contents?: true

Size: 1.46 KB

Versions: 1

Compression:

Stored size: 1.46 KB

Contents

require 'cli-format'

module Cody
  class List
    include AwsServices
    extend Memoist

    def initialize(options)
      @options = options
    end

    def run
      if projects.size > 15
        $stderr.puts "Number of projects: #{projects.size}"
        $stderr.puts "Can take a while for a large number of projects..."
      end

      presenter = CliFormat::Presenter.new(@options)
      presenter.header = ["Name", "Status", "Time"]
      projects.each do |project|
        row = [project.name, project.build_status, project.end_time]
        presenter.rows << row if show?(project.build_status)
      end
      presenter.show
    end

    def show?(build_status)
      status = @options[:status].upcase if @options[:status]
      if status
        build_status == status
      else
        true
      end
    end

    def projects
      projects = list_projects.map { |p| Project.new(p) }
      if @options[:sort_by]
        projects.sort_by { |p| p.send(@options[:sort_by]) }
      else
        projects # default name
      end
    end
    memoize :projects

    def list_projects
      projects = []
      next_token = :start
      while next_token
        options = {sort_by: "NAME"}
        if next_token && next_token != :start
          options[:next_token] = next_token
        end
        resp = codebuild.list_projects(options)
        next_token = resp.next_token
        projects += resp.projects
      end
      projects
    end
    memoize :list_projects
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cody-0.9.8 lib/cody/list.rb