Module: GreenHat::ShellHelper::Reports

Defined in:
lib/greenhat/reports/shell_helper.rb

Overview

Log Helpers

Class Method Summary collapse

Class Method Details

.auto_complete_listObject

Collect everything from Built-in and local reports



46
47
48
49
50
51
52
53
# File 'lib/greenhat/reports/shell_helper.rb', line 46

def self.auto_complete_list
  path = "#{File.dirname(__FILE__)}/reports"
  list = Dir["#{path}/*.rb"] + Dir["#{GreenHat::Settings.reports_dir}/*.rb"]

  list.map do |entry|
    File.basename(entry, '.rb')
  end
end

.listObject

Collect everything from Built-in and local reports



40
41
42
43
# File 'lib/greenhat/reports/shell_helper.rb', line 40

def self.list
  path = "#{File.dirname(__FILE__)}/reports"
  Dir["#{path}/*.rb"] + Dir["#{GreenHat::Settings.reports_dir}/*.rb"]
end

.run(file:, args:, flags:, raw_args:) ⇒ Object

Make Running more consistent



6
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
# File 'lib/greenhat/reports/shell_helper.rb', line 6

def self.run(file:, args:, flags:, raw_args:)
  report = GreenHat::Reports::Builder.new(file: file, args: args, flags: flags, raw_args: raw_args)

  # Fuzzy Match Archive Names
  archives = Archive.all
  if flags[:archive] && !flags[:archive].empty?
    archives.select! do |a|
      flags[:archive].any? do |x|
        a.name.include? x.to_s
      end
    end
  end

  output = archives.map do |archive|
    runner = GreenHat::Reports::Runner.new(
      archive: archive,
      store: report.store.clone,
      flags: flags,
      args: args,
      raw_args: raw_args
    )

    runner.run!

    runner
  end

  # Check for Pagination
  flags[:page] = ENV['GREENHAT_PAGE'] == 'true' if ENV['GREENHAT_PAGE']

  ShellHelper.show(output.flat_map(&:output), flags)
end