Class: Cody::CLI::List

Inherits:
Object
  • Object
show all
Extended by:
Memoist
Includes:
AwsServices
Defined in:
lib/cody/cli/list.rb

Instance Method Summary collapse

Methods included from AwsServices

#cfn, #codebuild

Methods included from AwsServices::Helpers

#are_you_sure?, #find_stack, #inferred_project_name, #inferred_stack_name, #normalize_stack_name, #project_name_convention, #stack_exists?

Constructor Details

#initialize(options) ⇒ List

Returns a new instance of List.



8
9
10
# File 'lib/cody/cli/list.rb', line 8

def initialize(options)
  @options = options
end

Instance Method Details

#list_projectsObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/cody/cli/list.rb', line 46

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
  if @options[:select]
    regexp = Regexp.new(@options[:select])
    projects.select! { |p| p =~ regexp }
  end
  projects
end

#projectsObject



36
37
38
39
40
41
42
43
# File 'lib/cody/cli/list.rb', line 36

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

#runObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/cody/cli/list.rb', line 12

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

#show?(build_status) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
30
31
32
33
34
# File 'lib/cody/cli/list.rb', line 27

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