Sha256: 6e736bdc5e6ca439f659f196970e715734371ba6fe4babd6e83296ae7adb93a8

Contents?: true

Size: 1.23 KB

Versions: 1

Compression:

Stored size: 1.23 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|
        presenter.rows << [project.name, project.build_status, project.end_time]
      end
      presenter.show
    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.7 lib/cody/list.rb